sub updatecpugraph {
         $period    = $_[0];
         $period1   = $_[0];
           if( $period eq 'year' )
         {
                 $period1 = 'year_rrd';
         }
           RRDs::graph ("$graphs/cpu-$period.png",
                 "--start", "-1$period", "-aPNG", "-z",
                 "--alt-y-grid", "-w 531", "-h 100", "-l 0", "-u 100", "-r",
                 "--color", "SHADEA#$borderColor",  #EAE9EE
                 "--color", "SHADEB#$borderColor",
                 "--color", "BACK#$backgroundColor",
                 "-t Utilisation CPU par $tr{$period1}",
                 "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
                 "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
                 "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
                 "CDEF:total=user,system,idle,+,+",
                 "CDEF:userpct=100,user,total,/,*",
                 "CDEF:systempct=100,system,total,/,*",
                 "CDEF:idlepct=100,idle,total,/,*",
                 "AREA:userpct#0000FF:CPU utilisateur",
                 "GPRINT:userpct:MAX:Maximum\\:%3.2lf%%",
                 "GPRINT:userpct:AVERAGE:Moyenne\\:%3.2lf%%",
                 "GPRINT:userpct:LAST:Actuel\\:%3.2lf%%\\j",
                 "STACK:systempct#FF0000:CPU système    ",
                 "GPRINT:systempct:MAX:Maximum\\:%3.2lf%%",
                 "GPRINT:systempct:AVERAGE:Moyenne\\:%3.2lf%%",
                 "GPRINT:systempct:LAST:Actuel\\:%3.2lf%%\\j",
                 "STACK:idlepct#00FF00:CPU inactif    ",
                 "GPRINT:idlepct:MAX:Maximum\\:%3.2lf%%",
                 "GPRINT:idlepct:AVERAGE:Moyenne\\:%3.2lf%%",
                 "GPRINT:idlepct:LAST:Actuel\\:%3.2lf%%\\j" );
         $ERROR = RRDs::error;
         print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
 }
   sub updatecpudata {
         if ( ! -e "$rrdlog/cpu.rrd" ) {
                 RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
                         "DS:user:COUNTER:300:0:500000000",
                         "DS:system:COUNTER:300:0:500000000",
                         "DS:idle:COUNTER:300:0:500000000",
                         "RRA:AVERAGE:0.5:1:576",
                         "RRA:AVERAGE:0.5:6:672",
                         "RRA:AVERAGE:0.5:24:732",
                         "RRA:AVERAGE:0.5:144:1460" );
                 $ERROR = RRDs::error;
                 print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
         }
           my ($cpu, $user, $nice, $system, $idle);
           open STAT, "/proc/stat";
         while(<STAT> ) {
                 chomp;
                 /^cpu\s/ or next;
                 ($cpu, $user, $nice, $system, $idle) = split /\s+/;
                 last;
         }
         close STAT;
         $user += $nice;
           RRDs::update ("$rrdlog/cpu.rrd",
                 "-t", "user:system:idle",
                 "N:$user:$system:$idle" );
         $ERROR = RRDs::error;
         print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
   }
  
   |