Et bien, j'ai fait ça il y a pas longtemps en PERL :
Le script PERL qui réalise la collecte des données avec SAR, un fichier texte est généré contenant les valeurs, tu passes ensuite une moulinette GNUPLOT, et tu obtiens un joli graphique.
if ( $Tab_Mot[1] eq "0" )
{
open (CPUSTAT, ">> $Fichier_de_StatsCPU0");
print (CPUSTAT "$Line\n");
close (CPUSTAT);
}
if ( $Tab_Mot[1] eq "1" )
{
open (CPUSTAT, ">> $Fichier_de_StatsCPU1");
print (CPUSTAT "$Line\n");
close (CPUSTAT);
}
}
sleep($Attente);
}
close(CPU);
Le script GNUPLOT:
set terminal postscript
set title "Charge CPU 1 CCDSI02 "
set autoscale
set data style lines
set xlabel "Heures"
set ylabel "Charge : %"
set output "/home/expl/audit/graph/cpu0.gs"
set xdata time
set timefmt "%d/%m/%y %H:%M:%S"
set format x "%H:%M"
set grid
#set key left
plot '/home/expl/audit/stats/Stat.CPU0' using 1:3 t '%Charge CPU' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:4 t '%Gestion Systeme' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:5 t '%Charge utilisateur' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:6 t '%Attente E/S' with lines
set terminal postscript
set title "Charge CPU 2 CCDSI02"
set autoscale
set data style lines
set xlabel "Heures"
set ylabel "Charge : %"
set output "/home/expl/audit/graph/cpu1.gs"
set xdata time
set timefmt "%d/%m/%y %H:%M:%S"
set format x "%H:%M"
set grid
#set key left
plot '/home/expl/audit/stats/Stat.CPU1' using 1:3 t '%Charge CPU' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:4 t '%Gestion Systeme' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:5 t '%Charge utilisateur' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:6 t '%Attente E/S' with lines
Cela va te générer donc deux graphiques, soit un par CPU, j'aurais pu faire aussi une moyenne, tout est possible :-)
# GNUPLOT ?
Posté par Dabowl_94 . En réponse au message Faire des graphiques à parti de Sar. Évalué à 3.
Le script PERL qui réalise la collecte des données avec SAR, un fichier texte est généré contenant les valeurs, tu passes ensuite une moulinette GNUPLOT, et tu obtiens un joli graphique.
Le script PERL:
#!/usr/bin/perl
$Fichier_de_StatsCPU0 = "/var/log/Stat.CPU0";
$Fichier_de_StatsCPU1 = "/var/log/Stat.CPU1";
$Commande = "/usr/bin/sar -P '0,1' -u'' $ARGV[0] $ARGV[1]";
$Attente = 2;
open(CPU,"$Commande |");
while($Line_CPU = )
{
chop $Line_CPU;
@Tab_Mot = split(/\s+/,$Line_CPU);
if (($Tab_Mot[0] ne "AIX") && ($Tab_Mot[0] ne "Moyenne") && ($Tab_Mot[1] ne "cpu") && ($Tab_Mot[1] ne ""))
{
$_ = `/usr/bin/date +"%d %m %y %H %M %S"`;
$IN = $_ ;
@Tab_Date = split(/\s+/,$IN);
$Line = "$Tab_Date[0]/$Tab_Date[1]/$Tab_Date[2] $Tab_Date[3]:$Tab_Date[4]:$Tab_Date[5] ";
$CPU_Occupe = 100 - $Tab_Mot[5];
$Line = $Line . "$CPU_Occupe $Tab_Mot[2] $Tab_Mot[3] $Tab_Mot[4] $Tab_Mot[1]";
if ( $Tab_Mot[1] eq "0" )
{
open (CPUSTAT, ">> $Fichier_de_StatsCPU0");
print (CPUSTAT "$Line\n");
close (CPUSTAT);
}
if ( $Tab_Mot[1] eq "1" )
{
open (CPUSTAT, ">> $Fichier_de_StatsCPU1");
print (CPUSTAT "$Line\n");
close (CPUSTAT);
}
}
sleep($Attente);
}
close(CPU);
Le script GNUPLOT:
set terminal postscript
set title "Charge CPU 1 CCDSI02 "
set autoscale
set data style lines
set xlabel "Heures"
set ylabel "Charge : %"
set output "/home/expl/audit/graph/cpu0.gs"
set xdata time
set timefmt "%d/%m/%y %H:%M:%S"
set format x "%H:%M"
set grid
#set key left
plot '/home/expl/audit/stats/Stat.CPU0' using 1:3 t '%Charge CPU' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:4 t '%Gestion Systeme' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:5 t '%Charge utilisateur' with lines,\
'/home/expl/audit/stats/Stat.CPU0' using 1:6 t '%Attente E/S' with lines
set terminal postscript
set title "Charge CPU 2 CCDSI02"
set autoscale
set data style lines
set xlabel "Heures"
set ylabel "Charge : %"
set output "/home/expl/audit/graph/cpu1.gs"
set xdata time
set timefmt "%d/%m/%y %H:%M:%S"
set format x "%H:%M"
set grid
#set key left
plot '/home/expl/audit/stats/Stat.CPU1' using 1:3 t '%Charge CPU' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:4 t '%Gestion Systeme' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:5 t '%Charge utilisateur' with lines,\
'/home/expl/audit/stats/Stat.CPU1' using 1:6 t '%Attente E/S' with lines
Cela va te générer donc deux graphiques, soit un par CPU, j'aurais pu faire aussi une moyenne, tout est possible :-)
Je pense que ça devrait pas mal t'aider ;-)
dabowl_75