3.0: 'system' graph finished

This commit is contained in:
Jordi Sanfeliu 2012-11-15 17:19:19 +01:00
parent 31e1e86a98
commit 5b612e6a1c
1 changed files with 53 additions and 43 deletions

View File

@ -1,6 +1,6 @@
package system; package system;
#use strict; use strict;
use warnings; use warnings;
use Monitorix; use Monitorix;
use RRDs; use RRDs;
@ -69,6 +69,7 @@ sub system_init {
} }
} }
# check dependencies
if(lc($config->{enable_alerts}) eq "y") { if(lc($config->{enable_alerts}) eq "y") {
if(! -x $config->{alert_loadavg_script}) { if(! -x $config->{alert_loadavg_script}) {
logger("$myself: ERROR: script '$config->{alert_loadavg_script}' doesn't exist or don't has execution permissions."); logger("$myself: ERROR: script '$config->{alert_loadavg_script}' doesn't exist or don't has execution permissions.");
@ -283,8 +284,9 @@ sub system_update {
} }
sub system_cgi { sub system_cgi {
my ($package, $config, $colors, $tf, $graph, $silent, $u) = @_; my ($package, $config, $colors, $tf, $graph, $silent) = @_;
my $u = "";
my $width; my $width;
my $height; my $height;
my @riglim; my @riglim;
@ -299,6 +301,14 @@ sub system_cgi {
my $total_mem; my $total_mem;
if($silent eq "yes" || $silent eq "imagetag") {
$colors->{fg_color} = "#000000"; # visible color for text mode
$u = "_";
}
if($silent eq "imagetagbig") {
$colors->{fg_color} = "#000000"; # visible color for text mode
$u = "";
}
my $PNG1 = $u . $package . "1." . $tf->{when} . ".png"; my $PNG1 = $u . $package . "1." . $tf->{when} . ".png";
my $PNG2 = $u . $package . "2." . $tf->{when} . ".png"; my $PNG2 = $u . $package . "2." . $tf->{when} . ".png";
my $PNG3 = $u . $package . "3." . $tf->{when} . ".png"; my $PNG3 = $u . $package . "3." . $tf->{when} . ".png";
@ -476,11 +486,11 @@ sub system_cgi {
} }
undef(@riglim); undef(@riglim);
if($SYSTEM2_RIGID eq 1) { if($config->{system2_rigid} eq 1) {
push(@riglim, "--upper-limit=$SYSTEM2_LIMIT"); push(@riglim, "--upper-limit=$config->{system2_limit}");
} else { } else {
if($SYSTEM2_RIGID eq 2) { if($config->{system2_rigid} eq 2) {
push(@riglim, "--upper-limit=$SYSTEM2_LIMIT"); push(@riglim, "--upper-limit=$config->{system2_limit}");
push(@riglim, "--rigid"); push(@riglim, "--rigid");
} }
} }
@ -491,25 +501,25 @@ sub system_cgi {
push(@tmp, "LINE1:nprun#EE0000"); push(@tmp, "LINE1:nprun#EE0000");
push(@tmp, "LINE1:npslp#00EEEE"); push(@tmp, "LINE1:npslp#00EEEE");
push(@tmp, "LINE1:nproc#EEEE00:Processes"); push(@tmp, "LINE1:nproc#EEEE00:Processes");
($width, $height) = split('x', $GRAPH_SIZE{small}); ($width, $height) = split('x', $config->{graph_size}->{small});
if($silent =~ /imagetag/) { if($silent =~ /imagetag/) {
($width, $height) = split('x', $GRAPH_SIZE{remote}) if $silent eq "imagetag"; ($width, $height) = split('x', $config->{graph_size}->{remote}) if $silent eq "imagetag";
($width, $height) = split('x', $GRAPH_SIZE{main}) if $silent eq "imagetagbig"; ($width, $height) = split('x', $config->{graph_size}->{main}) if $silent eq "imagetagbig";
push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n");
push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n");
} }
RRDs::graph("$PNG_DIR" . "$PNG2", RRDs::graph("$PNG_DIR" . "$PNG2",
"--title=$rgraphs{_system2} ($nwhen$twhen)", "--title=$config->{graphs}->{_system2} ($tf->{nwhen}$tf->{twhen})",
"--start=-$nwhen$twhen", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
"--vertical-label=Processes", "--vertical-label=Processes",
"--width=$width", "--width=$width",
"--height=$height", "--height=$height",
@riglim, @riglim,
"--lower-limit=0", "--lower-limit=0",
@VERSION12, @{$config->{version12}},
@VERSION12_small, @{$config->{version12_small}},
@graph_colors, @{$colors->{graph_colors}},
"DEF:nproc=$rrd:system_nproc:AVERAGE", "DEF:nproc=$rrd:system_nproc:AVERAGE",
"DEF:npslp=$rrd:system_npslp:AVERAGE", "DEF:npslp=$rrd:system_npslp:AVERAGE",
"DEF:nprun=$rrd:system_nprun:AVERAGE", "DEF:nprun=$rrd:system_nprun:AVERAGE",
@ -518,19 +528,19 @@ sub system_cgi {
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNG2: $err\n") if $err; print("ERROR: while graphing $PNG_DIR" . "$PNG2: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $GRAPH_SIZE{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
RRDs::graph("$PNG_DIR" . "$PNG2z", RRDs::graph("$PNG_DIR" . "$PNG2z",
"--title=$rgraphs{_system2} ($nwhen$twhen)", "--title=$config->{graphs}->{_system2} ($tf->{nwhen}$tf->{twhen})",
"--start=-$nwhen$twhen", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
"--vertical-label=Processes", "--vertical-label=Processes",
"--width=$width", "--width=$width",
"--height=$height", "--height=$height",
@riglim, @riglim,
"--lower-limit=0", "--lower-limit=0",
@VERSION12, @{$config->{version12}},
@VERSION12_small, @{$config->{version12_small}},
@graph_colors, @{$colors->{graph_colors}},
"DEF:nproc=$rrd:system_nproc:AVERAGE", "DEF:nproc=$rrd:system_nproc:AVERAGE",
"DEF:npslp=$rrd:system_npslp:AVERAGE", "DEF:npslp=$rrd:system_npslp:AVERAGE",
"DEF:nprun=$rrd:system_nprun:AVERAGE", "DEF:nprun=$rrd:system_nprun:AVERAGE",
@ -540,14 +550,14 @@ sub system_cgi {
} }
if($title || ($silent =~ /imagetag/ && $graph =~ /system2/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /system2/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if($DISABLE_JAVASCRIPT_VOID eq "Y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $URL . $IMGS_DIR . $PNG2z . "\"><img src='" . $URL . $IMGS_DIR . $PNG2 . "' border='0'></a>\n"); print(" <a href=\"" . $config->{url} . $config->{imgs_dir} . $PNG2z . "\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG2 . "' border='0'></a>\n");
} }
else { else {
print(" <a href=\"javascript:void(window.open('" . $URL . $IMGS_DIR . $PNG2z . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $URL . $IMGS_DIR . $PNG2 . "' border='0'></a>\n"); print(" <a href=\"javascript:void(window.open('" . $config->{url} . $config->{imgs_dir} . $PNG2z . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG2 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $URL . $IMGS_DIR . $PNG2 . "'>\n"); print(" <img src='" . $config->{url} . $config->{imgs_dir} . $PNG2 . "'>\n");
} }
} }
@ -577,16 +587,16 @@ sub system_cgi {
push(@tmp, "LINE1:m_macti#00EE00"); push(@tmp, "LINE1:m_macti#00EE00");
push(@tmp, "LINE1:m_mused#EE0000"); push(@tmp, "LINE1:m_mused#EE0000");
} }
($width, $height) = split('x', $GRAPH_SIZE{small}); ($width, $height) = split('x', $config->{graph_size}->{small});
if($silent =~ /imagetag/) { if($silent =~ /imagetag/) {
($width, $height) = split('x', $GRAPH_SIZE{remote}) if $silent eq "imagetag"; ($width, $height) = split('x', $config->{graph_size}->{remote}) if $silent eq "imagetag";
($width, $height) = split('x', $GRAPH_SIZE{main}) if $silent eq "imagetagbig"; ($width, $height) = split('x', $config->{graph_size}->{main}) if $silent eq "imagetagbig";
push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n");
push(@tmp, "COMMENT: \\n"); push(@tmp, "COMMENT: \\n");
} }
RRDs::graph("$PNG_DIR" . "$PNG3", RRDs::graph("$PNG_DIR" . "$PNG3",
"--title=$rgraphs{_system3} (${total_mem}MB) ($nwhen$twhen)", "--title=$config->{graphs}->{_system3} (${total_mem}MB) ($tf->{nwhen}$tf->{twhen})",
"--start=-$nwhen$twhen", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
"--vertical-label=Megabytes", "--vertical-label=Megabytes",
"--width=$width", "--width=$width",
@ -594,9 +604,9 @@ sub system_cgi {
"--upper-limit=$total_mem", "--upper-limit=$total_mem",
"--lower-limit=0", "--lower-limit=0",
"--base=1024", "--base=1024",
@VERSION12, @{$config->{version12}},
@VERSION12_small, @{$config->{version12_small}},
@graph_colors, @{$colors->{graph_colors}},
"DEF:mtotl=$rrd:system_mtotl:AVERAGE", "DEF:mtotl=$rrd:system_mtotl:AVERAGE",
"DEF:mbuff=$rrd:system_mbuff:AVERAGE", "DEF:mbuff=$rrd:system_mbuff:AVERAGE",
"DEF:mcach=$rrd:system_mcach:AVERAGE", "DEF:mcach=$rrd:system_mcach:AVERAGE",
@ -614,10 +624,10 @@ sub system_cgi {
$err = RRDs::error; $err = RRDs::error;
print("ERROR: while graphing $PNG_DIR" . "$PNG3: $err\n") if $err; print("ERROR: while graphing $PNG_DIR" . "$PNG3: $err\n") if $err;
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
($width, $height) = split('x', $GRAPH_SIZE{zoom}); ($width, $height) = split('x', $config->{graph_size}->{zoom});
RRDs::graph("$PNG_DIR" . "$PNG3z", RRDs::graph("$PNG_DIR" . "$PNG3z",
"--title=$rgraphs{_system3} (${total_mem}MB) ($nwhen$twhen)", "--title=$config->{graphs}->{_system3} (${total_mem}MB) ($tf->{nwhen}$tf->{twhen})",
"--start=-$nwhen$twhen", "--start=-$tf->{nwhen}$tf->{twhen}",
"--imgformat=PNG", "--imgformat=PNG",
"--vertical-label=Megabytes", "--vertical-label=Megabytes",
"--width=$width", "--width=$width",
@ -625,9 +635,9 @@ sub system_cgi {
"--upper-limit=$total_mem", "--upper-limit=$total_mem",
"--lower-limit=0", "--lower-limit=0",
"--base=1024", "--base=1024",
@VERSION12, @{$config->{version12}},
@VERSION12_small, @{$config->{version12_small}},
@graph_colors, @{$colors->{graph_colors}},
"DEF:mtotl=$rrd:system_mtotl:AVERAGE", "DEF:mtotl=$rrd:system_mtotl:AVERAGE",
"DEF:mbuff=$rrd:system_mbuff:AVERAGE", "DEF:mbuff=$rrd:system_mbuff:AVERAGE",
"DEF:mcach=$rrd:system_mcach:AVERAGE", "DEF:mcach=$rrd:system_mcach:AVERAGE",
@ -646,14 +656,14 @@ sub system_cgi {
} }
if($title || ($silent =~ /imagetag/ && $graph =~ /system3/)) { if($title || ($silent =~ /imagetag/ && $graph =~ /system3/)) {
if(lc($config->{enable_zoom}) eq "y") { if(lc($config->{enable_zoom}) eq "y") {
if($DISABLE_JAVASCRIPT_VOID eq "Y") { if(lc($config->{disable_javascript_void}) eq "y") {
print(" <a href=\"" . $URL . $IMGS_DIR . $PNG3z . "\"><img src='" . $URL . $IMGS_DIR . $PNG3 . "' border='0'></a>\n"); print(" <a href=\"" . $config->{url} . $config->{imgs_dir} . $PNG3z . "\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG3 . "' border='0'></a>\n");
} }
else { else {
print(" <a href=\"javascript:void(window.open('" . $URL . $IMGS_DIR . $PNG3z . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $URL . $IMGS_DIR . $PNG3 . "' border='0'></a>\n"); print(" <a href=\"javascript:void(window.open('" . $config->{url} . $config->{imgs_dir} . $PNG3z . "','','width=" . ($width + 115) . ",height=" . ($height + 100) . ",scrollbars=0,resizable=0'))\"><img src='" . $config->{url} . $config->{imgs_dir} . $PNG3 . "' border='0'></a>\n");
} }
} else { } else {
print(" <img src='" . $URL . $IMGS_DIR . $PNG3 . "'>\n"); print(" <img src='" . $config->{url} . $config->{imgs_dir} . $PNG3 . "'>\n");
} }
} }
@ -662,7 +672,7 @@ sub system_cgi {
print(" </tr>\n"); print(" </tr>\n");
main::graph_footer(); main::graph_footer();
} }
return 1; print(" <br>\n");
} }
sub get_uptime { sub get_uptime {