1#!/usr/bin/perl 2# $Id: libgraph.pl,v 1.4 2008/07/30 15:49:32 boggia Exp $ 3########################################################### 4# Creation : 21/05/08 : boggia 5# 6# Fichier contenant les fonctions de creation de graphiques 7# RRDtools 8########################################################### 9 10sub genere_graph 11{ 12 my ($type,$nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 13 14 # liste des fonction de création de graphiques 15 my %function_graph = ( 16 'trafic' => \&trafic, 17 'trafic-moyen' => \&trafic, 18 'aggreg_trafic' => \&aggreg_trafic, 19 'aggregation-trafic2-moyen' => \&aggreg_trafic, 20 'aggregation-trafic2' => \&aggreg_trafic, 21 'GaugeNbAuthWifi-site' => \&GaugeAuthWiFi, 22 'GaugeNbConAp' => \&GaugeAssocWiFi, 23 'GaugeNbAuthWifi' => \&GaugeAuthWiFi, 24 'GaugeDHCPuse' => \&GaugeDHCPleases, 25 'GaugeCPUCisco' => \&GaugeCPUCisco, 26 'GaugeCPUJuniper' => \&GaugeCPUJuniper, 27 'GaugeCPU' => \&GaugeCPUServer, 28 'GaugeLoadAverage' => \&GaugeLoadAverage, 29 'GaugeTempsReponse' => \&GaugeRespTime, 30 'tpsDisk' => \&GaugeTPSDisk, 31 'bind' => \&GaugeBind, 32 'GaugeGeneric' => \&GaugeGeneric, 33 'GaugeMailq' => \&GaugeMailq, 34 'GaugeMemByProc' => \&GaugeMemByProc, 35 'nbauthwifi' => \&nbauthwifi, 36 'nbassocwifi' => \&nbassocwifi, 37 'counter_generic' => \&counter_generic, 38 'packets' => \&packets, 39 ); 40 41 42 my %graph_size = ( 43 'petit' => "330x150", 44 'moyen' => "550x250", 45 'grand' => "750x250" 46 ); 47 48 if(exists $graph_size{$size}) 49 { 50 # si taille = petit, moyen ou grand : conversion en "longueur"x"hauteur" 51 $size = $graph_size{$size}; 52 } 53 54 if($size !~ m/[0-9]+x[0-9]+/) 55 { 56 # le paramètre taille est malformé 57 #print "Erreur : Paramètre $size incorrect"; 58 } 59 else 60 { 61 # appel de la fonction de creation du graphique 62 $function_graph{$type}->($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire); 63 } 64} 65 66 67 68########################################################### 69# Graph des authentifications WiFi 70sub nbauthwifi 71{ 72 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 73 74 my $label = "authentifiés"; 75 if($commentaire eq "") 76 { 77 $commentaire = "Authentifiés WiFi"; 78 79 } 80 81 GaugeWiFi($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire,$label); 82} 83 84 85 86########################################################### 87# Graph des associations WiFi 88sub nbassocwifi 89{ 90 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 91 92 my $label = "associés"; 93 if($commentaire eq "") 94 { 95 $commentaire = "Associés WiFi"; 96 } 97 98 GaugeWiFi($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire,$label); 99} 100 101 102########################################################### 103# Fonction générique qui graphe les utilisateurs WiFi 104sub GaugeWiFi 105{ 106 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire,$vertical_label) = @_; 107 108 # dereferencement 109 my @l = @$ref_l; 110 111 if(@l == 1) 112 { 113 my ($width,$height) = split(/x/,$size); 114 115 my %color_lines = ( 'avg' => "3d8d8d", 116 'max' => "b8ff4d", 117 ); 118 119 my $rrd = RRDTool::OO->new( 120 file => "$ref_l->[0]->[0]->{'base'}" ); 121 122 my @liste_arg; 123 my $plusline=""; 124 my ($drawlineavg,$drawlinemax); 125 126 my $ttl = @{$l[0]}; 127 128 for(my $j=0;$j<$ttl;$j++) 129 { 130 # dsname des bases a definir 131 132 my ($drawavg,$drawmax); 133 $drawavg->{'file'} = $l[0][$j]{'base'}; 134 $drawavg->{'type'} = "hidden"; 135 #$drawavg->{'dsname'} = "$ssid"; 136 $drawavg->{'name'} = "avg$j"; 137 $drawavg->{'cfunc'} = "AVERAGE"; 138 $drawmax->{'file'} = $l[0][$j]{'base'}; 139 $drawmax->{'type'} = "hidden"; 140 #$drawmax->{'dsname'} = "$ssid"; 141 $drawmax->{'name'} = "max$j"; 142 $drawmax->{'cfunc'} = "MAX"; 143 144 # calcul du cumul pour les donnes bases explicitement aggregees 145 # ex : Mescape-ap3.osiris.authwifi+Mescape-ap1.osiris.authwifi 146 # (afficher sous forme de ligne) 147 if(exists $drawlineavg->{'cdef'}) 148 { 149 $drawlineavg->{'cdef'}="$drawlineavg->{'cdef'},$drawavg->{'name'}"; 150 $drawlinemax->{'cdef'}="$drawlinemax->{'cdef'},$drawmax->{'name'}"; 151 $plusline = "$plusline,ADDNAN"; 152 } 153 else 154 { 155 $drawlineavg->{'cdef'}=$drawavg->{'name'}; 156 $drawlinemax->{'cdef'}=$drawmax->{'name'}; 157 } 158 159 push @liste_arg,"draw"; 160 push @liste_arg,$drawavg; 161 push @liste_arg,"draw"; 162 push @liste_arg,$drawmax; 163 } 164 165 # pour additionner le resultat des valeurs 166 $drawlineavg->{'cdef'}="$drawlineavg->{'cdef'}$plusline"; 167 $drawlinemax->{'cdef'}="$drawlinemax->{'cdef'}$plusline"; 168 169 # comparaison des legendes pour la mise en page 170 my @legend; 171 my $t_legend; 172 my $maxlengthlegend = 0; 173 174 if($l[0][0]{'legend'} ne "") 175 { 176 @legend = split(//,$l[0][0]{'legend'}); 177 $maxlengthlegend = @legend; 178 $t_legend = $maxlengthlegend; 179 } 180 $maxlengthlegend = $maxlengthlegend + 6; 181 182 # ecriture de la legende en entree 183 my $spaces = get_spaces(0,$maxlengthlegend,11); 184 push @liste_arg,"comment"; 185 push @liste_arg,"$spaces min max moyen actuel\\n"; 186 my ($gprintavg,$gprintmax); 187 $spaces = get_spaces($t_legend,$maxlengthlegend,8); 188 # ecriture de la courbe en input 189 $drawlineavg->{'type'} = "area"; 190 $drawlineavg->{'color'} = $color_lines{'avg'}; 191 $drawlineavg->{'name'} = "clients_avg"; 192 if($l[0][0]{'legend'} ne "") 193 { 194 $drawlineavg->{'legend'} = "$l[0][0]{'legend'}"; 195 } 196 else 197 { 198 $drawlineavg->{'legend'} = "clients"; 199 } 200 push @liste_arg,"draw"; 201 push @liste_arg,$drawlineavg; 202 # legende trafic in 203 push @liste_arg,"comment"; 204 push @liste_arg,$spaces; 205 $gprintavg->{0}->{'draw'}="clients_avg"; 206 $gprintavg->{0}->{'format'}="MIN:%5.0lf %S"; 207 push @liste_arg,"gprint"; 208 push @liste_arg,$gprintavg->{0}; 209 $gprintavg->{1}->{'draw'}="clients_avg"; 210 $gprintavg->{1}->{'format'}="MAX:%5.0lf %S"; 211 push @liste_arg,"gprint"; 212 push @liste_arg,$gprintavg->{1}; 213 $gprintavg->{2}->{'draw'}="clients_avg"; 214 $gprintavg->{2}->{'format'}="AVERAGE:%5.0lf %S"; 215 push @liste_arg,"gprint"; 216 push @liste_arg,$gprintavg->{2}; 217 $gprintavg->{3}->{'draw'}="clients_avg"; 218 $gprintavg->{3}->{'format'}="LAST:%5.0lf %S\\n"; 219 push @liste_arg,"gprint"; 220 push @liste_arg,$gprintavg->{3}; 221 222 # ecriture de la valeur MAX selon l'intervalle de temps 223 if(($end - $start) > 800000) 224 { 225 $spaces = get_spaces($t_legend,$maxlengthlegend,0); 226 # ecriture de la courbe en input 227 $drawlinemax->{'type'} = "line"; 228 $drawlinemax->{'color'} = $color_lines{'max'}; 229 $drawlinemax->{'name'} = "clients_max"; 230 if($l[0][0]{'legend'} ne "") 231 { 232 $drawlinemax->{'legend'} = "$l[0][0]{'legend'} (crête)"; 233 } 234 else 235 { 236 $drawlinemax->{'legend'} = "clients (crête)"; 237 } 238 push @liste_arg,"draw"; 239 push @liste_arg,$drawlinemax; 240 # legende trafic in 241 push @liste_arg,"comment"; 242 push @liste_arg,$spaces; 243 $gprintmax->{0}->{'draw'}="clients_max"; 244 $gprintmax->{0}->{'format'}="MIN:%5.0lf %S"; 245 push @liste_arg,"gprint"; 246 push @liste_arg,$gprintmax->{0}; 247 $gprintmax->{1}->{'draw'}="clients_max"; 248 $gprintmax->{1}->{'format'}="MAX:%5.0lf %S"; 249 push @liste_arg,"gprint"; 250 push @liste_arg,$gprintmax->{1}; 251 $gprintmax->{2}->{'draw'}="clients_max"; 252 $gprintmax->{2}->{'format'}="AVERAGE:%5.0lf %S"; 253 push @liste_arg,"gprint"; 254 push @liste_arg,$gprintmax->{2}; 255 $gprintmax->{3}->{'draw'}="clients_max"; 256 $gprintmax->{3}->{'format'}="LAST:%5.0lf %S"; 257 push @liste_arg,"gprint"; 258 push @liste_arg,$gprintmax->{3}; 259 } 260 261 $rrd->graph( 262 image => "-", 263 title => "$commentaire", 264 vertical_label => "$vertical_label", 265 lower_limit => 0, 266 units_exponent => 0, 267 height => $height, 268 width => $width, 269 start => $start, 270 end => $end, 271 @liste_arg, 272 ); 273 274 } 275 elsif(@l > 1) 276 { 277 aggregGaugeWiFi($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire,$vertical_label); 278 } 279 else 280 { 281 print "nombre de bases rrd incorrect : $nb_rrd_bases"; 282 } 283} 284 285 286 287########################################################### 288# Fonction générique qui graphe les utilisateurs WiFi 289sub aggregGaugeWiFi 290{ 291 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire,$vertical_label) = @_; 292 293 my ($width,$height) = split(/x/,$size); 294 295 my $couleur_cumul = "c9c9c9"; 296 my @couleurs_flux = qw(ff0000 0055ff 00ff00 ffff00 000000 ff00ff 00c6ff 009800 ffa400 7f0000 ff6b01 7f007f a29951 ffa7cc 00007f 007f7f 007f00 a29900 827f00 4c4c4c 666666 665166 fbcbfb ffff8b ffc68b a2ffff ff5e5e fffdfc dec7c6 deebc6 deebee a299ea); 297 298 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 299 300 my @liste_arg1; 301 my @liste_total; 302 303 # creation des parametres pour le cumul total 304 my $drawtotal; 305 $drawtotal->{'type'} = "area"; 306 $drawtotal->{'color'} = $couleur_cumul; 307 $drawtotal->{'name'} = "total"; 308 $drawtotal->{'legend'} = "cumul"; 309 310 my $drawline; 311 # dereferencement 312 my @l = @$ref_l; 313 314 # creation d'objets draw de type hidden pour chaque courbe 315 my $tl = @l; 316 my $plus; 317 for(my $i=0;$i<$tl;$i++) 318 { 319 my $ttl = @{$l[$i]}; 320 my $plusline=""; 321 for(my $j=0;$j<$ttl;$j++) 322 { 323 my $draw; 324 $draw->{'file'} = $l[$i][$j]{'base'}; 325 $draw->{'type'} = "hidden"; 326 #$drawin->{'dsname'} = "input"; 327 $draw->{'name'} = "$l[$i][$j]{'graph'}__clients"; 328 $draw->{'cfunc'} = "AVERAGE"; 329 $draw->{'name'} =~ s/\./__/g; 330 # calcul du cumul total (afficher sour forme d'une aire) 331 if(exists $drawtotal->{'cdef'}) 332 { 333 $drawtotal->{'cdef'}="$drawtotal->{'cdef'},$draw->{'name'}"; 334 $plus = "$plus,ADDNAN"; 335 } 336 else 337 { 338 $drawtotal->{'cdef'}=$draw->{'name'}; 339 } 340 # calcul du cumul seulement pour les donnes bases explicitement aggregees 341 # ex : Mescarpe-ap3.authwifi.osiris+Mescarpe-ap3.authwifi.osiris-sec 342 # (afficher sous forme de ligne) 343 if(exists $drawline->{$i}->{'cdef'}) 344 { 345 $drawline->{$i}->{'cdef'}="$drawline->{$i}->{'cdef'},$draw->{'name'}"; 346 $plusline = "$plusline,ADDNAN"; 347 } 348 else 349 { 350 $drawline->{$i}->{'cdef'}=$draw->{'name'}; 351 } 352 353 push @liste_arg1,"draw"; 354 push @liste_arg1,$draw; 355 } 356 # pour additionner les valeurs aggregees 357 $drawline->{$i}->{'cdef'}="$drawline->{$i}->{'cdef'}$plusline"; 358 } 359 360 # pour additionner les valeurs aggregees pour le cumul 361 $drawtotal->{'cdef'}="$drawtotal->{'cdef'}$plus"; 362 363 # ecriture du graphique de cumul en entree 364 push @liste_total,"draw"; 365 push @liste_total,$drawtotal; 366 367 # comparaison des legendes pour la mise en page 368 my %llegend; 369 $llegend{'total'} = length($drawtotal->{'legend'}); 370 my $maxlengthlegend = $llegend{'total'}; 371 372 for($i=0;$i<$tl;$i++) 373 { 374 if($l[$i][0]{'legend'} eq "") 375 { 376 $l[$i][0]{'legend'} = $l[$i][0]{'graph'}; 377 } 378 $llegend{$i} = length($l[$i][0]{'legend'}); 379 if($maxlengthlegend < $llegend{$i}) 380 { 381 $maxlengthlegend = $llegend{$i}; 382 } 383 } 384 $maxlengthlegend = $maxlengthlegend + 4; 385 386 # ecriture de la legende en entree 387 my $spaces = get_spaces(0,$maxlengthlegend,8); 388 push @liste_arg1,"comment"; 389 push @liste_arg1,"$spaces min max moyen actuel\\n"; 390 my $gprinttotal; 391 $spaces = get_spaces($llegend{'total'},$maxlengthlegend,0); 392 push @liste_total,"comment"; 393 push @liste_total,$spaces; 394 $gprinttotal->{0}->{'draw'}="total"; 395 $gprinttotal->{0}->{'format'}="MIN:%5.0lf %S"; 396 push @liste_total,"gprint"; 397 push @liste_total,$gprinttotal->{0}; 398 $gprinttotal->{1}->{'draw'}="total"; 399 $gprinttotal->{1}->{'format'}="MAX:%5.0lf %S"; 400 push @liste_total,"gprint"; 401 push @liste_total,$gprinttotal->{1}; 402 $gprinttotal->{2}->{'draw'}="total"; 403 $gprinttotal->{2}->{'format'}="AVERAGE:%5.0lf %S"; 404 push @liste_total,"gprint"; 405 push @liste_total,$gprinttotal->{2}; 406 $gprinttotal->{3}->{'draw'}="total"; 407 $gprinttotal->{3}->{'format'}="LAST:%5.0lf %S\\n"; 408 push @liste_total,"gprint"; 409 push @liste_total,$gprinttotal->{3}; 410 411 my $gprint; 412 # on cree les objets draw pour afficher les lignes 413 for($i=0;$i<$tl;$i++) 414 { 415 # ecriture de la courbe en input 416 $drawline->{$i}->{'type'} = "line"; 417 $drawline->{$i}->{'color'} = $couleurs_flux[$i]; 418 $drawline->{$i}->{'name'} = "ssid$i"; 419 # insertion de la legende 420 $drawline->{$i}->{'legend'} = "$l[$i][0]{'legend'}"; 421 push @liste_total,"draw"; 422 push @liste_total,$drawline->{$i}; 423 $gprint->{$i}->{0}->{'draw'}=$drawline->{$i}->{'name'}; 424 $gprint->{$i}->{0}->{'format'}="MIN:%5.0lf %S"; 425 $spaces = get_spaces($llegend{$i},$maxlengthlegend,0); 426 push @liste_total,"comment"; 427 push @liste_total,$spaces; 428 push @liste_total,"gprint"; 429 push @liste_total,$gprint->{$i}->{0}; 430 $gprint->{$i}->{1}->{'draw'}=$drawline->{$i}->{'name'}; 431 $gprint->{$i}->{1}->{'format'}="MAX:%5.0lf %S"; 432 push @liste_total,"gprint"; 433 push @liste_total,$gprint->{$i}->{1}; 434 $gprint->{$i}->{2}->{'draw'}=$drawline->{$i}->{'name'}; 435 $gprint->{$i}->{2}->{'format'}="AVERAGE:%5.0lf %S"; 436 push @liste_total,"gprint"; 437 push @liste_total,$gprint->{$i}->{2}; 438 $gprint->{$i}->{3}->{'draw'}=$drawline->{$i}->{'name'}; 439 $gprint->{$i}->{3}->{'format'}="LAST:%5.0lf %S\\n"; 440 push @liste_total,"gprint"; 441 push @liste_total,$gprint->{$i}->{3}; 442 } 443 444 $rrd->graph( 445 image => "-", 446 title => "$commentaire", 447 vertical_label => "$vertical_label", 448 lower_limit => 0, 449 units_exponent => 0, 450 height => $height, 451 width => $width, 452 start => $start, 453 end => $end, 454 @liste_arg1, 455 @liste_total, 456 ); 457 458} 459 460 461 462########################################################### 463# Graph de trafic 464sub trafic 465{ 466 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 467 468 # dereferencement 469 my @l = @$ref_l; 470 471 if(@l == 1) 472 { 473 my ($width,$height) = split(/x/,$size); 474 475 my %color_lines = ( 'input' => "00dd00", 476 'output' => "0000ff", 477 'maxinput' => "b8ff4d", 478 'maxoutput' => "ffa1e9", 479 ); 480 481 $vertical_label = "Trafic Réseau"; 482 483 my $rrd = RRDTool::OO->new( 484 file => "$ref_l->[0]->[0]->{'base'}", 485 #raise_error => 0, 486 ); 487 488 my @liste_arg; 489 my $plusline=""; 490 my ($drawlinein,$drawlineout); 491 492 my $ttl = @{$l[0]}; 493 494 for(my $j=0;$j<$ttl;$j++) 495 { 496 my ($drawin,$drawout,$drawinmax,$drawoutmax); 497 $drawin->{'file'} = $l[0][$j]{'base'}; 498 $drawin->{'type'} = "hidden"; 499 $drawin->{'dsname'} = "input"; 500 $drawin->{'name'} = "$l[0][$j]{'graph'}__inputbytes"; 501 $drawin->{'cfunc'} = "AVERAGE"; 502 $drawout->{'file'} = $l[0][$j]{'base'}; 503 $drawout->{'type'} = "hidden"; 504 $drawout->{'dsname'} = "output"; 505 $drawout->{'name'} = "$l[0][$j]{'graph'}__outputbytes"; 506 $drawout->{'cfunc'} = "AVERAGE"; 507 $drawin->{'name'} =~ s/\./__/g; 508 $drawout->{'name'} =~ s/\./__/g; 509 $drawinmax->{'file'} = $l[0][$j]{'base'}; 510 $drawinmax->{'type'} = "hidden"; 511 $drawinmax->{'dsname'} = "input"; 512 $drawinmax->{'name'} = "$l[0][$j]{'graph'}__maxinputbytes"; 513 $drawinmax->{'cfunc'} = "MAX"; 514 $drawoutmax->{'file'} = $l[0][$j]{'base'}; 515 $drawoutmax->{'type'} = "hidden"; 516 $drawoutmax->{'dsname'} = "output"; 517 $drawoutmax->{'name'} = "$l[0][$j]{'graph'}__maxoutputbytes"; 518 $drawoutmax->{'cfunc'} = "MAX"; 519 $drawinmax->{'name'} =~ s/\./__/g; 520 $drawoutmax->{'name'} =~ s/\./__/g; 521 522 # calcul du cumul pour les donnes bases explicitement aggregees 523 # ex : Mcrc-rc1.wifi-sec+Mle7-rc1.wifi-sec 524 # (afficher sous forme de ligne) 525 if(exists $drawlinein->{'cdef'}) 526 { 527 $drawlinein->{'cdef'}="$drawlinein->{'cdef'},$drawin->{'name'}"; 528 $drawlineout->{'cdef'}="$drawlineout->{'cdef'},$drawout->{'name'}"; 529 $drawlineinmax->{'cdef'}="$drawlineinmax->{'cdef'},$drawinmax->{'name'}"; 530 $drawlineoutmax->{'cdef'}="$drawlineoutmax->{'cdef'},$drawoutmax->{'name'}"; 531 $plusline = "$plusline,ADDNAN"; 532 } 533 else 534 { 535 $drawlinein->{'cdef'}=$drawin->{'name'}; 536 $drawlineout->{'cdef'}=$drawout->{'name'}; 537 $drawlineinmax->{'cdef'}=$drawinmax->{'name'}; 538 $drawlineoutmax->{'cdef'}=$drawoutmax->{'name'}; 539 } 540 541 push @liste_arg,"draw"; 542 push @liste_arg,$drawin; 543 push @liste_arg,"draw"; 544 push @liste_arg,$drawout; 545 push @liste_arg,"draw"; 546 push @liste_arg,$drawinmax; 547 push @liste_arg,"draw"; 548 push @liste_arg,$drawoutmax; 549 } 550 # pour convertir les valeurs de trafic des lignes en bits 551 $drawlinein->{'cdef'}="$drawlinein->{'cdef'}$plusline,8,*"; 552 $drawlineout->{'cdef'}="$drawlineout->{'cdef'}$plusline,8,*"; 553 $drawlineinmax->{'cdef'}="$drawlineinmax->{'cdef'}$plusline,8,*"; 554 $drawlineoutmax->{'cdef'}="$drawlineoutmax->{'cdef'}$plusline,8,*"; 555 556 # comparaison des legendes pour la mise en page 557 my %llegend; 558 if($l[0][0]{'legend'} ne "") 559 { 560 $llegend{'in'} = length($l[0][0]{'legend'}); 561 my $maxlengthlegend = $llegend{'in'}; 562 $llegend{'out'} = length($l[0][0]{'legend'}); 563 } 564 else 565 { 566 $llegend{'in'} = 0; 567 $llegend{'out'} = 0; 568 } 569 $maxlengthlegend = $maxlengthlegend + 6; 570 571 # ecriture de la legende en entree 572 my $spaces = get_spaces(0,$maxlengthlegend,17); 573 push @liste_arg,"comment"; 574 push @liste_arg,"$spaces maximum moyen actuel\\n"; 575 my ($gprintin,$gprintout,$gprintinmax,$gprintoutmax); 576 $spaces = get_spaces($llegend{'in'},$maxlengthlegend,0); 577 # ecriture de la courbe en input 578 $drawlinein->{'type'} = "area"; 579 $drawlinein->{'color'} = $color_lines{'input'}; 580 $drawlinein->{'name'} = "inputbits"; 581 $drawlinein->{'legend'} = "$l[0][0]{'legend'} entrant"; 582 push @liste_arg,"draw"; 583 push @liste_arg,$drawlinein; 584 # legende trafic in 585 push @liste_arg,"comment"; 586 push @liste_arg,$spaces; 587 $gprintin->{0}->{'draw'}="inputbits"; 588 $gprintin->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 589 push @liste_arg,"gprint"; 590 push @liste_arg,$gprintin->{0}; 591 $gprintin->{1}->{'draw'}="inputbits"; 592 $gprintin->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 593 push @liste_arg,"gprint"; 594 push @liste_arg,$gprintin->{1}; 595 $gprintin->{2}->{'draw'}="inputbits"; 596 $gprintin->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 597 push @liste_arg,"gprint"; 598 push @liste_arg,$gprintin->{2}; 599 600 # ecriture des valeurs MAX selon l'intervalle de temps 601 if(($end - $start) > 800000) 602 { 603 # ecriture de la legende en entree 604 $spaces = get_spaces($llegend{'in'},$maxlengthlegend,-6); 605 # ecriture de la courbe en input 606 $drawlineinmax->{'type'} = "line"; 607 $drawlineinmax->{'color'} = $color_lines{'maxinput'}; 608 $drawlineinmax->{'name'} = "maxinputbits"; 609 $drawlineinmax->{'legend'} = "$l[0][0]{'legend'} entrant crête"; 610 push @liste_arg,"draw"; 611 push @liste_arg,$drawlineinmax; 612 # legende trafic in 613 push @liste_arg,"comment"; 614 push @liste_arg,$spaces; 615 $gprintinmax->{0}->{'draw'}="maxinputbits"; 616 $gprintinmax->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 617 push @liste_arg,"gprint"; 618 push @liste_arg,$gprintinmax->{0}; 619 $gprintinmax->{1}->{'draw'}="maxinputbits"; 620 $gprintinmax->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 621 push @liste_arg,"gprint"; 622 push @liste_arg,$gprintinmax->{1}; 623 $gprintinmax->{2}->{'draw'}="maxinputbits"; 624 $gprintinmax->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 625 push @liste_arg,"gprint"; 626 push @liste_arg,$gprintinmax->{2}; 627 628 # ecriture de la legende en entree 629 $spaces = get_spaces($llegend{'out'},$maxlengthlegend,-6); 630 # ecriture de la courbe en input 631 $drawlineoutmax->{'type'} = "line"; 632 $drawlineoutmax->{'color'} = $color_lines{'maxoutput'}; 633 $drawlineoutmax->{'name'} = "maxoutputbits"; 634 $drawlineoutmax->{'legend'} = "$l[0][0]{'legend'} sortant crête"; 635 push @liste_arg,"draw"; 636 push @liste_arg,$drawlineoutmax; 637 # legende trafic in 638 push @liste_arg,"comment"; 639 push @liste_arg,$spaces; 640 $gprintoutmax->{0}->{'draw'}="maxoutputbits"; 641 $gprintoutmax->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 642 push @liste_arg,"gprint"; 643 push @liste_arg,$gprintoutmax->{0}; 644 $gprintoutmax->{1}->{'draw'}="maxoutputbits"; 645 $gprintoutmax->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 646 push @liste_arg,"gprint"; 647 push @liste_arg,$gprintoutmax->{1}; 648 $gprintoutmax->{2}->{'draw'}="maxoutputbits"; 649 $gprintoutmax->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 650 push @liste_arg,"gprint"; 651 push @liste_arg,$gprintoutmax->{2}; 652 } 653 654 # ecriture de la courbe en output 655 $spaces = get_spaces($llegend{'out'},$maxlengthlegend,0); 656 $drawlineout->{'type'} = "line"; 657 $drawlineout->{'color'} = $color_lines{'output'}; 658 $drawlineout->{'name'} = "outputbits"; 659 $drawlineout->{'legend'} = "$l[0][0]{'legend'} sortant"; 660 push @liste_arg,"draw"; 661 push @liste_arg,$drawlineout; 662 # legende trafic out 663 push @liste_arg,"comment"; 664 push @liste_arg,$spaces; 665 $gprintout->{0}->{'draw'}="outputbits"; 666 $gprintout->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 667 push @liste_arg,"gprint"; 668 push @liste_arg,$gprintout->{0}; 669 $gprintout->{1}->{'draw'}="outputbits"; 670 $gprintout->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 671 push @liste_arg,"gprint"; 672 push @liste_arg,$gprintout->{1}; 673 $gprintout->{2}->{'draw'}="outputbits"; 674 $gprintout->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 675 push @liste_arg,"gprint"; 676 push @liste_arg,$gprintout->{2}; 677 678 $rrd->graph( 679 image => "-", 680 title => "$commentaire", 681 vertical_label => "trafic", 682 height => $height, 683 width => $width, 684 start => $start, 685 end => $end, 686 @liste_arg, 687 ); 688 689 $rrd->error_message(); 690 } 691 elsif($nb_rrd_bases > 1 && $nb_rrd_bases < 20) 692 { 693 aggreg_trafic($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire); 694 } 695 else 696 { 697 print "nombre de bases rrd incorrect : $nb_rrd_bases"; 698 } 699} 700 701 702########################################################### 703# Graph de trafic aggrégé 704sub aggreg_trafic 705{ 706 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 707 # parametre détail : 0 : n'affiche que le cumul de l'ensemble des bases 708 # 1 : affiche le détail pour chaque base 709 710 my ($width,$height) = split(/x/,$size); 711 712 my $couleur_cumul = "c9c9c9"; 713 my @couleurs_flux = qw(e207ff 0010ff ffbb00 32bc2d ff8800 ff0000 00ffaa 000000 fb96be 795634); 714 715 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 716 717 my @liste_arg1; 718 my @liste_total; 719 720 # creation des parametres pour le cumul total 721 my ($drawtotalin,$drawtotalout); 722 $drawtotalin->{'type'} = "area"; 723 $drawtotalin->{'color'} = $couleur_cumul; 724 $drawtotalin->{'name'} = "totalinputbits"; 725 $drawtotalin->{'legend'} = "total entrant"; 726 $drawtotalout->{'type'} = "area"; 727 $drawtotalout->{'color'} = $couleur_cumul; 728 $drawtotalout->{'name'} = "totaloutputbits"; 729 $drawtotalout->{'legend'} = "total sortant"; 730 731 my ($drawlinein,$drawlineout); 732 # dereferencement 733 my @l = @$ref_l; 734 735 # creation d'objets draw de type hidden pour chaque courbe de trafic 736 # en input et en output 737 my $tl = @l; 738 my $plus; 739 for(my $i=0;$i<$tl;$i++) 740 { 741 my $ttl = @{$l[$i]}; 742 my $plusline=""; 743 for(my $j=0;$j<$ttl;$j++) 744 { 745 my ($drawin,$drawout); 746 $drawin->{'file'} = $l[$i][$j]{'base'}; 747 $drawin->{'type'} = "hidden"; 748 $drawin->{'dsname'} = "input"; 749 $drawin->{'name'} = "$l[$i][$j]{'graph'}__inputbytes"; 750 $drawin->{'cfunc'} = "AVERAGE"; 751 $drawout->{'file'} = $l[$i][$j]{'base'}; 752 $drawout->{'type'} = "hidden"; 753 $drawout->{'dsname'} = "output"; 754 $drawout->{'name'} = "$l[$i][$j]{'graph'}__outputbytes"; 755 $drawout->{'cfunc'} = "AVERAGE"; 756 $drawin->{'name'} =~ s/\./__/g; 757 $drawout->{'name'} =~ s/\./__/g; 758 # calcul du cumul total (afficher sour forme d'une aire) 759 if(exists $drawtotalin->{'cdef'}) 760 { 761 $drawtotalin->{'cdef'}="$drawtotalin->{'cdef'},$drawin->{'name'}"; 762 $drawtotalout->{'cdef'}="$drawtotalout->{'cdef'},$drawout->{'name'}"; 763 $plus = "$plus,ADDNAN"; 764 } 765 else 766 { 767 $drawtotalin->{'cdef'}=$drawin->{'name'}; 768 $drawtotalout->{'cdef'}=$drawout->{'name'}; 769 } 770 # calcul du cumul seulement pour les donnes bases explicitement aggregees 771 # ex : Mcrc-rc1.wifi-sec+Mle7-rc1.wifi-sec 772 # (afficher sous forme de ligne) 773 if(exists $drawlinein->{$i}->{'cdef'}) 774 { 775 $drawlinein->{$i}->{'cdef'}="$drawlinein->{$i}->{'cdef'},$drawin->{'name'}"; 776 $drawlineout->{$i}->{'cdef'}="$drawlineout->{$i}->{'cdef'},$drawout->{'name'}"; 777 $plusline = "$plusline,ADDNAN"; 778 } 779 else 780 { 781 $drawlinein->{$i}->{'cdef'}=$drawin->{'name'}; 782 $drawlineout->{$i}->{'cdef'}=$drawout->{'name'}; 783 } 784 785 push @liste_arg1,"draw"; 786 push @liste_arg1,$drawin; 787 push @liste_arg1,"draw"; 788 push @liste_arg1,$drawout; 789 } 790 # pour convertir les valeurs de trafic des lignes en bits 791 $drawlinein->{$i}->{'cdef'}="$drawlinein->{$i}->{'cdef'}$plusline,8,*"; 792 $drawlineout->{$i}->{'cdef'}="$drawlineout->{$i}->{'cdef'}$plusline,-8,*"; 793 } 794 795 # pour convertir les valeurs de trafic du total en bits 796 $drawtotalin->{'cdef'}="$drawtotalin->{'cdef'}$plus,8,*"; 797 $drawtotalout->{'cdef'}="$drawtotalout->{'cdef'}$plus,-8,*"; 798 799 # objet hidden pour creer une valeur de trafic en output positive 800 my $drawtotaloutpositif; 801 $drawtotaloutpositif->{'type'} = "hidden"; 802 $drawtotaloutpositif->{'name'} = "totaloutputbitspos"; 803 $drawtotaloutpositif->{'cdef'} = "totaloutputbits,-1,*", 804 805 # ecriture du graphique de cumul en entree 806 push @liste_total,"draw"; 807 push @liste_total,$drawtotalin; 808 809 # comparaison des legendes pour la mise en page 810 my %llegend; 811 $llegend{'totalin'} = length($drawtotalin->{'legend'}); 812 my $maxlengthlegend = $llegend{'totalin'}; 813 $llegend{'totalout'} = length($drawtotalout->{'legend'}); 814 if($maxlengthlegend < $llegend{'totalout'}) 815 { 816 $maxlengthlegend = $llegend{'totalout'}; 817 } 818 819 for($i=0;$i<$tl;$i++) 820 { 821 if($l[$i][0]{'legend'} eq "") 822 { 823 $l[$i][0]{'legend'} = $l[$i][0]{'graph'}; 824 } 825 $llegend{$i} = length($l[$i][0]{'legend'}); 826 if($maxlengthlegend < $llegend{$i}) 827 { 828 $maxlengthlegend = $llegend{$i}; 829 } 830 } 831 $maxlengthlegend = $maxlengthlegend + 4; 832 833 # ecriture de la legende en entree 834 my $spaces = get_spaces(0,$maxlengthlegend,10); 835 push @liste_arg1,"comment"; 836 push @liste_arg1,"$spaces maximum moyen actuel\\n"; 837 my ($gprinttotalin,$gprinttotalout); 838 $spaces = get_spaces($llegend{'totalin'},$maxlengthlegend,0); 839 push @liste_total,"comment"; 840 push @liste_total,$spaces; 841 $gprinttotalin->{0}->{'draw'}="totalinputbits"; 842 $gprinttotalin->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 843 push @liste_total,"gprint"; 844 push @liste_total,$gprinttotalin->{0}; 845 $gprinttotalin->{1}->{'draw'}="totalinputbits"; 846 $gprinttotalin->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 847 push @liste_total,"gprint"; 848 push @liste_total,$gprinttotalin->{1}; 849 $gprinttotalin->{2}->{'draw'}="totalinputbits"; 850 $gprinttotalin->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 851 push @liste_total,"gprint"; 852 push @liste_total,$gprinttotalin->{2}; 853 # ecriture du graphique de cumul en sortie 854 push @liste_total,"draw"; 855 push @liste_total,$drawtotalout; 856 # insere l'objet draw de type hidden avec les valeurs d'output positives 857 push @liste_total,"draw"; 858 push @liste_total,$drawtotaloutpositif; 859 # ecriture de la legende en sortie 860 $spaces = get_spaces($llegend{'totalout'},$maxlengthlegend,0); 861 push @liste_total,"comment"; 862 push @liste_total,$spaces; 863 $gprinttotalout->{0}->{'draw'}="totaloutputbitspos"; 864 $gprinttotalout->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 865 push @liste_total,"gprint"; 866 push @liste_total,$gprinttotalout->{0}; 867 $gprinttotalout->{1}->{'draw'}="totaloutputbitspos"; 868 $gprinttotalout->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 869 push @liste_total,"gprint"; 870 push @liste_total,$gprinttotalout->{1}; 871 $gprinttotalout->{2}->{'draw'}="totaloutputbitspos"; 872 $gprinttotalout->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 873 push @liste_total,"gprint"; 874 push @liste_total,$gprinttotalout->{2}; 875 876 my $drawlineoutpositif; 877 my ($gprintin,$gprintout); 878 # on cree les objets draw pour afficher les lignes 879 for($i=0;$i<$tl;$i++) 880 { 881 # ecriture de la courbe en input 882 $drawlinein->{$i}->{'type'} = "line"; 883 $drawlinein->{$i}->{'color'} = $couleurs_flux[$i]; 884 $drawlinein->{$i}->{'name'} = "input$i"; 885 $drawlineout->{$i}->{'type'} = "line"; 886 $drawlineout->{$i}->{'color'} = $couleurs_flux[$i]; 887 $drawlineout->{$i}->{'name'} = "output$i"; 888 # insertion de la legende 889 $drawlinein->{$i}->{'legend'} = "$l[$i][0]{'legend'} in"; 890 $drawlineout->{$i}->{'legend'} = "$l[$i][0]{'legend'} out"; 891 push @liste_total,"draw"; 892 push @liste_total,$drawlinein->{$i}; 893 $gprintin->{$i}->{0}->{'draw'}=$drawlinein->{$i}->{'name'}; 894 $gprintin->{$i}->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 895 $spaces = get_spaces($llegend{$i},$maxlengthlegend,-3); 896 push @liste_total,"comment"; 897 push @liste_total,$spaces; 898 push @liste_total,"gprint"; 899 push @liste_total,$gprintin->{$i}->{0}; 900 $gprintin->{$i}->{1}->{'draw'}=$drawlinein->{$i}->{'name'}; 901 $gprintin->{$i}->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 902 push @liste_total,"gprint"; 903 push @liste_total,$gprintin->{$i}->{1}; 904 $gprintin->{$i}->{2}->{'draw'}=$drawlinein->{$i}->{'name'}; 905 $gprintin->{$i}->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 906 push @liste_total,"gprint"; 907 push @liste_total,$gprintin->{$i}->{2}; 908 # ecriture de la courbe en output 909 $drawlineoutpositif->{$i}->{'type'} = "hidden"; 910 $drawlineoutpositif->{$i}->{'name'} = "outputpos$i"; 911 $drawlineoutpositif->{$i}->{'cdef'} = "$drawlineout->{$i}->{'name'},-1,*", 912 push @liste_total,"draw"; 913 push @liste_total,$drawlineout->{$i}; 914 # insere l'objet draw de type hidden avec les valeurs d'output positives 915 push @liste_total,"draw"; 916 push @liste_total,$drawlineoutpositif->{$i}; 917 $gprintout->{$i}->{0}->{'draw'}=$drawlineoutpositif->{$i}->{'name'}; 918 $gprintout->{$i}->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 919 $spaces = get_spaces($llegend{$i},$maxlengthlegend,-4); 920 push @liste_total,"comment"; 921 push @liste_total,$spaces; 922 push @liste_total,"gprint"; 923 push @liste_total,$gprintout->{$i}->{0}; 924 $gprintout->{$i}->{1}->{'draw'}=$drawlineoutpositif->{$i}->{'name'}; 925 $gprintout->{$i}->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 926 push @liste_total,"gprint"; 927 push @liste_total,$gprintout->{$i}->{1}; 928 $gprintout->{$i}->{2}->{'draw'}=$drawlineoutpositif->{$i}->{'name'}; 929 $gprintout->{$i}->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 930 push @liste_total,"gprint"; 931 push @liste_total,$gprintout->{$i}->{2}; 932 } 933 934 $rrd->graph( 935 image => "-", 936 title => "$commentaire", 937 vertical_label => "trafic", 938 height => $height, 939 width => $width, 940 start => $start, 941 end => $end, 942 @liste_arg1, 943 @liste_total, 944 ); 945} 946 947 948# cree une chaine de caracteres avec des espaces pour aligner les légendes 949# parametres : nombre de caracteres de la legende, nombre de car. de la légende 950# la plus longue, ajustement en nombre de blancs. 951sub get_spaces 952{ 953 my ($nb_char,$maxlengthlegend,$ajust) = @_; 954 955 my $string = " "; 956 957 my $nb_spaces = $maxlengthlegend - $nb_char + $ajust; 958 959 system("echo \"($nb_char,$maxlengthlegend,$ajust) => $nb_spaces\" >> /var/tmp/sortie.txt"); 960 961 for(my $i=0;$i<$nb_spaces;$i++) 962 { 963 $string = "$string "; 964 } 965 966 system("echo \"'$string'\" >> /var/tmp/sortie.txt"); 967 return $string; 968} 969 970 971sub GaugeAuthWiFi 972{ 973 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 974 975 # dereferencement 976 my @l = @$ref_l; 977 978 my ($width,$height) = split(/x/,$size); 979 980 my $couleur_osirissec = "0000ff"; 981 my $couleur_osiris = "00ff00"; 982 my $couleur_cumul = "bcbcbc"; 983 my $couleur_osiris_max = "a1ff00"; 984 my $couleur_osirissec_max = "00aaff"; 985 my $couleur_cumul_max = "cccccc"; 986 987 if($commentaire eq "") 988 { 989 $commentaire = "Clients WiFi authentifiés"; 990 } 991 992 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 993 994 my $osiris_sec = "osiris-sec"; 995 my $osiris = "osiris"; 996 ############################################ 997 # Hack temporaire pour le graphique global 998 # 999 if($ref_l->[0]->[0]->{'base'} =~ m/general\/authentifies_wifi\.rrd/) 1000 { 1001 $osiris_sec = "8021X"; 1002 $osiris = "portail_captif"; 1003 } 1004 ########################################### 1005 if(($end - $start) < 800000) 1006 { 1007 $rrd->graph( 1008 image => "-", 1009 title => "$commentaire", 1010 vertical_label => "nb authentifiés", 1011 lower_limit => 0, 1012 units_exponent => 0, 1013 height => $height, 1014 width => $width, 1015 start => $start, 1016 end => $end, 1017 draw => { 1018 type => "hidden", 1019 dsname => $osiris_sec, 1020 name => 'osiris-sec', 1021 cfunc => 'AVERAGE', 1022 }, 1023 draw => { 1024 type => "hidden", 1025 dsname => $osiris , 1026 name => 'osiris', 1027 cfunc => 'AVERAGE', 1028 }, 1029 comment => ' min max moyen actuel\n', 1030 draw => { 1031 type => 'area', 1032 color => $couleur_cumul, 1033 name => "cumul", 1034 cdef => "osiris,osiris-sec,ADDNAN", 1035 legend => 'total', 1036 }, 1037 comment => ' ', 1038 gprint => { 1039 draw => 'cumul', 1040 format => 'MIN:%5.0lf %S', 1041 }, 1042 gprint => { 1043 draw => 'cumul', 1044 format => 'MAX:%5.0lf %S', 1045 }, 1046 gprint => { 1047 draw => 'cumul', 1048 format => 'AVERAGE:%5.0lf %S', 1049 }, 1050 gprint => { 1051 draw => 'cumul', 1052 format => 'LAST:%5.0lf %S\\n', 1053 }, 1054 draw => { 1055 type => 'line', 1056 color => $couleur_osiris, 1057 cdef => "osiris", 1058 legend => 'osiris', 1059 }, 1060 comment => ' ', 1061 gprint => { 1062 draw => 'osiris', 1063 format => 'MIN:%5.0lf %S', 1064 }, 1065 gprint => { 1066 draw => 'osiris', 1067 format => 'MAX:%5.0lf %S', 1068 }, 1069 gprint => { 1070 draw => 'osiris', 1071 format => 'AVERAGE:%5.0lf %S', 1072 }, 1073 gprint => { 1074 draw => 'osiris', 1075 format => 'LAST:%5.0lf %S\\n', 1076 }, 1077 draw => { 1078 type => 'line', 1079 color => $couleur_osirissec, 1080 cdef => "osiris-sec", 1081 legend => '802.1X', 1082 }, 1083 comment => ' ', 1084 gprint => { 1085 draw => 'osiris-sec', 1086 format => 'MIN:%5.0lf %S', 1087 }, 1088 gprint => { 1089 draw => 'osiris-sec', 1090 format => 'MAX:%5.0lf %S', 1091 }, 1092 gprint => { 1093 draw => 'osiris-sec', 1094 format => 'AVERAGE:%5.0lf %S', 1095 }, 1096 gprint => { 1097 draw => 'osiris-sec', 1098 format => 'LAST:%5.0lf %S\\n', 1099 }, 1100 ); 1101 } 1102 else 1103 { 1104 $rrd->graph( 1105 image => "-", 1106 title => "$commentaire", 1107 vertical_label => "nb authentifiés", 1108 lower_limit => 0, 1109 units_exponent => 0, 1110 height => $height, 1111 width => $width, 1112 start => $start, 1113 end => $end, 1114 draw => { 1115 type => "hidden", 1116 dsname => $osiris_sec, 1117 name => 'osiris-sec', 1118 cfunc => 'AVERAGE', 1119 }, 1120 draw => { 1121 type => "hidden", 1122 dsname => $osiris, 1123 name => 'osiris', 1124 cfunc => 'AVERAGE', 1125 }, 1126 draw => { 1127 type => "hidden", 1128 dsname => $osiris_sec, 1129 name => 'maxosiris-sec', 1130 cfunc => 'MAX', 1131 }, 1132 draw => { 1133 type => "hidden", 1134 dsname => $osiris, 1135 name => 'maxosiris', 1136 cfunc => 'MAX', 1137 }, 1138 comment => ' min max moyen actuel\n', 1139 draw => { 1140 type => 'area', 1141 color => $couleur_cumul_max, 1142 name => "cumulmax", 1143 cdef => "maxosiris,maxosiris-sec,ADDNAN", 1144 legend => 'total crête', 1145 }, 1146 comment => ' ', 1147 gprint => { 1148 draw => 'cumulmax', 1149 format => 'MIN:%5.0lf %S', 1150 }, 1151 gprint => { 1152 draw => 'cumulmax', 1153 format => 'MAX:%5.0lf %S', 1154 }, 1155 gprint => { 1156 draw => 'cumulmax', 1157 format => 'AVERAGE:%5.0lf %S', 1158 }, 1159 gprint => { 1160 draw => 'cumulmax', 1161 format => 'LAST:%5.0lf %S\\n', 1162 }, 1163 draw => { 1164 type => 'area', 1165 color => $couleur_cumul, 1166 name => "cumul", 1167 cdef => "osiris,osiris-sec,ADDNAN", 1168 legend => 'total', 1169 }, 1170 comment => ' ', 1171 gprint => { 1172 draw => 'cumul', 1173 format => 'MIN:%5.0lf %S', 1174 }, 1175 gprint => { 1176 draw => 'cumul', 1177 format => 'MAX:%5.0lf %S', 1178 }, 1179 gprint => { 1180 draw => 'cumul', 1181 format => 'AVERAGE:%5.0lf %S', 1182 }, 1183 gprint => { 1184 draw => 'cumul', 1185 format => 'LAST:%5.0lf %S\\n', 1186 }, 1187 draw => { 1188 type => 'line', 1189 color => $couleur_osiris_max, 1190 cdef => "maxosiris", 1191 legend => 'osiris crête', 1192 }, 1193 comment => ' ', 1194 gprint => { 1195 draw => 'maxosiris', 1196 format => 'MIN:%5.0lf %S', 1197 }, 1198 gprint => { 1199 draw => 'maxosiris', 1200 format => 'MAX:%5.0lf %S', 1201 }, 1202 gprint => { 1203 draw => 'maxosiris', 1204 format => 'AVERAGE:%5.0lf %S', 1205 }, 1206 gprint => { 1207 draw => 'maxosiris', 1208 format => 'LAST:%5.0lf %S\\n', 1209 }, 1210 draw => { 1211 type => 'line', 1212 color => $couleur_osirissec_max, 1213 cdef => "maxosiris-sec", 1214 legend => '802.1X crête', 1215 }, 1216 comment => ' ', 1217 gprint => { 1218 draw => 'maxosiris-sec', 1219 format => 'MIN:%5.0lf %S', 1220 }, 1221 gprint => { 1222 draw => 'maxosiris-sec', 1223 format => 'MAX:%5.0lf %S', 1224 }, 1225 gprint => { 1226 draw => 'maxosiris-sec', 1227 format => 'AVERAGE:%5.0lf %S', 1228 }, 1229 gprint => { 1230 draw => 'maxosiris-sec', 1231 format => 'LAST:%5.0lf %S\\n', 1232 }, 1233 draw => { 1234 type => 'line', 1235 color => $couleur_osiris, 1236 cdef => "osiris", 1237 legend => 'osiris', 1238 }, 1239 comment => ' ', 1240 gprint => { 1241 draw => 'osiris', 1242 format => 'MIN:%5.0lf %S', 1243 }, 1244 gprint => { 1245 draw => 'osiris', 1246 format => 'MAX:%5.0lf %S', 1247 }, 1248 gprint => { 1249 draw => 'osiris', 1250 format => 'AVERAGE:%5.0lf %S', 1251 }, 1252 gprint => { 1253 draw => 'osiris', 1254 format => 'LAST:%5.0lf %S\\n', 1255 }, 1256 draw => { 1257 type => 'line', 1258 color => $couleur_osirissec, 1259 cdef => "osiris-sec", 1260 legend => '802.1X', 1261 }, 1262 comment => ' ', 1263 gprint => { 1264 draw => 'osiris-sec', 1265 format => 'MIN:%5.0lf %S', 1266 }, 1267 gprint => { 1268 draw => 'osiris-sec', 1269 format => 'MAX:%5.0lf %S', 1270 }, 1271 gprint => { 1272 draw => 'osiris-sec', 1273 format => 'AVERAGE:%5.0lf %S', 1274 }, 1275 gprint => { 1276 draw => 'osiris-sec', 1277 format => 'LAST:%5.0lf %S\\n', 1278 }, 1279 ); 1280 } 1281} 1282 1283 1284sub GaugeAssocWiFi 1285{ 1286 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 1287 1288 # dereferencement 1289 my @l = @$ref_l; 1290 1291 my ($width,$height) = split(/x/,$size); 1292 1293 my $couleur_osirissec = "ff0000"; 1294 my $couleur_osiris = "00ff00"; 1295 my $couleur_cumul = "bcbcbc"; 1296 my $couleur_osiris_max = "a1ff00"; 1297 my $couleur_osirissec_max = "ff91bd"; 1298 my $couleur_cumul_max = "cccccc"; 1299 1300 if($commentaire eq "") 1301 { 1302 $commentaire = "Clients WiFi associés"; 1303 } 1304 1305 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 1306 1307 if(($end - $start) < 800000) 1308 { 1309 $rrd->graph( 1310 image => "-", 1311 title => "$commentaire", 1312 vertical_label => "nb authentifiés", 1313 lower_limit => 0, 1314 units_exponent => 0, 1315 height => $height, 1316 width => $width, 1317 start => $start, 1318 end => $end, 1319 draw => { 1320 type => "hidden", 1321 dsname => "wpa", 1322 name => 'osiris-sec', 1323 cfunc => 'AVERAGE', 1324 }, 1325 draw => { 1326 type => "hidden", 1327 dsname => "clair", 1328 name => 'osiris', 1329 cfunc => 'AVERAGE', 1330 }, 1331 comment => ' min max moyen actuel\n', 1332 draw => { 1333 type => 'area', 1334 color => $couleur_cumul, 1335 name => "cumul", 1336 cdef => "osiris,osiris-sec,ADDNAN", 1337 legend => 'total', 1338 }, 1339 comment => ' ', 1340 gprint => { 1341 draw => 'cumul', 1342 format => 'MIN:%5.0lf %S', 1343 }, 1344 gprint => { 1345 draw => 'cumul', 1346 format => 'MAX:%5.0lf %S', 1347 }, 1348 gprint => { 1349 draw => 'cumul', 1350 format => 'AVERAGE:%5.0lf %S', 1351 }, 1352 gprint => { 1353 draw => 'cumul', 1354 format => 'LAST:%5.0lf %S\\n', 1355 }, 1356 draw => { 1357 type => 'line', 1358 color => $couleur_osiris, 1359 cdef => "osiris", 1360 legend => 'osiris', 1361 }, 1362 comment => ' ', 1363 gprint => { 1364 draw => 'osiris', 1365 format => 'MIN:%5.0lf %S', 1366 }, 1367 gprint => { 1368 draw => 'osiris', 1369 format => 'MAX:%5.0lf %S', 1370 }, 1371 gprint => { 1372 draw => 'osiris', 1373 format => 'AVERAGE:%5.0lf %S', 1374 }, 1375 gprint => { 1376 draw => 'osiris', 1377 format => 'LAST:%5.0lf %S\\n', 1378 }, 1379 draw => { 1380 type => 'line', 1381 color => $couleur_osirissec, 1382 cdef => "osiris-sec", 1383 legend => '802.1X', 1384 }, 1385 comment => ' ', 1386 gprint => { 1387 draw => 'osiris-sec', 1388 format => 'MIN:%5.0lf %S', 1389 }, 1390 gprint => { 1391 draw => 'osiris-sec', 1392 format => 'MAX:%5.0lf %S', 1393 }, 1394 gprint => { 1395 draw => 'osiris-sec', 1396 format => 'AVERAGE:%5.0lf %S', 1397 }, 1398 gprint => { 1399 draw => 'osiris-sec', 1400 format => 'LAST:%5.0lf %S\\n', 1401 }, 1402 ); 1403 } 1404 else 1405 { 1406 $rrd->graph( 1407 image => "-", 1408 title => "$commentaire", 1409 vertical_label => "nb authentifiés", 1410 lower_limit => 0, 1411 units_exponent => 0, 1412 height => $height, 1413 width => $width, 1414 start => $start, 1415 end => $end, 1416 draw => { 1417 type => "hidden", 1418 dsname => "wpa", 1419 name => 'osiris-sec', 1420 cfunc => 'AVERAGE', 1421 }, 1422 draw => { 1423 type => "hidden", 1424 dsname => "clair", 1425 name => 'osiris', 1426 cfunc => 'AVERAGE', 1427 }, 1428 draw => { 1429 type => "hidden", 1430 dsname => "wpa", 1431 name => 'maxosiris-sec', 1432 cfunc => 'MAX', 1433 }, 1434 draw => { 1435 type => "hidden", 1436 dsname => "clair", 1437 name => 'maxosiris', 1438 cfunc => 'MAX', 1439 }, 1440 comment => ' min max moyen actuel\n', 1441 draw => { 1442 type => 'area', 1443 color => $couleur_cumul_max, 1444 name => "cumulmax", 1445 cdef => "maxosiris,maxosiris-sec,ADDNAN", 1446 legend => 'total crête', 1447 }, 1448 comment => ' ', 1449 gprint => { 1450 draw => 'cumulmax', 1451 format => 'MIN:%5.0lf %S', 1452 }, 1453 gprint => { 1454 draw => 'cumulmax', 1455 format => 'MAX:%5.0lf %S', 1456 }, 1457 gprint => { 1458 draw => 'cumulmax', 1459 format => 'AVERAGE:%5.0lf %S', 1460 }, 1461 gprint => { 1462 draw => 'cumulmax', 1463 format => 'LAST:%5.0lf %S\\n', 1464 }, 1465 draw => { 1466 type => 'area', 1467 color => $couleur_cumul, 1468 name => "cumul", 1469 cdef => "osiris,osiris-sec,ADDNAN", 1470 legend => 'total', 1471 }, 1472 comment => ' ', 1473 gprint => { 1474 draw => 'cumul', 1475 format => 'MIN:%5.0lf %S', 1476 }, 1477 gprint => { 1478 draw => 'cumul', 1479 format => 'MAX:%5.0lf %S', 1480 }, 1481 gprint => { 1482 draw => 'cumul', 1483 format => 'AVERAGE:%5.0lf %S', 1484 }, 1485 gprint => { 1486 draw => 'cumul', 1487 format => 'LAST:%5.0lf %S\\n', 1488 }, 1489 draw => { 1490 type => 'line', 1491 color => $couleur_osiris_max, 1492 cdef => "maxosiris", 1493 legend => 'osiris crête', 1494 }, 1495 comment => ' ', 1496 gprint => { 1497 draw => 'maxosiris', 1498 format => 'MIN:%5.0lf %S', 1499 }, 1500 gprint => { 1501 draw => 'maxosiris', 1502 format => 'MAX:%5.0lf %S', 1503 }, 1504 gprint => { 1505 draw => 'maxosiris', 1506 format => 'AVERAGE:%5.0lf %S', 1507 }, 1508 gprint => { 1509 draw => 'maxosiris', 1510 format => 'LAST:%5.0lf %S\\n', 1511 }, 1512 draw => { 1513 type => 'line', 1514 color => $couleur_osirissec_max, 1515 cdef => "maxosiris-sec", 1516 legend => '802.1X crête', 1517 }, 1518 comment => ' ', 1519 gprint => { 1520 draw => 'maxosiris-sec', 1521 format => 'MIN:%5.0lf %S', 1522 }, 1523 gprint => { 1524 draw => 'maxosiris-sec', 1525 format => 'MAX:%5.0lf %S', 1526 }, 1527 gprint => { 1528 draw => 'maxosiris-sec', 1529 format => 'AVERAGE:%5.0lf %S', 1530 }, 1531 gprint => { 1532 draw => 'maxosiris-sec', 1533 format => 'LAST:%5.0lf %S\\n', 1534 }, 1535 draw => { 1536 type => 'line', 1537 color => $couleur_osiris, 1538 cdef => "osiris", 1539 legend => 'osiris', 1540 }, 1541 comment => ' ', 1542 gprint => { 1543 draw => 'osiris', 1544 format => 'MIN:%5.0lf %S', 1545 }, 1546 gprint => { 1547 draw => 'osiris', 1548 format => 'MAX:%5.0lf %S', 1549 }, 1550 gprint => { 1551 draw => 'osiris', 1552 format => 'AVERAGE:%5.0lf %S', 1553 }, 1554 gprint => { 1555 draw => 'osiris', 1556 format => 'LAST:%5.0lf %S\\n', 1557 }, 1558 draw => { 1559 type => 'line', 1560 color => $couleur_osirissec, 1561 cdef => "osiris-sec", 1562 legend => '802.1X', 1563 }, 1564 comment => ' ', 1565 gprint => { 1566 draw => 'osiris-sec', 1567 format => 'MIN:%5.0lf %S', 1568 }, 1569 gprint => { 1570 draw => 'osiris-sec', 1571 format => 'MAX:%5.0lf %S', 1572 }, 1573 gprint => { 1574 draw => 'osiris-sec', 1575 format => 'AVERAGE:%5.0lf %S', 1576 }, 1577 gprint => { 1578 draw => 'osiris-sec', 1579 format => 'LAST:%5.0lf %S\\n', 1580 }, 1581 ); 1582 } 1583} 1584 1585 1586sub GaugeDHCPleases 1587{ 1588 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 1589 1590 # dereferencement 1591 my @l = @$ref_l; 1592 1593 my ($width,$height) = split(/x/,$size); 1594 1595 my $couleur_inuse = "0000ff"; 1596 my $couleur_avail = "ff0000"; 1597 my $couleur_inuse_max = "a7c7cb"; 1598 1599 if($commentaire eq "") 1600 { 1601 $commentaire = "Baux DHCP actifs"; 1602 } 1603 1604 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 1605 1606 if(($end - $start) < 800000) 1607 { 1608 $rrd->graph( 1609 image => "-", 1610 title => "$commentaire", 1611 vertical_label => "nb baux DHCP", 1612 lower_limit => 0, 1613 units_exponent => 0, 1614 height => $height, 1615 width => $width, 1616 start => $start, 1617 end => $end, 1618 draw => { 1619 type => "hidden", 1620 dsname => "avail", 1621 name => 'avail', 1622 cfunc => 'AVERAGE', 1623 }, 1624 draw => { 1625 type => "hidden", 1626 dsname => "inuse", 1627 name => 'inuse', 1628 cfunc => 'AVERAGE', 1629 }, 1630 comment => ' min moyen actuel\n', 1631 draw => { 1632 type => 'line', 1633 color => $couleur_avail, 1634 cdef => "avail", 1635 legend => 'Adresses IP disponibles', 1636 }, 1637 comment => ' ', 1638 gprint => { 1639 draw => 'avail', 1640 format => 'MIN:%5.0lf %S', 1641 }, 1642 gprint => { 1643 draw => 'avail', 1644 format => 'AVERAGE:%5.0lf %S', 1645 }, 1646 gprint => { 1647 draw => 'avail', 1648 format => 'LAST:%5.0lf %S\\n', 1649 }, 1650 draw => { 1651 type => 'line', 1652 color => $couleur_inuse, 1653 cdef => "inuse", 1654 legend => 'Adresses IP allouées', 1655 }, 1656 comment => ' ', 1657 gprint => { 1658 draw => 'inuse', 1659 format => 'MIN:%5.0lf %S', 1660 }, 1661 gprint => { 1662 draw => 'inuse', 1663 format => 'AVERAGE:%5.0lf %S', 1664 }, 1665 gprint => { 1666 draw => 'inuse', 1667 format => 'LAST:%5.0lf %S\\n', 1668 }, 1669 ); 1670 } 1671 else 1672 { 1673 $rrd->graph( 1674 image => "-", 1675 title => "$commentaire", 1676 vertical_label => "nb baux DHCP", 1677 lower_limit => 0, 1678 units_exponent => 0, 1679 height => $height, 1680 width => $width, 1681 start => $start, 1682 end => $end, 1683 draw => { 1684 type => "hidden", 1685 dsname => "avail", 1686 name => 'avail', 1687 cfunc => 'AVERAGE', 1688 }, 1689 draw => { 1690 type => "hidden", 1691 dsname => "inuse", 1692 name => 'inuse', 1693 cfunc => 'AVERAGE', 1694 }, 1695 draw => { 1696 type => "hidden", 1697 dsname => "inuse", 1698 name => 'maxinuse', 1699 cfunc => 'MAX', 1700 }, 1701 comment => ' min moyen actuel\n', 1702 draw => { 1703 type => 'line', 1704 color => $couleur_avail, 1705 cdef => "avail", 1706 legend => 'Adresses IP disponibles', 1707 }, 1708 comment => ' ', 1709 gprint => { 1710 draw => 'avail', 1711 format => 'MIN:%5.0lf %S', 1712 }, 1713 gprint => { 1714 draw => 'avail', 1715 format => 'AVERAGE:%5.0lf %S', 1716 }, 1717 gprint => { 1718 draw => 'avail', 1719 format => 'LAST:%5.0lf %S\\n', 1720 }, 1721 draw => { 1722 type => 'line', 1723 color => $couleur_inuse_max, 1724 cdef => "maxinuse", 1725 legend => 'Adresses IP allouées (en crête)', 1726 }, 1727 comment => ' ', 1728 gprint => { 1729 draw => 'maxinuse', 1730 format => 'MIN:%5.0lf %S', 1731 }, 1732 gprint => { 1733 draw => 'maxinuse', 1734 format => 'AVERAGE:%5.0lf %S', 1735 }, 1736 gprint => { 1737 draw => 'maxinuse', 1738 format => 'LAST:%5.0lf %S\\n', 1739 }, 1740 draw => { 1741 type => 'line', 1742 color => $couleur_inuse, 1743 cdef => "inuse", 1744 legend => 'Adresses IP allouées (en moyenne)', 1745 }, 1746 comment => ' ', 1747 gprint => { 1748 draw => 'inuse', 1749 format => 'MIN:%5.0lf %S', 1750 }, 1751 gprint => { 1752 draw => 'inuse', 1753 format => 'AVERAGE:%5.0lf %S', 1754 }, 1755 gprint => { 1756 draw => 'inuse', 1757 format => 'LAST:%5.0lf %S\\n', 1758 }, 1759 ); 1760 } 1761} 1762 1763 1764# afficher l'utilisation moyenne de la CPU des equipements Juniper 1765# sur les slots O et 1 des ssb et RE 1766sub GaugeCPUJuniper 1767{ 1768 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 1769 1770 # dereferencement 1771 my @l = @$ref_l; 1772 1773 my ($width,$height) = split(/x/,$size); 1774 1775 my $couleur0 = "8888ff"; 1776 my $couleur1 = "0000ff"; 1777 1778 if($commentaire eq "") 1779 { 1780 $commentaire = "Utilisation CPU en %"; 1781 } 1782 1783 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 1784 1785 $rrd->graph( 1786 image => "-", 1787 title => "$commentaire", 1788 vertical_label => "% CPU", 1789 lower_limit => 0, 1790 units_exponent => 0, 1791 height => $height, 1792 width => $width, 1793 start => $start, 1794 end => $end, 1795 draw => { 1796 type => "hidden", 1797 dsname => "cpu0", 1798 name => 'cpu0', 1799 cfunc => 'AVERAGE', 1800 }, 1801 draw => { 1802 type => "hidden", 1803 dsname => "cpu1", 1804 name => 'cpu1', 1805 cfunc => 'AVERAGE', 1806 }, 1807 comment => ' min max moyen actuel\n', 1808 draw => { 1809 type => 'line', 1810 color => $couleur0, 1811 cdef => "cpu0", 1812 legend => 'CPU sur le slot 0', 1813 }, 1814 comment => ' ', 1815 gprint => { 1816 draw => 'cpu0', 1817 format => 'MIN:%5.0lf %S', 1818 }, 1819 gprint => { 1820 draw => 'cpu0', 1821 format => 'MAX:%5.0lf %S', 1822 }, 1823 gprint => { 1824 draw => 'cpu0', 1825 format => 'AVERAGE:%5.0lf %S', 1826 }, 1827 gprint => { 1828 draw => 'cpu0', 1829 format => 'LAST:%5.0lf %S\\n', 1830 }, 1831 draw => { 1832 type => 'line', 1833 color => $couleur1, 1834 cdef => "cpu1", 1835 legend => 'CPU sur le slot 1', 1836 }, 1837 comment => ' ', 1838 gprint => { 1839 draw => 'cpu1', 1840 format => 'MIN:%5.0lf %S', 1841 }, 1842 gprint => { 1843 draw => 'cpu1', 1844 format => 'MAX:%5.0lf %S', 1845 }, 1846 gprint => { 1847 draw => 'cpu1', 1848 format => 'AVERAGE:%5.0lf %S', 1849 }, 1850 gprint => { 1851 draw => 'cpu1', 1852 format => 'LAST:%5.0lf %S\\n', 1853 }, 1854 ); 1855} 1856 1857 1858# afficher l'utilisation moyenne de la CPU des equipements Cisco 1859# sur 1m et sur 5m 1860sub GaugeCPUCisco 1861{ 1862 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 1863 1864 # dereferencement 1865 my @l = @$ref_l; 1866 1867 my ($width,$height) = split(/x/,$size); 1868 1869 my $couleur_1min = "8888ff"; 1870 my $couleur_5min = "0000ff"; 1871 1872 if($commentaire eq "") 1873 { 1874 $commentaire = "Utilisation CPU en %"; 1875 } 1876 1877 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 1878 1879 $rrd->graph( 1880 image => "-", 1881 title => "$commentaire", 1882 vertical_label => "% CPU", 1883 lower_limit => 0, 1884 units_exponent => 0, 1885 height => $height, 1886 width => $width, 1887 start => $start, 1888 end => $end, 1889 draw => { 1890 type => "hidden", 1891 dsname => "cpu_1min", 1892 name => 'cpu_1min', 1893 cfunc => 'AVERAGE', 1894 }, 1895 draw => { 1896 type => "hidden", 1897 dsname => "cpu_5min", 1898 name => 'cpu_5min', 1899 cfunc => 'AVERAGE', 1900 }, 1901 comment => ' min max moyen actuel\n', 1902 draw => { 1903 type => 'line', 1904 color => $couleur_1min, 1905 cdef => "cpu_1min", 1906 legend => 'Moyenne sur 1 minute', 1907 }, 1908 comment => ' ', 1909 gprint => { 1910 draw => 'cpu_1min', 1911 format => 'MIN:%5.0lf %S', 1912 }, 1913 gprint => { 1914 draw => 'cpu_1min', 1915 format => 'MAX:%5.0lf %S', 1916 }, 1917 gprint => { 1918 draw => 'cpu_1min', 1919 format => 'AVERAGE:%5.0lf %S', 1920 }, 1921 gprint => { 1922 draw => 'cpu_1min', 1923 format => 'LAST:%5.0lf %S\\n', 1924 }, 1925 draw => { 1926 type => 'line', 1927 color => $couleur_5min, 1928 cdef => "cpu_5min", 1929 legend => 'Moyenne sur 5 minutes', 1930 }, 1931 comment => ' ', 1932 gprint => { 1933 draw => 'cpu_5min', 1934 format => 'MIN:%5.0lf %S', 1935 }, 1936 gprint => { 1937 draw => 'cpu_5min', 1938 format => 'MAX:%5.0lf %S', 1939 }, 1940 gprint => { 1941 draw => 'cpu_5min', 1942 format => 'AVERAGE:%5.0lf %S', 1943 }, 1944 gprint => { 1945 draw => 'cpu_5min', 1946 format => 'LAST:%5.0lf %S\\n', 1947 }, 1948 ); 1949} 1950 1951 1952# afficher pour un serveur l'utilisation moyenne de la CPU 1953# par le système et en mode user 1954sub GaugeCPUServer 1955{ 1956 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 1957 1958 # dereferencement 1959 my @l = @$ref_l; 1960 1961 my ($width,$height) = split(/x/,$size); 1962 1963 my $system = "ff0000"; 1964 my $user = "0000ff"; 1965 my $couleur_cumul = "707070"; 1966 1967 if($commentaire eq "") 1968 { 1969 $commentaire = "Utilisation CPU en %"; 1970 } 1971 1972 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 1973 1974 $rrd->graph( 1975 image => "-", 1976 title => "$commentaire", 1977 vertical_label => "% CPU", 1978 lower_limit => 0, 1979 units_exponent => 0, 1980 height => $height, 1981 width => $width, 1982 start => $start, 1983 end => $end, 1984 draw => { 1985 type => "hidden", 1986 dsname => "cpu_system", 1987 name => 'cpu_system', 1988 cfunc => 'AVERAGE', 1989 }, 1990 draw => { 1991 type => "hidden", 1992 dsname => "cpu_user", 1993 name => 'cpu_user', 1994 cfunc => 'AVERAGE', 1995 }, 1996 comment => ' min max moyen actuel\n', 1997 draw => { 1998 type => 'area', 1999 color => $couleur_cumul, 2000 name => "total", 2001 cdef => "cpu_system,cpu_user,ADDNAN", 2002 legend => 'total', 2003 }, 2004 comment => ' ', 2005 gprint => { 2006 draw => 'total', 2007 format => 'MIN:%5.0lf %S', 2008 }, 2009 gprint => { 2010 draw => 'total', 2011 format => 'MAX:%5.0lf %S', 2012 }, 2013 gprint => { 2014 draw => 'total', 2015 format => 'AVERAGE:%5.0lf %S', 2016 }, 2017 gprint => { 2018 draw => 'total', 2019 format => 'LAST:%5.0lf %S\\n', 2020 }, 2021 draw => { 2022 type => 'line', 2023 color => $system, 2024 cdef => "cpu_system", 2025 legend => 'system', 2026 }, 2027 comment => ' ', 2028 gprint => { 2029 draw => 'cpu_system', 2030 format => 'MIN:%5.0lf %S', 2031 }, 2032 gprint => { 2033 draw => 'cpu_system', 2034 format => 'MAX:%5.0lf %S', 2035 }, 2036 gprint => { 2037 draw => 'cpu_system', 2038 format => 'AVERAGE:%5.0lf %S', 2039 }, 2040 gprint => { 2041 draw => 'cpu_system', 2042 format => 'LAST:%5.0lf %S\\n', 2043 }, 2044 draw => { 2045 type => 'line', 2046 color => $user, 2047 cdef => "cpu_user", 2048 legend => 'user', 2049 }, 2050 comment => ' ', 2051 gprint => { 2052 draw => 'cpu_user', 2053 format => 'MIN:%5.0lf %S', 2054 }, 2055 gprint => { 2056 draw => 'cpu_user', 2057 format => 'MAX:%5.0lf %S', 2058 }, 2059 gprint => { 2060 draw => 'cpu_user', 2061 format => 'AVERAGE:%5.0lf %S', 2062 }, 2063 gprint => { 2064 draw => 'cpu_user', 2065 format => 'LAST:%5.0lf %S\\n', 2066 }, 2067 ); 2068} 2069 2070 2071# affiche la charge d'un serveur sur 5 minutes et 15 minutes 2072sub GaugeLoadAverage 2073{ 2074 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2075 2076 # dereferencement 2077 my @l = @$ref_l; 2078 2079 my ($width,$height) = split(/x/,$size); 2080 2081 my $couleur_5min = "0000ff"; 2082 my $couleur_15min = "ff6000"; 2083 2084 if($commentaire eq "") 2085 { 2086 $commentaire = "Load Average"; 2087 } 2088 2089 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2090 2091 $rrd->graph( 2092 image => "-", 2093 title => "$commentaire", 2094 vertical_label => "Load Average", 2095 lower_limit => 0, 2096 units_exponent => 0, 2097 height => $height, 2098 width => $width, 2099 start => $start, 2100 end => $end, 2101 draw => { 2102 type => "hidden", 2103 dsname => "load_5m", 2104 name => 'load_5m', 2105 cfunc => 'AVERAGE', 2106 }, 2107 draw => { 2108 type => "hidden", 2109 dsname => "load_15m", 2110 name => 'load_15m', 2111 cfunc => 'AVERAGE', 2112 }, 2113 comment => ' min max moyen actuel\n', 2114 draw => { 2115 type => 'line', 2116 color => $couleur_5min, 2117 cdef => "load_5m", 2118 legend => 'Moyenne sur 5 minutes', 2119 }, 2120 comment => ' ', 2121 gprint => { 2122 draw => 'load_5m', 2123 format => 'MIN:%3.2lf', 2124 }, 2125 gprint => { 2126 draw => 'load_5m', 2127 format => 'MAX:%3.2lf', 2128 }, 2129 gprint => { 2130 draw => 'load_5m', 2131 format => 'AVERAGE:%3.2lf', 2132 }, 2133 gprint => { 2134 draw => 'load_5m', 2135 format => 'LAST:%3.2lf\\n', 2136 }, 2137 draw => { 2138 type => 'line', 2139 color => $couleur_15min, 2140 cdef => "load_15m", 2141 legend => 'Moyenne sur 15 minutes', 2142 }, 2143 comment => ' ', 2144 gprint => { 2145 draw => 'load_15m', 2146 format => 'MIN:%3.2lf', 2147 }, 2148 gprint => { 2149 draw => 'load_15m', 2150 format => 'MAX:%3.2lf', 2151 }, 2152 gprint => { 2153 draw => 'load_15m', 2154 format => 'AVERAGE:%3.2lf', 2155 }, 2156 gprint => { 2157 draw => 'load_15m', 2158 format => 'LAST:%3.2lf\\n', 2159 }, 2160 ); 2161} 2162 2163 2164# affichage generique d'une gauge 2165# 2166sub GaugeRespTime 2167{ 2168 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2169 2170 # dereferencement 2171 my @l = @$ref_l; 2172 2173 my ($width,$height) = split(/x/,$size); 2174 2175 my $couleur = "0000ff"; 2176 2177 if($commentaire eq "") 2178 { 2179 $commentaire = "Temps de réponse"; 2180 } 2181 2182 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2183 2184 $rrd->graph( 2185 image => "-", 2186 title => "$commentaire", 2187 vertical_label => "Temps de réponse (sec)", 2188 lower_limit => 0, 2189 units_exponent => 0, 2190 height => $height, 2191 width => $width, 2192 start => $start, 2193 end => $end, 2194 draw => { 2195 type => "hidden", 2196 dsname => "time", 2197 name => 'time', 2198 cfunc => 'AVERAGE', 2199 }, 2200 comment => ' min max moyen actuel\n', 2201 draw => { 2202 type => 'line', 2203 color => $couleur, 2204 cdef => "time", 2205 legend => 'temps de réponse (s)', 2206 }, 2207 comment => ' ', 2208 gprint => { 2209 draw => 'time', 2210 format => 'MIN:%3.3lf', 2211 }, 2212 gprint => { 2213 draw => 'time', 2214 format => 'MAX:%3.3lf', 2215 }, 2216 gprint => { 2217 draw => 'time', 2218 format => 'AVERAGE:%3.3lf', 2219 }, 2220 gprint => { 2221 draw => 'time', 2222 format => 'LAST:%3.3lf\\n', 2223 }, 2224 ); 2225} 2226 2227 2228# afficher le nombre de transactions par secondes pour un disque 2229# en lecture et en ecriture 2230sub GaugeTPSDisk 2231{ 2232 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2233 2234 # dereferencement 2235 my @l = @$ref_l; 2236 2237 my ($width,$height) = split(/x/,$size); 2238 2239 my $couleur_IOreads = "00ff00"; 2240 my $couleur_IOwrites = "ffff00"; 2241 my $couleur_cumul = "707070"; 2242 2243 if($commentaire eq "") 2244 { 2245 $commentaire = "Transactions par seconde"; 2246 } 2247 2248 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2249 2250 $rrd->graph( 2251 image => "-", 2252 title => "$commentaire", 2253 vertical_label => "TPS", 2254 lower_limit => 0, 2255 units_exponent => 0, 2256 height => $height, 2257 width => $width, 2258 start => $start, 2259 end => $end, 2260 draw => { 2261 type => "hidden", 2262 dsname => "ioreads", 2263 name => 'IOreads', 2264 cfunc => 'AVERAGE', 2265 }, 2266 draw => { 2267 type => "hidden", 2268 dsname => "iowrites", 2269 name => 'IOwrites', 2270 cfunc => 'AVERAGE', 2271 }, 2272 comment => ' min max moyen actuel\n', 2273 draw => { 2274 type => 'area', 2275 color => $couleur_cumul, 2276 name => "total", 2277 cdef => "IOreads,IOwrites,+", 2278 legend => 'total', 2279 }, 2280 comment => ' ', 2281 gprint => { 2282 draw => 'total', 2283 format => 'MIN:%5.0lf %S', 2284 }, 2285 gprint => { 2286 draw => 'total', 2287 format => 'MAX:%5.0lf %S', 2288 }, 2289 gprint => { 2290 draw => 'total', 2291 format => 'AVERAGE:%5.0lf %S', 2292 }, 2293 gprint => { 2294 draw => 'total', 2295 format => 'LAST:%5.0lf %S\\n', 2296 }, 2297 draw => { 2298 type => 'line', 2299 color => $couleur_IOreads, 2300 cdef => "IOreads", 2301 legend => 'IOreads', 2302 }, 2303 comment => ' ', 2304 gprint => { 2305 draw => 'IOreads', 2306 format => 'MIN:%5.0lf %S', 2307 }, 2308 gprint => { 2309 draw => 'IOreads', 2310 format => 'MAX:%5.0lf %S', 2311 }, 2312 gprint => { 2313 draw => 'IOreads', 2314 format => 'AVERAGE:%5.0lf %S', 2315 }, 2316 gprint => { 2317 draw => 'IOreads', 2318 format => 'LAST:%5.0lf %S\\n', 2319 }, 2320 draw => { 2321 type => 'line', 2322 color => $couleur_IOwrites, 2323 cdef => "IOwrites", 2324 legend => 'IOwrites', 2325 }, 2326 comment => ' ', 2327 gprint => { 2328 draw => 'IOwrites', 2329 format => 'MIN:%5.0lf %S', 2330 }, 2331 gprint => { 2332 draw => 'IOwrites', 2333 format => 'MAX:%5.0lf %S', 2334 }, 2335 gprint => { 2336 draw => 'IOwrites', 2337 format => 'AVERAGE:%5.0lf %S', 2338 }, 2339 gprint => { 2340 draw => 'IOwrites', 2341 format => 'LAST:%5.0lf %S\\n', 2342 }, 2343 ); 2344} 2345 2346 2347 2348# 2349# 2350sub GaugeBind 2351{ 2352 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2353 2354 # dereferencement 2355 my @l = @$ref_l; 2356 2357 my ($width,$height) = split(/x/,$size); 2358 2359 my $couleur_success = "00ff00"; 2360 my $couleur_failure = "ffff00"; 2361 my $couleur_nxdomain = "00ffdc"; 2362 my $couleur_recursion = "f600ff"; 2363 my $couleur_referral = "0000ff"; 2364 my $couleur_nxrrset = "ff0000"; 2365 my $couleur_cumul = "cccccc"; 2366 2367 if($commentaire eq "") 2368 { 2369 $commentaire = "Statistiques des requêtes DNS"; 2370 } 2371 2372 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2373 2374 $rrd->graph( 2375 image => "-", 2376 title => "$commentaire", 2377 vertical_label => "Requêtes/s", 2378 lower_limit => 0, 2379 units_exponent => 0, 2380 height => $height, 2381 width => $width, 2382 start => $start, 2383 end => $end, 2384 draw => { 2385 type => "hidden", 2386 dsname => "success", 2387 name => 'success', 2388 cfunc => 'AVERAGE', 2389 }, 2390 draw => { 2391 type => "hidden", 2392 dsname => "failure", 2393 name => 'failure', 2394 cfunc => 'AVERAGE', 2395 }, 2396 draw => { 2397 type => "hidden", 2398 dsname => "nxdomain", 2399 name => 'nxdomain', 2400 cfunc => 'AVERAGE', 2401 }, 2402 draw => { 2403 type => "hidden", 2404 dsname => "recursion", 2405 name => 'recursion', 2406 cfunc => 'AVERAGE', 2407 }, 2408 draw => { 2409 type => "hidden", 2410 dsname => "referral", 2411 name => 'referral', 2412 cfunc => 'AVERAGE', 2413 }, 2414 draw => { 2415 type => "hidden", 2416 dsname => "nxrrset", 2417 name => 'nxrrset', 2418 cfunc => 'AVERAGE', 2419 }, 2420 comment => ' min max moyen actuel\n', 2421 draw => { 2422 type => 'area', 2423 color => $couleur_cumul, 2424 name => "total", 2425 cdef => "success,failure,+,nxdomain,+,recursion,+,referral,+,nxrrset,+", 2426 legend => 'total', 2427 }, 2428 comment => ' ', 2429 gprint => { 2430 draw => 'total', 2431 format => 'MIN:%5.0lf', 2432 }, 2433 gprint => { 2434 draw => 'total', 2435 format => 'MAX:%5.0lf', 2436 }, 2437 gprint => { 2438 draw => 'total', 2439 format => 'AVERAGE:%5.0lf', 2440 }, 2441 gprint => { 2442 draw => 'total', 2443 format => 'LAST:%5.0lf\\n', 2444 }, 2445 draw => { 2446 type => 'line', 2447 color => $couleur_success, 2448 cdef => "success", 2449 legend => 'success', 2450 }, 2451 comment => ' ', 2452 gprint => { 2453 draw => 'success', 2454 format => 'MIN:%5.0lf', 2455 }, 2456 gprint => { 2457 draw => 'success', 2458 format => 'MAX:%5.0lf', 2459 }, 2460 gprint => { 2461 draw => 'success', 2462 format => 'AVERAGE:%5.0lf', 2463 }, 2464 gprint => { 2465 draw => 'success', 2466 format => 'LAST:%5.0lf\\n', 2467 }, 2468 draw => { 2469 type => 'line', 2470 color => $couleur_failure, 2471 cdef => "failure", 2472 legend => 'failure', 2473 }, 2474 comment => ' ', 2475 gprint => { 2476 draw => 'failure', 2477 format => 'MIN:%5.0lf', 2478 }, 2479 gprint => { 2480 draw => 'failure', 2481 format => 'MAX:%5.0lf', 2482 }, 2483 gprint => { 2484 draw => 'failure', 2485 format => 'AVERAGE:%5.0lf', 2486 }, 2487 gprint => { 2488 draw => 'failure', 2489 format => 'LAST:%5.0lf\\n', 2490 }, 2491 draw => { 2492 type => 'line', 2493 color => $couleur_nxdomain, 2494 cdef => "nxdomain", 2495 legend => 'nxdomain', 2496 }, 2497 comment => ' ', 2498 gprint => { 2499 draw => 'nxdomain', 2500 format => 'MIN:%5.0lf', 2501 }, 2502 gprint => { 2503 draw => 'nxdomain', 2504 format => 'MAX:%5.0lf', 2505 }, 2506 gprint => { 2507 draw => 'nxdomain', 2508 format => 'AVERAGE:%5.0lf', 2509 }, 2510 gprint => { 2511 draw => 'nxdomain', 2512 format => 'LAST:%5.0lf\\n', 2513 }, 2514 draw => { 2515 type => 'line', 2516 color => $couleur_recursion, 2517 cdef => "recursion", 2518 legend => 'recursion', 2519 }, 2520 comment => ' ', 2521 gprint => { 2522 draw => 'recursion', 2523 format => 'MIN:%5.0lf', 2524 }, 2525 gprint => { 2526 draw => 'recursion', 2527 format => 'MAX:%5.0lf', 2528 }, 2529 gprint => { 2530 draw => 'recursion', 2531 format => 'AVERAGE:%5.0lf', 2532 }, 2533 gprint => { 2534 draw => 'recursion', 2535 format => 'LAST:%5.0lf\\n', 2536 }, 2537 draw => { 2538 type => 'line', 2539 color => $couleur_referral, 2540 cdef => "referral", 2541 legend => 'referral', 2542 }, 2543 comment => ' ', 2544 gprint => { 2545 draw => 'referral', 2546 format => 'MIN:%5.0lf', 2547 }, 2548 gprint => { 2549 draw => 'referral', 2550 format => 'MAX:%5.0lf', 2551 }, 2552 gprint => { 2553 draw => 'referral', 2554 format => 'AVERAGE:%5.0lf', 2555 }, 2556 gprint => { 2557 draw => 'referral', 2558 format => 'LAST:%5.0lf\\n', 2559 }, 2560 draw => { 2561 type => 'line', 2562 color => $couleur_nxrrset, 2563 cdef => "nxrrset", 2564 legend => 'nxrrset', 2565 }, 2566 comment => ' ', 2567 gprint => { 2568 draw => 'nxrrset', 2569 format => 'MIN:%5.0lf', 2570 }, 2571 gprint => { 2572 draw => 'nxrrset', 2573 format => 'MAX:%5.0lf', 2574 }, 2575 gprint => { 2576 draw => 'nxrrset', 2577 format => 'AVERAGE:%5.0lf', 2578 }, 2579 gprint => { 2580 draw => 'nxrrset', 2581 format => 'LAST:%5.0lf\\n', 2582 }, 2583 ); 2584} 2585 2586 2587# affichage generique d'une gauge 2588# 2589sub GaugeGeneric 2590{ 2591 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2592 2593 # dereferencement 2594 my @l = @$ref_l; 2595 2596 my ($width,$height) = split(/x/,$size); 2597 2598 $couleur_current = "0000ff"; 2599 $couleur_max = "ffa1e9"; 2600 2601 if($commentaire eq "") 2602 { 2603 $commentaire = "unités"; 2604 } 2605 2606 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2607 2608 if(($end - $start) < 800000) 2609 { 2610 $rrd->graph( 2611 image => "-", 2612 title => "$commentaire", 2613 vertical_label => "jauge", 2614 lower_limit => 0, 2615 units_exponent => 0, 2616 height => $height, 2617 width => $width, 2618 start => $start, 2619 end => $end, 2620 draw => { 2621 type => "hidden", 2622 dsname => "value", 2623 name => 'value', 2624 cfunc => 'AVERAGE', 2625 }, 2626 comment => ' min max moyen actuel\n', 2627 draw => { 2628 type => 'line', 2629 color => $couleur_current, 2630 cdef => "value", 2631 legend => $commentaire, 2632 }, 2633 comment => ' ', 2634 gprint => { 2635 draw => 'value', 2636 format => 'MIN:%7.0lf', 2637 }, 2638 gprint => { 2639 draw => 'value', 2640 format => 'MAX:%7.0lf', 2641 }, 2642 gprint => { 2643 draw => 'value', 2644 format => 'AVERAGE:%7.0lf', 2645 }, 2646 gprint => { 2647 draw => 'value', 2648 format => 'LAST:%7.0lf\\n', 2649 }, 2650 ); 2651 } 2652 else 2653 { 2654 $rrd->graph( 2655 image => "-", 2656 title => "$commentaire", 2657 vertical_label => "jauge", 2658 lower_limit => 0, 2659 units_exponent => 0, 2660 height => $height, 2661 width => $width, 2662 start => $start, 2663 end => $end, 2664 draw => { 2665 type => "hidden", 2666 dsname => "value", 2667 name => 'value', 2668 cfunc => 'AVERAGE', 2669 }, 2670 draw => { 2671 type => "hidden", 2672 dsname => "value", 2673 name => 'maxvalue', 2674 cfunc => 'MAX', 2675 }, 2676 comment => ' min max moyen actuel\n', 2677 draw => { 2678 type => 'line', 2679 color => $couleur_max, 2680 cdef => "maxvalue", 2681 legend => "$commentaire (en crête)", 2682 }, 2683 comment => ' ', 2684 gprint => { 2685 draw => 'maxvalue', 2686 format => 'MIN:%7.0lf', 2687 }, 2688 gprint => { 2689 draw => 'maxvalue', 2690 format => 'MAX:%7.0lf', 2691 }, 2692 gprint => { 2693 draw => 'maxvalue', 2694 format => 'AVERAGE:%7.0lf', 2695 }, 2696 gprint => { 2697 draw => 'maxvalue', 2698 format => 'LAST:%7.0lf\\n', 2699 }, 2700 draw => { 2701 type => 'line', 2702 color => $couleur_current, 2703 cdef => "value", 2704 legend => "$commentaire (en moyenne)", 2705 }, 2706 comment => ' ', 2707 gprint => { 2708 draw => 'value', 2709 format => 'MIN:%7.0lf', 2710 }, 2711 gprint => { 2712 draw => 'value', 2713 format => 'MAX:%7.0lf', 2714 }, 2715 gprint => { 2716 draw => 'value', 2717 format => 'AVERAGE:%7.0lf', 2718 }, 2719 gprint => { 2720 draw => 'value', 2721 format => 'LAST:%7.0lf\\n', 2722 }, 2723 ); 2724 } 2725} 2726 2727 2728# affichage de la mailqueue d'un relayeur 2729# 2730sub GaugeMailq 2731{ 2732 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2733 2734 # dereferencement 2735 my @l = @$ref_l; 2736 2737 my ($width,$height) = split(/x/,$size); 2738 2739 $couleur_current = "9cfc15"; 2740 $couleur_max = "ffa1e9"; 2741 2742 if($commentaire eq "") 2743 { 2744 $commentaire = "taille de la mailq"; 2745 } 2746 2747 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2748 2749 if(($end - $start) < 800000) 2750 { 2751 $rrd->graph( 2752 image => "-", 2753 title => "$commentaire", 2754 vertical_label => "nb mails", 2755 lower_limit => 0, 2756 units_exponent => 0, 2757 height => $height, 2758 width => $width, 2759 start => $start, 2760 end => $end, 2761 draw => { 2762 type => "hidden", 2763 dsname => "mailq", 2764 name => 'mailq', 2765 cfunc => 'AVERAGE', 2766 }, 2767 comment => ' min max moyen actuel\n', 2768 draw => { 2769 type => 'area', 2770 color => $couleur_current, 2771 cdef => "mailq", 2772 legend => $commentaire, 2773 }, 2774 comment => ' ', 2775 gprint => { 2776 draw => 'mailq', 2777 format => 'MIN:%7.0lf', 2778 }, 2779 gprint => { 2780 draw => 'mailq', 2781 format => 'MAX:%7.0lf', 2782 }, 2783 gprint => { 2784 draw => 'mailq', 2785 format => 'AVERAGE:%7.0lf', 2786 }, 2787 gprint => { 2788 draw => 'mailq', 2789 format => 'LAST:%7.0lf\\n', 2790 }, 2791 ); 2792 } 2793 else 2794 { 2795 $rrd->graph( 2796 image => "-", 2797 title => "$commentaire", 2798 vertical_label => "jauge", 2799 lower_limit => 0, 2800 units_exponent => 0, 2801 height => $height, 2802 width => $width, 2803 start => $start, 2804 end => $end, 2805 draw => { 2806 type => "hidden", 2807 dsname => "mailq", 2808 name => 'mailq', 2809 cfunc => 'AVERAGE', 2810 }, 2811 draw => { 2812 type => "hidden", 2813 dsname => "mailq", 2814 name => 'maxmailq', 2815 cfunc => 'MAX', 2816 }, 2817 comment => ' min max moyen actuel\n', 2818 draw => { 2819 type => 'area', 2820 color => $couleur_max, 2821 cdef => "maxmailq", 2822 legend => "$commentaire (en crête)", 2823 }, 2824 comment => ' ', 2825 gprint => { 2826 draw => 'maxmailq', 2827 format => 'MIN:%7.0lf', 2828 }, 2829 gprint => { 2830 draw => 'maxmailq', 2831 format => 'MAX:%7.0lf', 2832 }, 2833 gprint => { 2834 draw => 'maxmailq', 2835 format => 'AVERAGE:%7.0lf', 2836 }, 2837 gprint => { 2838 draw => 'maxmailq', 2839 format => 'LAST:%7.0lf\\n', 2840 }, 2841 draw => { 2842 type => 'area', 2843 color => $couleur_current, 2844 cdef => "mailq", 2845 legend => "$commentaire (en moyenne)", 2846 }, 2847 comment => ' ', 2848 gprint => { 2849 draw => 'mailq', 2850 format => 'MIN:%7.0lf', 2851 }, 2852 gprint => { 2853 draw => 'mailq', 2854 format => 'MAX:%7.0lf', 2855 }, 2856 gprint => { 2857 draw => 'mailq', 2858 format => 'AVERAGE:%7.0lf', 2859 }, 2860 gprint => { 2861 draw => 'mailq', 2862 format => 'LAST:%7.0lf\\n', 2863 }, 2864 ); 2865 } 2866} 2867 2868 2869 2870# affichage de la mémoire utilisée par un process 2871# 2872sub GaugeMemByProc 2873{ 2874 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 2875 2876 # dereferencement 2877 my @l = @$ref_l; 2878 2879 my ($width,$height) = split(/x/,$size); 2880 2881 $couleur_current = "9cfc15"; 2882 $couleur_max = "ffa1e9"; 2883 2884 if($commentaire eq "") 2885 { 2886 $commentaire = "place en mémoire"; 2887 } 2888 2889 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 2890 2891 if(($end - $start) < 800000) 2892 { 2893 $rrd->graph( 2894 image => "-", 2895 title => "$commentaire", 2896 vertical_label => "octets", 2897 lower_limit => 0, 2898 height => $height, 2899 width => $width, 2900 start => $start, 2901 end => $end, 2902 draw => { 2903 type => "hidden", 2904 dsname => "octets", 2905 name => 'octets', 2906 cfunc => 'AVERAGE', 2907 }, 2908 comment => ' min max moyen actuel\n', 2909 draw => { 2910 type => 'area', 2911 color => $couleur_current, 2912 cdef => "octets", 2913 legend => $commentaire, 2914 }, 2915 comment => ' ', 2916 gprint => { 2917 draw => 'octets', 2918 format => 'MIN:%7.2lf %S', 2919 }, 2920 gprint => { 2921 draw => 'octets', 2922 format => 'MAX:%7.2lf %S', 2923 }, 2924 gprint => { 2925 draw => 'octets', 2926 format => 'AVERAGE:%7.2lf %S', 2927 }, 2928 gprint => { 2929 draw => 'octets', 2930 format => 'LAST:%7.2lf %S\\n', 2931 }, 2932 ); 2933 } 2934 else 2935 { 2936 $rrd->graph( 2937 image => "-", 2938 title => "$commentaire", 2939 vertical_label => "jauge", 2940 lower_limit => 0, 2941 height => $height, 2942 width => $width, 2943 start => $start, 2944 end => $end, 2945 draw => { 2946 type => "hidden", 2947 dsname => "octets", 2948 name => 'octets', 2949 cfunc => 'AVERAGE', 2950 }, 2951 draw => { 2952 type => "hidden", 2953 dsname => "octets", 2954 name => 'maxoctets', 2955 cfunc => 'MAX', 2956 }, 2957 comment => ' min max moyen actuel\n', 2958 draw => { 2959 type => 'area', 2960 color => $couleur_max, 2961 cdef => "maxoctets", 2962 legend => "$commentaire (en crête)", 2963 }, 2964 comment => ' ', 2965 gprint => { 2966 draw => 'maxoctets', 2967 format => 'MIN:%7.2lf %S', 2968 }, 2969 gprint => { 2970 draw => 'maxoctets', 2971 format => 'MAX:%7.2lf %S', 2972 }, 2973 gprint => { 2974 draw => 'maxoctets', 2975 format => 'AVERAGE:%7.2lf %S', 2976 }, 2977 gprint => { 2978 draw => 'maxoctets', 2979 format => 'LAST:%7.2lf %S\\n', 2980 }, 2981 draw => { 2982 type => 'area', 2983 color => $couleur_current, 2984 cdef => "octets", 2985 legend => "$commentaire (en moyenne)", 2986 }, 2987 comment => ' ', 2988 gprint => { 2989 draw => 'octets', 2990 format => 'MIN:%7.2lf %S', 2991 }, 2992 gprint => { 2993 draw => 'octets', 2994 format => 'MAX:%7.2lf %S', 2995 }, 2996 gprint => { 2997 draw => 'octets', 2998 format => 'AVERAGE:%7.2lf %S', 2999 }, 3000 gprint => { 3001 draw => 'octets', 3002 format => 'LAST:%7.2lf %S\\n', 3003 }, 3004 ); 3005 } 3006} 3007 3008 3009########################################################### 3010# Graph generique pour les compteurs 3011sub counter_generic 3012{ 3013 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 3014 3015 my ($width,$height) = split(/x/,$size); 3016 3017 my @couleurs_flux = qw(00dd00 0000ff 0010ff ffbb00 32bc2d ff8800 ); 3018 my @couleurs_max_flux = qw(b8ff4d ffa1e9 ff0000 000000 fb96be 795634); 3019 3020 my $rrd = RRDTool::OO->new(file => "$ref_l->[0]->[0]->{'base'}"); 3021 3022 my @liste_arg1; 3023 3024 my $drawline; 3025 my $drawlinemax; 3026 # dereferencement 3027 my @l = @$ref_l; 3028 3029 # creation d'objets draw de type hidden pour chaque courbe de trafic 3030 my $tl = @l; 3031 for(my $i=0;$i<$tl;$i++) 3032 { 3033 my $ttl = @{$l[$i]}; 3034 my $plusline=""; 3035 for(my $j=0;$j<$ttl;$j++) 3036 { 3037 my $draw; 3038 my $drawmax; 3039 3040 $draw->{'file'} = $l[$i][$j]{'base'}; 3041 $drawmax->{'file'} = $l[$i][$j]{'base'}; 3042 3043 system("echo \"i=$i, j=$j, $l[$i][$j]{'base'}\" >> /tmp/genere_graph.out"); 3044 3045 $draw->{'type'} = "hidden"; 3046 $draw->{'dsname'} = "value"; 3047 $draw->{'name'} = "$l[$i][$j]{'graph'}__value"; 3048 $draw->{'cfunc'} = "AVERAGE"; 3049 $draw->{'name'} =~ s/\./__/g; 3050 $drawmax->{'type'} = "hidden"; 3051 $drawmax->{'dsname'} = "value"; 3052 $drawmax->{'name'} = "$l[$i][$j]{'graph'}__maxvalue"; 3053 $drawmax->{'cfunc'} = "MAX"; 3054 $drawmax->{'name'} =~ s/\./__/g; 3055 3056 # pour convertir les valeurs de trafic des lignes en bits 3057 $drawline->{$i}->{'cdef'}="$draw->{'name'}$plusline,8,*"; 3058 $drawlinemax->{$i}->{'cdef'}="$drawmax->{'name'}$plusline,8,*"; 3059 3060 push @liste_arg1,"draw"; 3061 push @liste_arg1,$draw; 3062 push @liste_arg1,"draw"; 3063 push @liste_arg1,$drawmax; 3064 } 3065 } 3066 for($i=0;$i<$tl;$i++) 3067 { 3068 if($l[$i][0]{'legend'} eq "") 3069 { 3070 $l[$i][0]{'legend'} = $l[$i][0]{'graph'}; 3071 } 3072 $llegend{$i} = length($l[$i][0]{'legend'}); 3073 if($maxlengthlegend < $llegend{$i}) 3074 { 3075 $maxlengthlegend = $llegend{$i}; 3076 } 3077 } 3078 $maxlengthlegend = $maxlengthlegend + 4; 3079 3080 # ecriture de la legende en entree 3081 my $spaces = get_spaces(0,$maxlengthlegend,10); 3082 push @liste_arg1,"comment"; 3083 push @liste_arg1,"$spaces maximum moyen actuel\\n"; 3084 my ($gprint,$gprintmax); 3085 3086 # on cree les objets draw pour afficher les lignes 3087 for($i=0;$i<$tl;$i++) 3088 { 3089 # ecriture de la courbe en input 3090 if($i == 0) 3091 { 3092 $drawline->{$i}->{'type'} = "area"; 3093 } 3094 else 3095 { 3096 $drawline->{$i}->{'type'} = "line"; 3097 } 3098 $drawline->{$i}->{'color'} = $couleurs_flux[$i]; 3099 $drawline->{$i}->{'name'} = "value$i"; 3100 # insertion de la legende 3101 $drawline->{$i}->{'legend'} = "$l[$i][0]{'legend'}"; 3102 push @liste_total,"draw"; 3103 push @liste_total,$drawline->{$i}; 3104 $gprint->{$i}->{0}->{'draw'}=$drawline->{$i}->{'name'}; 3105 $gprint->{$i}->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 3106 $spaces = get_spaces($llegend{$i},$maxlengthlegend,-3); 3107 push @liste_total,"comment"; 3108 push @liste_total,$spaces; 3109 push @liste_total,"gprint"; 3110 push @liste_total,$gprint->{$i}->{0}; 3111 $gprint->{$i}->{1}->{'draw'}=$drawline->{$i}->{'name'}; 3112 $gprint->{$i}->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 3113 push @liste_total,"gprint"; 3114 push @liste_total,$gprint->{$i}->{1}; 3115 $gprint->{$i}->{2}->{'draw'}=$drawline->{$i}->{'name'}; 3116 $gprint->{$i}->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 3117 push @liste_total,"gprint"; 3118 push @liste_total,$gprint->{$i}->{2}; 3119 3120 # ecriture des valeurs MAX selon l'intervalle de temps 3121 if(($end - $start) > 800000) 3122 { 3123# # ecriture de la courbe en input 3124 $drawlinemax->{$i}->{'type'} = "line"; 3125 $drawlinemax->{$i}->{'color'} = $couleurs_max_flux[$i]; 3126 $drawlinemax->{$i}->{'name'} = "valuemax$i"; 3127# # insertion de la legende 3128 $drawlinemax->{$i}->{'legend'} = "$l[$i][0]{'legend'}"; 3129 push @liste_total,"draw"; 3130 push @liste_total,$drawlinemax->{$i}; 3131 $gprintmax->{$i}->{0}->{'draw'}=$drawlinemax->{$i}->{'name'}; 3132 $gprintmax->{$i}->{0}->{'format'}="MAX:%7.2lf %Sb/s"; 3133 $spaces = get_spaces($llegend{$i},$maxlengthlegend,-3); 3134 push @liste_total,"comment"; 3135 push @liste_total,$spaces; 3136 push @liste_total,"gprint"; 3137 push @liste_total,$gprintmax->{$i}->{0}; 3138 $gprintmax->{$i}->{1}->{'draw'}=$drawlinemax->{$i}->{'name'}; 3139 $gprintmax->{$i}->{1}->{'format'}="AVERAGE:%7.2lf %Sb/s"; 3140 push @liste_total,"gprint"; 3141 push @liste_total,$gprintmax->{$i}->{1}; 3142 $gprintmax->{$i}->{2}->{'draw'}=$drawlinemax->{$i}->{'name'}; 3143 $gprintmax->{$i}->{2}->{'format'}="LAST:%7.2lf %Sb/s\\n"; 3144 push @liste_total,"gprint"; 3145 push @liste_total,$gprintmax->{$i}->{2}; 3146 } 3147 } 3148 3149 $rrd->graph( 3150 image => "-", 3151 title => "$commentaire", 3152 vertical_label => "trafic", 3153 height => $height, 3154 width => $width, 3155 start => $start, 3156 end => $end, 3157 @liste_arg1, 3158 @liste_total, 3159 ); 3160} 3161 3162 3163 3164########################################################### 3165# Graph de packets (in et out) 3166sub packets 3167{ 3168 my ($nb_rrd_bases,$ref_l,$output,$start,$end,$size,$commentaire) = @_; 3169 3170 # dereferencement 3171 my @l = @$ref_l; 3172 3173 my ($width,$height) = split(/x/,$size); 3174 3175 my %color_lines = ( 'input' => "00dd00", 3176 'output' => "0000ff", 3177 'maxinput' => "b8ff4d", 3178 'maxoutput' => "ffa1e9", 3179 ); 3180 3181 $vertical_label = "nombre de paquets"; 3182 3183 my $rrd = RRDTool::OO->new( 3184 file => "$ref_l->[0]->[0]->{'base'}", 3185 ); 3186 3187 my @liste_arg; 3188 my $plusline=""; 3189 my ($drawlinein,$drawlineout); 3190 3191 my $ttl = @{$l[0]}; 3192 3193 for(my $j=0;$j<$ttl;$j++) 3194 { 3195 my ($drawin,$drawout,$drawinmax,$drawoutmax); 3196 $drawin->{'file'} = $l[0][$j]{'base'}; 3197 $drawin->{'type'} = "hidden"; 3198 $drawin->{'dsname'} = "input"; 3199 $drawin->{'name'} = "$l[0][$j]{'graph'}__inputbytes"; 3200 $drawin->{'cfunc'} = "AVERAGE"; 3201 $drawout->{'file'} = $l[0][$j]{'base'}; 3202 $drawout->{'type'} = "hidden"; 3203 $drawout->{'dsname'} = "output"; 3204 $drawout->{'name'} = "$l[0][$j]{'graph'}__outputbytes"; 3205 $drawout->{'cfunc'} = "AVERAGE"; 3206 $drawin->{'name'} =~ s/\./__/g; 3207 $drawout->{'name'} =~ s/\./__/g; 3208 $drawinmax->{'file'} = $l[0][$j]{'base'}; 3209 $drawinmax->{'type'} = "hidden"; 3210 $drawinmax->{'dsname'} = "input"; 3211 $drawinmax->{'name'} = "$l[0][$j]{'graph'}__maxinputbytes"; 3212 $drawinmax->{'cfunc'} = "MAX"; 3213 $drawoutmax->{'file'} = $l[0][$j]{'base'}; 3214 $drawoutmax->{'type'} = "hidden"; 3215 $drawoutmax->{'dsname'} = "output"; 3216 $drawoutmax->{'name'} = "$l[0][$j]{'graph'}__maxoutputbytes"; 3217 $drawoutmax->{'cfunc'} = "MAX"; 3218 $drawinmax->{'name'} =~ s/\./__/g; 3219 $drawoutmax->{'name'} =~ s/\./__/g; 3220 3221 # calcul du cumul pour les donnes bases explicitement aggregees 3222 # ex : Mcrc-rc1.wifi-sec+Mle7-rc1.wifi-sec 3223 # (afficher sous forme de ligne) 3224 if(exists $drawlinein->{'cdef'}) 3225 { 3226 $drawlinein->{'cdef'}="$drawlinein->{'cdef'},$drawin->{'name'}"; 3227 $drawlineout->{'cdef'}="$drawlineout->{'cdef'},$drawout->{'name'}"; 3228 $drawlineinmax->{'cdef'}="$drawlineinmax->{'cdef'},$drawinmax->{'name'}"; 3229 $drawlineoutmax->{'cdef'}="$drawlineoutmax->{'cdef'},$drawoutmax->{'name'}"; 3230 $plusline = "$plusline,ADDNAN"; 3231 } 3232 else 3233 { 3234 $drawlinein->{'cdef'}=$drawin->{'name'}; 3235 $drawlineout->{'cdef'}=$drawout->{'name'}; 3236 $drawlineinmax->{'cdef'}=$drawinmax->{'name'}; 3237 $drawlineoutmax->{'cdef'}=$drawoutmax->{'name'}; 3238 } 3239 3240 push @liste_arg,"draw"; 3241 push @liste_arg,$drawin; 3242 push @liste_arg,"draw"; 3243 push @liste_arg,$drawout; 3244 push @liste_arg,"draw"; 3245 push @liste_arg,$drawinmax; 3246 push @liste_arg,"draw"; 3247 push @liste_arg,$drawoutmax; 3248 } 3249 # pour convertir les valeurs de trafic des lignes en bits 3250 $drawlinein->{'cdef'}="$drawlinein->{'cdef'}$plusline"; 3251 $drawlineout->{'cdef'}="$drawlineout->{'cdef'}$plusline"; 3252 $drawlineinmax->{'cdef'}="$drawlineinmax->{'cdef'}$plusline"; 3253 $drawlineoutmax->{'cdef'}="$drawlineoutmax->{'cdef'}$plusline"; 3254 3255 # comparaison des legendes pour la mise en page 3256 my %llegend; 3257 if($l[0][0]{'legend'} ne "") 3258 { 3259 $llegend{'in'} = length($l[0][0]{'legend'}); 3260 my $maxlengthlegend = $llegend{'in'}; 3261 $llegend{'out'} = length($l[0][0]{'legend'}); 3262 } 3263 else 3264 { 3265 $llegend{'in'} = 0; 3266 $llegend{'out'} = 0; 3267 } 3268 $maxlengthlegend = $maxlengthlegend + 2; 3269 3270 # ecriture de la legende en entree 3271 my $spaces = get_spaces(0,$maxlengthlegend,14); 3272 push @liste_arg,"comment"; 3273 push @liste_arg,"$spaces maximum moyen actuel\\n"; 3274 my ($gprintin,$gprintout,$gprintinmax,$gprintoutmax); 3275 $spaces = get_spaces($llegend{'in'},$maxlengthlegend,-12); 3276 # ecriture de la courbe en input 3277 $drawlinein->{'type'} = "area"; 3278 $drawlinein->{'color'} = $color_lines{'input'}; 3279 $drawlinein->{'name'} = "inputbits"; 3280 $drawlinein->{'legend'} = "$l[0][0]{'legend'} entrant"; 3281 push @liste_arg,"draw"; 3282 push @liste_arg,$drawlinein; 3283 # legende trafic in 3284 push @liste_arg,"comment"; 3285 push @liste_arg,$spaces; 3286 $gprintin->{0}->{'draw'}="inputbits"; 3287 $gprintin->{0}->{'format'}="MAX:%5.0lf %SPkts/s"; 3288 push @liste_arg,"gprint"; 3289 push @liste_arg,$gprintin->{0}; 3290 $gprintin->{1}->{'draw'}="inputbits"; 3291 $gprintin->{1}->{'format'}="AVERAGE:%5.0lf %SPkts/s"; 3292 push @liste_arg,"gprint"; 3293 push @liste_arg,$gprintin->{1}; 3294 $gprintin->{2}->{'draw'}="inputbits"; 3295 $gprintin->{2}->{'format'}="LAST:%5.0lf %SPkts/s\\n"; 3296 push @liste_arg,"gprint"; 3297 push @liste_arg,$gprintin->{2}; 3298 3299 # ecriture des valeurs MAX selon l'intervalle de temps 3300 if(($end - $start) > 800000) 3301 { 3302 # ecriture de la legende en entree 3303 $spaces = get_spaces($llegend{'in'},$maxlengthlegend,-12); 3304 # ecriture de la courbe en input 3305 $drawlineinmax->{'type'} = "line"; 3306 $drawlineinmax->{'color'} = $color_lines{'maxinput'}; 3307 $drawlineinmax->{'name'} = "maxinputbits"; 3308 $drawlineinmax->{'legend'} = "$l[0][0]{'legend'} entrant crête"; 3309 push @liste_arg,"draw"; 3310 push @liste_arg,$drawlineinmax; 3311 # legende trafic in 3312 push @liste_arg,"comment"; 3313 push @liste_arg,$spaces; 3314 $gprintinmax->{0}->{'draw'}="maxinputbits"; 3315 $gprintinmax->{0}->{'format'}="MAX:%5.0lf %SPkts/s"; 3316 push @liste_arg,"gprint"; 3317 push @liste_arg,$gprintinmax->{0}; 3318 $gprintinmax->{1}->{'draw'}="maxinputbits"; 3319 $gprintinmax->{1}->{'format'}="AVERAGE:%5.0lf %SPkts/s"; 3320 push @liste_arg,"gprint"; 3321 push @liste_arg,$gprintinmax->{1}; 3322 $gprintinmax->{2}->{'draw'}="maxinputbits"; 3323 $gprintinmax->{2}->{'format'}="LAST:%5.0lf %SPkts/s\\n"; 3324 push @liste_arg,"gprint"; 3325 push @liste_arg,$gprintinmax->{2}; 3326 3327 # ecriture de la legende en entree 3328 $spaces = get_spaces($llegend{'out'},$maxlengthlegend,-12); 3329 # ecriture de la courbe en input 3330 $drawlineoutmax->{'type'} = "line"; 3331 $drawlineoutmax->{'color'} = $color_lines{'maxoutput'}; 3332 $drawlineoutmax->{'name'} = "maxoutputbits"; 3333 $drawlineoutmax->{'legend'} = "$l[0][0]{'legend'} sortant crête"; 3334 push @liste_arg,"draw"; 3335 push @liste_arg,$drawlineoutmax; 3336 # legende trafic in 3337 push @liste_arg,"comment"; 3338 push @liste_arg,$spaces; 3339 $gprintoutmax->{0}->{'draw'}="maxoutputbits"; 3340 $gprintoutmax->{0}->{'format'}="MAX:%5.0lf %SPkts/s"; 3341 push @liste_arg,"gprint"; 3342 push @liste_arg,$gprintoutmax->{0}; 3343 $gprintoutmax->{1}->{'draw'}="maxoutputbits"; 3344 $gprintoutmax->{1}->{'format'}="AVERAGE:%5.0lf %SPkts/s"; 3345 push @liste_arg,"gprint"; 3346 push @liste_arg,$gprintoutmax->{1}; 3347 $gprintoutmax->{2}->{'draw'}="maxoutputbits"; 3348 $gprintoutmax->{2}->{'format'}="LAST:%5.0lf %SPkts/s\\n"; 3349 push @liste_arg,"gprint"; 3350 push @liste_arg,$gprintoutmax->{2}; 3351 } 3352 3353 # ecriture de la courbe en output 3354 $spaces = get_spaces($llegend{'out'},$maxlengthlegend,-12); 3355 $drawlineout->{'type'} = "line"; 3356 $drawlineout->{'color'} = $color_lines{'output'}; 3357 $drawlineout->{'name'} = "outputbits"; 3358 $drawlineout->{'legend'} = "$l[0][0]{'legend'} sortant"; 3359 push @liste_arg,"draw"; 3360 push @liste_arg,$drawlineout; 3361 # legende trafic out 3362 push @liste_arg,"comment"; 3363 push @liste_arg,$spaces; 3364 $gprintout->{0}->{'draw'}="outputbits"; 3365 $gprintout->{0}->{'format'}="MAX:%5.0lf %SPkts/s"; 3366 push @liste_arg,"gprint"; 3367 push @liste_arg,$gprintout->{0}; 3368 $gprintout->{1}->{'draw'}="outputbits"; 3369 $gprintout->{1}->{'format'}="AVERAGE:%5.0lf %SPkts/s"; 3370 push @liste_arg,"gprint"; 3371 push @liste_arg,$gprintout->{1}; 3372 $gprintout->{2}->{'draw'}="outputbits"; 3373 $gprintout->{2}->{'format'}="LAST:%5.0lf %SPkts/s\\n"; 3374 push @liste_arg,"gprint"; 3375 push @liste_arg,$gprintout->{2}; 3376 3377 $rrd->graph( 3378 image => "-", 3379 title => "$commentaire", 3380 vertical_label => "trafic (Paquets/s)", 3381 height => $height, 3382 width => $width, 3383 start => $start, 3384 end => $end, 3385 @liste_arg, 3386 ); 3387} 3388 3389return 1; 3390