- my $period = $_[0];
- my @command = ("$graphs/cpu-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z", "-W www.ipfire.org", "-v $Lang::tr{'percentage'}",
- "--alt-y-grid", "-w 600", "-h 125", "-l 0", "-u 100", "-r",
- "--color", "SHADEA".$color{"color19"},
- "--color", "SHADEB".$color{"color19"},
- "--color", "BACK".$color{"color21"},
- "-t $Lang::tr{'cpu usage per'} $Lang::tr{$period}");
-
- if ( -e "$rrdlog/collectd/localhost/cpu-1/" ){
- push(@command,"DEF:iowait0=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE",
- "DEF:nice0=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE",
- "DEF:interrupt0=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE",
- "DEF:steal0=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE",
- "DEF:user0=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE",
- "DEF:system0=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE",
- "DEF:idle0=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE",
- "DEF:irq0=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE");
- push(@command,"DEF:iowait1=$rrdlog/collectd/localhost/cpu-1/cpu-wait.rrd:value:AVERAGE",
- "DEF:nice1=$rrdlog/collectd/localhost/cpu-1/cpu-nice.rrd:value:AVERAGE",
- "DEF:interrupt1=$rrdlog/collectd/localhost/cpu-1/cpu-interrupt.rrd:value:AVERAGE",
- "DEF:steal1=$rrdlog/collectd/localhost/cpu-1/cpu-steal.rrd:value:AVERAGE",
- "DEF:user1=$rrdlog/collectd/localhost/cpu-1/cpu-user.rrd:value:AVERAGE",
- "DEF:system1=$rrdlog/collectd/localhost/cpu-1/cpu-system.rrd:value:AVERAGE",
- "DEF:idle1=$rrdlog/collectd/localhost/cpu-1/cpu-idle.rrd:value:AVERAGE",
- "DEF:irq1=$rrdlog/collectd/localhost/cpu-1/cpu-softirq.rrd:value:AVERAGE");
- push(@command,"CDEF:user=user0,user1,+",
- "CDEF:nice=nice0,nice1,+",
- "CDEF:interrupt=interrupt0,interrupt1,+",
- "CDEF:steal=steal0,steal1,+",
- "CDEF:system=system0,system1,+",
- "CDEF:idle=idle0,idle1,+",
- "CDEF:iowait=iowait0,iowait1,+",
- "CDEF:irq=irq0,irq1,+");
- }
- else {
- push(@command,"DEF:iowait=$rrdlog/collectd/localhost/cpu-0/cpu-wait.rrd:value:AVERAGE",
- "DEF:nice=$rrdlog/collectd/localhost/cpu-0/cpu-nice.rrd:value:AVERAGE",
- "DEF:interrupt=$rrdlog/collectd/localhost/cpu-0/cpu-interrupt.rrd:value:AVERAGE",
- "DEF:steal=$rrdlog/collectd/localhost/cpu-0/cpu-steal.rrd:value:AVERAGE",
- "DEF:user=$rrdlog/collectd/localhost/cpu-0/cpu-user.rrd:value:AVERAGE",
- "DEF:system=$rrdlog/collectd/localhost/cpu-0/cpu-system.rrd:value:AVERAGE",
- "DEF:idle=$rrdlog/collectd/localhost/cpu-0/cpu-idle.rrd:value:AVERAGE",
- "DEF:irq=$rrdlog/collectd/localhost/cpu-0/cpu-softirq.rrd:value:AVERAGE");
- }
- push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+",
- "CDEF:userpct=100,user,total,/,*",
- "CDEF:nicepct=100,nice,total,/,*",
- "CDEF:interruptpct=100,interrupt,total,/,*",
- "CDEF:stealpct=100,steal,total,/,*",
- "CDEF:systempct=100,system,total,/,*",
- "CDEF:idlepct=100,idle,total,/,*",
- "CDEF:iowaitpct=100,iowait,total,/,*",
- "CDEF:irqpct=100,irq,total,/,*",
- "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
- "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
- "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
- "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
- "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j",
- "AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'}),
- "GPRINT:iowaitpct:MAX:%3.2lf%%",
- "GPRINT:iowaitpct:AVERAGE:%3.2lf%%",
- "GPRINT:iowaitpct:MIN:%3.2lf%%",
- "GPRINT:iowaitpct:LAST:%3.2lf%%\\j",
- "STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'}),
- "GPRINT:irqpct:MAX:%3.2lf%%",
- "GPRINT:irqpct:AVERAGE:%3.2lf%%",
- "GPRINT:irqpct:MIN:%3.2lf%%",
- "GPRINT:irqpct:LAST:%3.2lf%%\\j",
- "STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'}),
- "GPRINT:nicepct:MAX:%3.2lf%%",
- "GPRINT:nicepct:AVERAGE:%3.2lf%%",
- "GPRINT:nicepct:MIN:%3.2lf%%",
- "GPRINT:nicepct:LAST:%3.2lf%%\\j",
- "STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'}),
- "GPRINT:interruptpct:MAX:%3.2lf%%",
- "GPRINT:interruptpct:AVERAGE:%3.2lf%%",
- "GPRINT:interruptpct:MIN:%3.2lf%%",
- "GPRINT:interruptpct:LAST:%3.2lf%%\\j",
- "STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'}),
- "GPRINT:stealpct:MAX:%3.2lf%%",
- "GPRINT:stealpct:AVERAGE:%3.2lf%%",
- "GPRINT:stealpct:MIN:%3.2lf%%",
- "GPRINT:stealpct:LAST:%3.2lf%%\\j",
- "STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'}),
- "GPRINT:userpct:MAX:%3.2lf%%",
- "GPRINT:userpct:AVERAGE:%3.2lf%%",
- "GPRINT:userpct:MIN:%3.2lf%%",
- "GPRINT:userpct:LAST:%3.2lf%%\\j",
- "STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'}),
- "GPRINT:systempct:MAX:%3.2lf%%",
- "GPRINT:systempct:AVERAGE:%3.2lf%%",
- "GPRINT:systempct:MIN:%3.2lf%%",
- "GPRINT:systempct:LAST:%3.2lf%%\\j",
- "STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'}),
- "GPRINT:idlepct:MAX:%3.2lf%%",
- "GPRINT:idlepct:AVERAGE:%3.2lf%%",
- "GPRINT:idlepct:MIN:%3.2lf%%",
- "GPRINT:idlepct:LAST:%3.2lf%%\\j");
-
- RRDs::graph (@command);
- $ERROR = RRDs::error;
- print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
+ my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`;
+ my $period = $_[0];
+ my @command = (
+ "-",
+ "--start",
+ "-1".$period,
+ "-aPNG",
+ "-i",
+ "-z",
+ "-W www.ipfire.org",
+ "--alt-y-grid",
+ "-w 600",
+ "-h 125",
+ "-l 0",
+ "-u 100",
+ "-r",
+ "-t ".$Lang::tr{'cpu usage per'}." ".$Lang::tr{$period."-graph"},
+ "-v ".$Lang::tr{'percentage'},
+ "--color=SHADEA".$color{"color19"},
+ "--color=SHADEB".$color{"color19"},
+ "--color=BACK".$color{"color21"},
+ "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
+ );
+
+ my $nice = "CDEF:nice=";
+ my $interrupt = "CDEF:interrupt=";
+ my $steal = "CDEF:steal=";
+ my $user = "CDEF:user=";
+ my $system = "CDEF:system=";
+ my $idle = "CDEF:idle=";
+ my $iowait = "CDEF:iowait=";
+ my $irq = "CDEF:irq=";
+ my $addstring = "";
+
+ for(my $i = 0; $i < $cpucount; $i++) {
+ push(@command,"DEF:iowait".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-wait.rrd:value:AVERAGE"
+ ,"DEF:nice".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-nice.rrd:value:AVERAGE"
+ ,"DEF:interrupt".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-interrupt.rrd:value:AVERAGE"
+ ,"DEF:steal".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-steal.rrd:value:AVERAGE"
+ ,"DEF:user".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-user.rrd:value:AVERAGE"
+ ,"DEF:system".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-system.rrd:value:AVERAGE"
+ ,"DEF:idle".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-idle.rrd:value:AVERAGE"
+ ,"DEF:irq".$i."=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpu-".$i."/cpu-softirq.rrd:value:AVERAGE");
+
+ $nice .= "nice".$i.",";
+ $interrupt .= "interrupt".$i.",";
+ $steal .= "steal".$i.",";
+ $user .= "user".$i.",";
+ $system .= "system".$i.",";
+ $idle .= "idle".$i.",";
+ $iowait .= "iowait".$i.",";
+ $irq .= "irq".$i.",";
+ }
+
+ for(my $i = 2; $i < $cpucount; $i++) {
+ $addstring .= "+,";
+ }
+
+ if ( $cpucount > 1){
+ $addstring .= "+";
+ push(@command,$nice.$addstring
+ ,$interrupt.$addstring
+ ,$steal.$addstring
+ ,$user.$addstring
+ ,$system.$addstring
+ ,$idle.$addstring
+ ,$iowait.$addstring
+ ,$irq.$addstring);
+ }else{
+ chop($nice),chop($interrupt),chop($steal),chop($user),chop($system),chop($idle),chop($iowait),chop($irq);
+ push(@command,$nice,$interrupt,$steal,$user,$system,$idle,$iowait,$irq);
+ }
+
+ push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+"
+ ,"CDEF:userpct=100,user,total,/,*"
+ ,"CDEF:nicepct=100,nice,total,/,*"
+ ,"CDEF:interruptpct=100,interrupt,total,/,*"
+ ,"CDEF:stealpct=100,steal,total,/,*"
+ ,"CDEF:systempct=100,system,total,/,*"
+ ,"CDEF:idlepct=100,idle,total,/,*"
+ ,"CDEF:iowaitpct=100,iowait,total,/,*"
+ ,"CDEF:irqpct=100,irq,total,/,*"
+ ,"AREA:iowaitpct".$color{"color14"}.":".sprintf("%-25s",$Lang::tr{'cpu iowait usage'})
+ ,"GPRINT:iowaitpct:MAX:%3.2lf%%"
+ ,"GPRINT:iowaitpct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:iowaitpct:MIN:%3.2lf%%"
+ ,"GPRINT:iowaitpct:LAST:%3.2lf%%\\j"
+ ,"STACK:irqpct".$color{"color23"}."A0:".sprintf("%-25s",$Lang::tr{'cpu irq usage'})
+ ,"GPRINT:irqpct:MAX:%3.2lf%%"
+ ,"GPRINT:irqpct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:irqpct:MIN:%3.2lf%%"
+ ,"GPRINT:irqpct:LAST:%3.2lf%%\\j"
+ ,"STACK:nicepct".$color{"color16"}."A0:".sprintf("%-25s",$Lang::tr{'cpu nice usage'})
+ ,"GPRINT:nicepct:MAX:%3.2lf%%"
+ ,"GPRINT:nicepct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:nicepct:MIN:%3.2lf%%"
+ ,"GPRINT:nicepct:LAST:%3.2lf%%\\j"
+ ,"STACK:interruptpct".$color{"color15"}."A0:".sprintf("%-25s",$Lang::tr{'cpu interrupt usage'})
+ ,"GPRINT:interruptpct:MAX:%3.2lf%%"
+ ,"GPRINT:interruptpct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:interruptpct:MIN:%3.2lf%%"
+ ,"GPRINT:interruptpct:LAST:%3.2lf%%\\j"
+ ,"STACK:stealpct".$color{"color18"}."A0:".sprintf("%-25s",$Lang::tr{'cpu steal usage'})
+ ,"GPRINT:stealpct:MAX:%3.2lf%%"
+ ,"GPRINT:stealpct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:stealpct:MIN:%3.2lf%%"
+ ,"GPRINT:stealpct:LAST:%3.2lf%%\\j"
+ ,"STACK:userpct".$color{"color11"}."A0:".sprintf("%-25s",$Lang::tr{'cpu user usage'})
+ ,"GPRINT:userpct:MAX:%3.2lf%%"
+ ,"GPRINT:userpct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:userpct:MIN:%3.2lf%%"
+ ,"GPRINT:userpct:LAST:%3.2lf%%\\j"
+ ,"STACK:systempct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cpu system usage'})
+ ,"GPRINT:systempct:MAX:%3.2lf%%"
+ ,"GPRINT:systempct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:systempct:MIN:%3.2lf%%"
+ ,"GPRINT:systempct:LAST:%3.2lf%%\\j"
+ ,"STACK:idlepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'cpu idle usage'})
+ ,"GPRINT:idlepct:MAX:%3.2lf%%"
+ ,"GPRINT:idlepct:AVERAGE:%3.2lf%%"
+ ,"GPRINT:idlepct:MIN:%3.2lf%%"
+ ,"GPRINT:idlepct:LAST:%3.2lf%%\\j");
+
+ RRDs::graph (@command);
+ $ERROR = RRDs::error;
+ print "Error in RRD::graph for cpu: ".$ERROR."\n" if $ERROR;