Projet

Général

Profil

Révision d51266a3

IDd51266a3588fd76f377379c76eddcbe2893acca6
Parent 1ee2a115
Enfant 3216a70b

Ajouté par Olivier Mehani il y a plus de 8 ans

[http_load_] Use separate subroutines for config output

Signed-off-by: Olivier Mehani <>

Voir les différences:

plugins/http/http_load_
208 208
	return $url;
209 209
}
210 210

  
211
sub graph_title_config{
212
	my $id = $_[0];
213
	my %urls = %{$_[1]};
214
	my $type = $_[2];
215

  
216
        print "graph_title $urls{$id} ${type}\n";
217
        print "graph_args -l 0 --base 1000\n";
218
        print "graph_category webserver\n";
219
}
220

  
221
sub size_config{
222
	my $id = $_[0];
223
	my %urls = %{$_[1]};
224
	my %cache = %{$_[2]};
225

  
226
	my $count = 0;
227

  
228
	graph_title_config($id, \%urls, "size");
229

  
230
	print "graph_vlabel Bytes\n";
231
	print "graph_total Total\n";
232
	print "graph_info This graph is generated by a set of serial GETs to calculate the total size of $urls{$id}.\n";
233

  
234
	if(keys(%cache)>0){
235
		for my $key ( sort reverse keys %cache ){
236
			my $value=$cache{$key};
237

  
238
			if($key =~ m/^size_(\S+)$/){
239
				my $host=$1;
240
				my $value=$value;
241

  
242
				my $name=$1;
243
				$name=get_fieldname($name);
244

  
245
				print "$name.label from $host\n";
246
				print "$name.min 0\n";
247
				print "$name.max 20000000\n";
248
				if($count eq 0){
249
					print "$name.draw AREA\n";
250
				} else {
251
					print "$name.draw STACK\n";
252
				}
253
				$count+=1;
254
			}
255
		}
256
	}
257
}
258

  
259
sub loadtime_config{
260
	my $id = $_[0];
261
	my %urls = %{$_[1]};
262
	my %cache = %{$_[2]};
263

  
264
	my $count = 0;
265

  
266
	graph_title_config($id, \%urls, "loadtime");
267

  
268
	print "graph_vlabel Seconds\n";
269
	print "graph_total Total\n";
270
	print "graph_info This graph is generated by a set of serial GETs to calculate the total time to load $urls{$id}. ";
271
	print "Note that browsers usually fork() the GET requests, resulting in a shorter total loading time.\n";
272
	
273
	if(keys(%cache)>0){
274
		for my $key ( sort reverse keys %cache ){
275
			my $value=$cache{$key};
276

  
277
			if($key =~ m/^loadtime_(\S+)$/){
278
				my $host=$1;
279
				my $value=$value;
280

  
281
				my $name=$1;
282
				$name=get_fieldname($name);
283

  
284
				print "$name.label from $host\n";
285
				print "$name.min 0\n";
286
				print "$name.max 400\n";
287
				if($count eq 0){
288
					print "$name.draw AREA\n";
289
				} else {
290
					print "$name.draw STACK\n";
291
				}
292
				$count+=1;
293
			}
294
		}
295
	}
296
}
297

  
298
sub elements_config{
299
	my $id = $_[0];
300
	my %urls = %{$_[1]};
301
	my %cache = %{$_[2]};
302

  
303
	my $count = 0;
304

  
305
	graph_title_config($id, \%urls, "elements");
306

  
307
	print "graph_vlabel Number of elements\n";
308
	print "graph_total Total\n";
309
	print "graph_info This graph is generated by a set of serial GETs to count the number of elements (images, CSS files, etc) from $urls{$id}.\n";
310

  
311
	if(keys(%cache)>0){
312
		for my $key ( sort reverse keys %cache ){
313
			my $value=$cache{$key};
314

  
315
			if($key =~ m/^elements_(\S+)$/){
316
				my $host=$1;
317
				my $value=$value;
318

  
319
				my $name=$1;
320
				$name=get_fieldname($name);
321

  
322
				print "$name.label from $host\n";
323
				print "$name.min 0\n";
324
				print "$name.max 10000\n";
325
				if($count eq 0){
326
					print "$name.draw AREA\n";
327
				} else {
328
					print "$name.draw STACK\n";
329
				}
330
				$count+=1;
331
			}
332
		}
333
	}
334
}
335

  
336
sub response_config{
337
	my $id = $_[0];
338
	my %urls = %{$_[1]};
339
	my %cache = %{$_[2]};
340

  
341
	my $count = 0;
342

  
343
	graph_title_config($id, \%urls, "response");
344

  
345
	print "graph_vlabel Server response code count\n";
346
	print "graph_total Total\n";
347
	print "graph_info This graph is generated by a set of serial GETs to visualize the server response codes received while loading $urls{$id}.\n";
348

  
349
	if(keys(%cache)>0){
350
		for my $key ( sort reverse keys %cache ){
351
			my $value=$cache{$key};
352

  
353
			if($key =~ m/^response_(\S+)$/){
354
				my $host=$1;
355
				my $value=$value;
356

  
357
				my $name=$1;
358
				$name=get_fieldname($name);
359

  
360
				$host =~ s/\_/ /g;
361
				$host =~ s/(\S+)\s(\d+)/ /g;
362
				$host=$1;
363
				my $code=$2;
364

  
365
				print "$name.label $host ($code)\n";
366
				print "$name.min 0\n";
367
				print "$name.max 10000\n";
368
				if($count eq 0){
369
					print "$name.draw AREA\n";
370
				} else {
371
					print "$name.draw STACK\n";
372
				}
373
				$count+=1;
374
			}
375
		}
376
	}
377
}
378

  
379
sub type_config{
380
	my $id = $_[0];
381
	my %urls = %{$_[1]};
382
	my %cache = %{$_[2]};
383

  
384
	my $count = 0;
385

  
386
	graph_title_config($id, \%urls, "type");
387

  
388
	print "graph_vlabel Content type count\n";
389
	print "graph_total Total\n";
390
	print "graph_info This graph is generated by a set of serial GETs to visualize the different content types $urls{$id} consists of.\n";
391

  
392
	if(keys(%cache)>0){
393
		for my $key ( sort reverse keys %cache ){
394
			my $value=$cache{$key};
395

  
396
			if($key =~ m/^type_(\S+)$/){
397
				my $type=$1;
398
				my $value=$value;
399

  
400
				my $name=$1;
401
				$name=get_fieldname($name);
402

  
403
				#$host =~ s/\_/ /g;
404
				#$host =~ s/(\S+)\s(\S+)/ /g;
405
				#$host=$1;
406
				#my $type=$2;
407

  
408
				print "$name.label $type\n";
409
				print "$name.min 0\n";
410
				print "$name.max 100000\n";
411
				if($count eq 0){
412
					print "$name.draw AREA\n";
413
				} else {
414
					print "$name.draw STACK\n";
415
				}
416
				$count+=1;
417
			}
418
		}
419
	}
420
}
421

  
422
sub tags_config{
423
	my $id = $_[0];
424
	my %urls = %{$_[1]};
425
	my %cache = %{$_[2]};
426

  
427
	my $count = 0;
428

  
429
	graph_title_config($id, \%urls, "tags");
430

  
431
	print "graph_vlabel HTML tag count\n";
432
	print "graph_total Total\n";
433
	print "graph_info This graph is generated by a set of serial GETs to visualize the different tags $urls{$id} consists of.\n";
434

  
435
	if(keys(%cache)>0){
436
		for my $key ( sort reverse keys %cache ){
437
			my $value=$cache{$key};
438

  
439
			if($key =~ m/^tags_(\S+)$/){
440
				my $host=$1;
441
				my $value=$value;
442

  
443
				my $name=$1;
444
				$name=get_fieldname($name);
445

  
446
				$host =~ s/\W/ /g;
447

  
448
				print "$name.label $host\n";
449
				print "$name.min 0\n";
450
				print "$name.max 100000\n";
451
				if($count eq 0){
452
					print "$name.draw AREA\n";
453
				} else {
454
					print "$name.draw STACK\n";
455
				}
456
				$count+=1;
457
			}
458
		}
459
	}
460
}
461

  
462
sub cache_values{
463
	my %cache = %{$_[0]};
464
	my $type = $_[1];
465

  
466
	if(keys(%cache)>0){
467
		for my $key ( sort keys %cache ){
468
			my $value=$cache{$key};
469
			if($key =~ m/^([A-Za-z]+)\_(\S+)$/){
470
				my $name=$2;
471
				
472
				if ($1 eq $type){
473
					$name=get_fieldname($name);
474
					print $name . ".value " . $value . "\n";
475
				}
476
			} elsif(m/^(\S+)\s+(\S+)$/){
477
				if ($1 eq $type){
478
					print $1 . ".value " . $2 . "\n";
479
				}
480
			}
481
		}
482
	}
483
}
484

  
211 485
$debug && print "Scriptname: " . $scriptname . "\n";
212 486

  
213 487
# Get the url id and the type of the graph
......
379 653
}elsif($ARGV[0] and $ARGV[0] eq "config") {
380 654
	my %urls=&read_urls($url_file);
381 655
	
382
        print "graph_title $urls{$id} ${type}\n";
383
        print "graph_args -l 0 --base 1000\n";
384
        print "graph_category webserver\n";
385 656
	$debug && print "Reading cache file\n";
386 657
	my $cachefile=$cachedir . "/" . &get_cache_file_name($scriptname,$id);
387 658
	my %cache=read_cache($cachefile);
388 659

  
389
	my $count=0;
390 660
	$debug && print "The cache file contains " . keys(%cache) . " lines\n";
391 661

  
392 662
	if($type eq "size"){
393
                print "graph_vlabel Bytes\n";
394
		print "graph_total Total\n";
395
         	print "graph_info This graph is generated by a set of serial GETs to calculate the total size of $urls{$id}.\n";
396

  
397
		if(keys(%cache)>0){
398
			for my $key ( sort reverse keys %cache ){
399
				my $value=$cache{$key};
400
				
401
				if($key =~ m/^size_(\S+)$/){
402
					my $host=$1;
403
					my $value=$value;
404

  
405
					my $name=$1;
406
					$name=get_fieldname($name);
407
	
408
        	        		print "$name.label from $host\n";
409
        	        		print "$name.min 0\n";
410
        	        		print "$name.max 20000000\n";
411
					if($count eq 0){
412
						print "$name.draw AREA\n";
413
					} else {
414
						print "$name.draw STACK\n";
415
					}
416
					$count+=1;
417
				}
418
			}
419
		}
663
		size_config($id, \%urls, \%cache)
420 664
	}elsif($type eq "loadtime"){
421
                print "graph_vlabel Seconds\n";
422
		print "graph_total Total\n";
423
         	print "graph_info This graph is generated by a set of serial GETs to calculate the total time to load $urls{$id}. ";
424
		print "Note that browsers usually fork() the GET requests, resulting in a shorter total loading time.\n";
425
		
426
		if(keys(%cache)>0){
427
			for my $key ( sort reverse keys %cache ){
428
				my $value=$cache{$key};
429

  
430
				if($key =~ m/^loadtime_(\S+)$/){
431
					my $host=$1;
432
					my $value=$value;
433

  
434
					my $name=$1;
435
					$name=get_fieldname($name);
436
	
437
        	        		print "$name.label from $host\n";
438
        	        		print "$name.min 0\n";
439
        	        		print "$name.max 400\n";
440
					if($count eq 0){
441
						print "$name.draw AREA\n";
442
					} else {
443
						print "$name.draw STACK\n";
444
					}
445
					$count+=1;
446
				}
447
			}
448
		}
449

  
665
		loadtime_config($id, \%urls, \%cache)
450 666
	}elsif($type eq "elements"){
451
                print "graph_vlabel Number of elements\n";
452
		print "graph_total Total\n";
453
        	print "graph_info This graph is generated by a set of serial GETs to count the number of elements (images, CSS files, etc) from $urls{$id}.\n";
454
	
455
		if(keys(%cache)>0){
456
			for my $key ( sort reverse keys %cache ){
457
				my $value=$cache{$key};
458
       
459
				if($key =~ m/^elements_(\S+)$/){
460
					my $host=$1;
461
					my $value=$value;
462

  
463
					my $name=$1;
464
					$name=get_fieldname($name);
465
	
466
        	        		print "$name.label from $host\n";
467
        	        		print "$name.min 0\n";
468
        	        		print "$name.max 10000\n";
469
					if($count eq 0){
470
						print "$name.draw AREA\n";
471
					} else {
472
						print "$name.draw STACK\n";
473
					}
474
					$count+=1;
475
				}
476
			}
477
		}
667
		elements_config($id, \%urls, \%cache)
478 668
	}elsif($type eq "response"){
479
                print "graph_vlabel Server response code count\n";
480
		print "graph_total Total\n";
481
         	print "graph_info This graph is generated by a set of serial GETs to visualize the server response codes received while loading $urls{$id}.\n";
482

  
483
		if(keys(%cache)>0){
484
			for my $key ( sort reverse keys %cache ){
485
				my $value=$cache{$key};
486

  
487
				if($key =~ m/^response_(\S+)$/){
488
					my $host=$1;
489
					my $value=$value;
490

  
491
					my $name=$1;
492
					$name=get_fieldname($name);
493

  
494
					$host =~ s/\_/ /g;
495
					$host =~ s/(\S+)\s(\d+)/ /g;
496
					$host=$1;
497
					my $code=$2;
498
	
499
        	        		print "$name.label $host ($code)\n";
500
        	        		print "$name.min 0\n";
501
        	        		print "$name.max 10000\n";
502
					if($count eq 0){
503
						print "$name.draw AREA\n";
504
					} else {
505
						print "$name.draw STACK\n";
506
					}
507
					$count+=1;
508
				}
509
			}
510
		}
669
		response_config($id, \%urls, \%cache)
511 670
	}elsif($type eq "type"){
512
                print "graph_vlabel Content type count\n";
513
		print "graph_total Total\n";
514
         	print "graph_info This graph is generated by a set of serial GETs to visualize the different content types $urls{$id} consists of.\n";
515

  
516
		if(keys(%cache)>0){
517
			for my $key ( sort reverse keys %cache ){
518
				my $value=$cache{$key};
519

  
520
				if($key =~ m/^type_(\S+)$/){
521
					my $type=$1;
522
					my $value=$value;
523

  
524
					my $name=$1;
525
					$name=get_fieldname($name);
526

  
527
					#$host =~ s/\_/ /g;
528
					#$host =~ s/(\S+)\s(\S+)/ /g;
529
					#$host=$1;
530
					#my $type=$2;
531
	
532
        	        		print "$name.label $type\n";
533
        	        		print "$name.min 0\n";
534
        	        		print "$name.max 100000\n";
535
					if($count eq 0){
536
						print "$name.draw AREA\n";
537
					} else {
538
						print "$name.draw STACK\n";
539
					}
540
					$count+=1;
541
				}
542
			}
543
		}
671
		type_config($id, \%urls, \%cache)
544 672
	}elsif($type eq "tags"){
545
                print "graph_vlabel HTML tag count\n";
546
		print "graph_total Total\n";
547
         	print "graph_info This graph is generated by a set of serial GETs to visualize the different tags $urls{$id} consists of.\n";
548

  
549
		if(keys(%cache)>0){
550
			for my $key ( sort reverse keys %cache ){
551
				my $value=$cache{$key};
552

  
553
				if($key =~ m/^tags_(\S+)$/){
554
					my $host=$1;
555
					my $value=$value;
556

  
557
					my $name=$1;
558
					$name=get_fieldname($name);
559

  
560
					$host =~ s/\W/ /g;
561
	
562
        	        		print "$name.label $host\n";
563
        	        		print "$name.min 0\n";
564
        	        		print "$name.max 100000\n";
565
					if($count eq 0){
566
						print "$name.draw AREA\n";
567
					} else {
568
						print "$name.draw STACK\n";
569
					}
570
					$count+=1;
571
				}
572
			}
573
		}
673
		tags_config($id, \%urls, \%cache)
574 674
	}
575
	exit(0); 
675
	exit(0);
576 676
} else {
577 677
	my $cachefile=$cachedir . "/" . &get_cache_file_name($scriptname,$id);
578 678
	$debug && print "Reading cache file: " . $cachefile . "\n";
579 679
	my %cache=read_cache($cachefile);
580 680
	$debug && print "Number of lines in cache file: " . keys(%cache) . "\n";
581 681

  
582
	if(keys(%cache)>0){
583
		for my $key ( sort keys %cache ){
584
			my $value=$cache{$key};
585
			if($key =~ m/^([A-Za-z]+)\_(\S+)$/){
586
				my $name=$2;
587
				
588
				if ($1 eq $type){
589
					$name=get_fieldname($name);
590
					print $name . ".value " . $value . "\n";
591
				}
592
			} elsif(m/^(\S+)\s+(\S+)$/){
593
				if ($1 eq $type){
594
					print $1 . ".value " . $2 . "\n";
595
				}
596
			}
597
		}
598
	}
682
	cache_values(\%cache, $type);
599 683
} 
600 684

  
601 685
# vim:syntax=perl

Formats disponibles : Unified diff