sammler/sammler.php

676 lines
31 KiB
PHP

<?php
define('CONFIG', 'sammler_graph.conf');
define('BASE_DIR', '/var/lib/rrd/');
define('RRDTOOL', '/usr/bin/rrdtool');
function setup_html($conf) {
echo "<html><head><title>sammler graph setup</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-15\"/>\n";
echo "</head><body>\n";
echo "<form method=\"POST\" action=\"{$_SERVER['SCRIPT_NAME']}?action=setup\">\n";
echo "<table>\n";
echo "<tr><td><b>Graph Height:</b></td>\n";
echo "<td><input type=\"text\" name=\"height\" value=\"{$conf['height']}\"></td></tr>\n";
echo "<tr><td><b>Graph Width:</b></td>\n";
echo "<td><input type=\"text\" name=\"width\" value=\"{$conf['width']}\"></td></tr>\n";
echo "<tr><td colspan=\"4\"><hr></td></tr>\n";
echo "<tr><td><b>Available Views:</b></td><td colspan=\"2\"></td><td><b>default</b></td></tr>\n";
foreach ($conf['views'] as $name => $value) {
echo "<tr><td>({$value}s)</td>\n";
echo "<td><input type=\"text\" name=\"views[$value]\" value=\"{$name}\"></td><td></td>\n";
if ($conf['default_view'] == $value)
echo "<td><input type=\"radio\" name=\"default_view\" value=\"{$value}\" checked=\"checked\"></td>\n";
else
echo "<td><input type=\"radio\" name=\"default_view\" value=\"{$value}\"></td>\n";
echo "</tr>\n";
}
echo "<tr><td><b>add view:</b></td><td><input type=\"text\" name=\"views[new]\"></td></tr>\n";
echo "<tr><td colspan=\"4\"><hr></td></tr>\n";
foreach ($conf['hosts'] as $hostid => $host) {
echo "<tr><td><b>Hostname:</b></td>\n";
echo "<td><input type=\"text\" name=\"hosts[{$hostid}][hostname]\" value=\"{$host['hostname']}\"></td>\n";
echo "<td><a href=\"{$_SERVER['SCRIPT_NAME']}?action=setup&sub=move_host_up&host={$hostid}\">up</a>&nbsp;\n";
echo "<a href=\"{$_SERVER['SCRIPT_NAME']}?action=setup&sub=move_host_down&host={$hostid}\">down</a></td>\n";
if ($host['show'])
echo "<td><input type=\"checkbox\" name=\"hosts[{$hostid}][show]\" checked=\"checked\">show</td>";
else
echo "<td><input type=\"checkbox\" name=\"hosts[{$hostid}][show]\">show</td>";
echo "</tr>\n";
foreach ($host['rrds'] as $rrdid => $rrd) {
echo "<tr><td>&nbsp;&nbsp;{$rrd['rrd']}</td>\n";
echo "<td><input type=\"text\" name=\"hosts[{$hostid}][rrds][{$rrdid}][title]\" value=\"{$rrd['title']}\"></td>\n";
echo "<td><a href=\"{$_SERVER['SCRIPT_NAME']}?action=setup&sub=move_rrd_up&host={$hostid}&rrd={$rrdid}\">up</a>&nbsp;\n";
echo "<a href=\"{$_SERVER['SCRIPT_NAME']}?action=setup&sub=move_rrd_down&host={$hostid}&rrd={$rrdid}\">down</a></td>\n";
if ($rrd['show'])
echo "<td><input type=\"checkbox\" name=\"hosts[{$hostid}][rrds][{$rrdid}][show]\" checked=\"checked\">show</td>";
else
echo "<td><input type=\"checkbox\" name=\"hosts[{$hostid}][rrds][{$rrdid}][show]\">show</td>";
echo "</tr>\n";
}
echo "<tr><td colspan=\"4\"><hr></td></tr>\n";
}
echo "<tr><td colspan=\"4\" align=\"center\">\n";
echo "<input type=\"button\" value=\"Show\" onClick=\"javascript:window.location.href='{$_SERVER['SCRIPT_NAME']}?action=show'\">&nbsp\n";
echo "<input type=\"submit\" value=\"Save Config\">&nbsp\n";
echo "<input type=\"button\" value=\"Rebuild Config\" onClick=\"javascript:window.location.href='{$_SERVER['SCRIPT_NAME']}?action=init'\">\n";
echo "</td></tr>\n";
echo "</table></form>\n";
echo "</body></html>\n";
}
function show_html($conf) {
echo "<html><head><title>Stats</title>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-15\"/>\n";
echo "</head><body>\n";
$hostid = isset($_GET['host']) ? $_GET['host'] : 0;
$view = isset($_GET['view']) ? $_GET['view'] : $conf['default_view'];
echo "<b>Select Host:</b>\n";
echo "<select name=\"host\" OnChange=\"document.location.href='{$_SERVER['SCRIPT_NAME']}?action=show&host='+this.value+'&view={$view}'\">\n";
foreach ($conf['hosts'] as $id => $host) {
if (!$host['show'])
continue;
if ($hostid == $id)
echo "<option value=\"{$id}\" selected=\"selected\">{$host['hostname']}</option>\n";
else
echo "<option value=\"{$id}\">{$host['hostname']}</option>\n";
}
echo "</select>&nbsp;\n";
echo "<td><select name=\"view\" OnChange=\"document.location.href='{$_SERVER['SCRIPT_NAME']}?action=show&host={$hostid}&view='+this.value\">\n";
foreach ($conf['views'] as $name => $value) {
if ($view == $value)
echo "<option value=\"{$value}\" selected=\"selected\">{$name}</option>\n";
else
echo "<option value=\"{$value}\">{$name}</option>\n";
}
echo "</select><br><br>\n";
foreach ($conf['hosts'][$hostid]['rrds'] as $rrdid => $rrd) {
if (!$rrd['show'])
continue;
echo "<img src=\"{$_SERVER['SCRIPT_NAME']}?action=rrd&host={$hostid}&rrd={$rrdid}&view={$view}\" border=\"0\"><br><br>\n";
}
echo "</body></html>\n";
}
function read_config($filename) {
$handle = @fopen($filename, "r");
if ($handle !== false && filesize($filename) > 0) {
$contents = fread($handle, filesize($filename));
fclose($handle);
return unserialize($contents);
}
}
function write_config($filename, $config) {
$handle = fopen($filename, "w+");
if ($handle !== false) {
$contents = serialize($config);
fwrite($handle, $contents);
fclose($handle);
}
}
function get_hostdirs() {
$retval = array();
$dh = opendir(BASE_DIR);
while (($file = readdir($dh)) !== false)
if (is_dir(BASE_DIR.$file) && $file != "." && $file != "..")
$retval[] = $file;
closedir($dh);
natsort($retval);
return $retval;
}
function get_rrdfiles($directory) {
$retval = array();
$dh = opendir(BASE_DIR.$directory);
while (($file = readdir($dh)) !== false) {
if (is_dir(BASE_DIR.$file))
continue;
if (strstr($file, "rrd") !== false)
$retval[] = $file;
}
closedir($dh);
natsort($retval);
return $retval;
}
function create_config() {
$conf = array();
$conf['default_view'] = 86400;
$conf['views'] = array("6 hours" => 21600, "1 day" => 86400, "1 week" => 604800, "1 month" => 2678400);
$conf['height'] = 80;
$conf['width'] = 400;
$conf['hosts'] = array();
$rrds = array();
$tmp = get_rrdfiles('');
foreach ($tmp as $file) {
$rrds[] = array(
'show' => true,
'title' => str_replace(".rrd", "", basename($file)),
'rrd' => $file,
);
}
$hosts = get_hostdirs();
foreach ($hosts as $host) {
$rrds = array();
$tmp = get_rrdfiles($host);
foreach ($tmp as $file) {
$rrds[] = array(
'show' => true,
'title' => str_replace(".rrd", "", basename($file)),
'rrd' => "$host/$file",
);
}
$conf['hosts'][] = array(
'hostname' => $host,
'show' => true,
'rrds' => $rrds,
);
}
return $conf;
}
function setup($conf) {
if (isset($_GET['sub']) && $_GET['sub'] == "move_host_up") {
$hostid = isset($_GET['host']) ? $_GET['host'] : -1;
if (isset($conf['hosts'][$hostid]) && isset($conf['hosts'][$hostid -1])) {
$a = $conf['hosts'][$hostid];
$b = $conf['hosts'][$hostid -1];
$conf['hosts'][$hostid] = $b;
$conf['hosts'][$hostid -1] = $a;
}
return $conf;
} else if (isset($_GET['sub']) && $_GET['sub'] == "move_host_down") {
$hostid = isset($_GET['host']) ? $_GET['host'] : -1;
if (isset($conf['hosts'][$hostid]) && isset($conf['hosts'][$hostid +1])) {
$a = $conf['hosts'][$hostid];
$b = $conf['hosts'][$hostid +1];
$conf['hosts'][$hostid] = $b;
$conf['hosts'][$hostid +1] = $a;
}
return $conf;
} else if (isset($_GET['sub']) && $_GET['sub'] == "move_rrd_up") {
$hostid = isset($_GET['host']) ? $_GET['host'] : -1;
$rrdid = isset($_GET['rrd']) ? $_GET['rrd'] : -1;
if (isset($conf['hosts'][$hostid]['rrds'][$rrdid]) && isset($conf['hosts'][$hostid]['rrds'][$rrdid -1])) {
$a = $conf['hosts'][$hostid]['rrds'][$rrdid];
$b = $conf['hosts'][$hostid]['rrds'][$rrdid -1];
$conf['hosts'][$hostid]['rrds'][$rrdid] = $b;
$conf['hosts'][$hostid]['rrds'][$rrdid -1] = $a;
}
return $conf;
} else if (isset($_GET['sub']) && $_GET['sub'] == "move_rrd_down") {
$hostid = isset($_GET['host']) ? $_GET['host'] : -1;
$rrdid = isset($_GET['rrd']) ? $_GET['rrd'] : -1;
if (isset($conf['hosts'][$hostid]['rrds'][$rrdid]) && isset($conf['hosts'][$hostid]['rrds'][$rrdid +1])) {
$a = $conf['hosts'][$hostid]['rrds'][$rrdid];
$b = $conf['hosts'][$hostid]['rrds'][$rrdid +1];
$conf['hosts'][$hostid]['rrds'][$rrdid] = $b;
$conf['hosts'][$hostid]['rrds'][$rrdid +1] = $a;
}
return $conf;
} else if (!empty($_POST)) {
$conf['default_view'] = $_POST['default_view'];
$conf['height'] = $_POST['height'];
$conf['width'] = $_POST['width'];
$conf['views'] = array();
foreach ($_POST['views'] as $name) {
if (empty($name))
continue;
$tmp = strtotime($name);
if ($tmp != -1)
$conf['views'][$name] = $tmp - time();
}
natsort($conf['views']);
foreach ($_POST['hosts'] as $hostid => $host) {
$conf['hosts'][$hostid]['hostname'] = $host['hostname'];
$conf['hosts'][$hostid]['show'] = ($host['show'] == "on");
foreach ($host['rrds'] as $rrdid => $rrd) {
$conf['hosts'][$hostid]['rrds'][$rrdid]['title'] = $_POST['hosts'][$hostid]['rrds'][$rrdid]['title'];
$conf['hosts'][$hostid]['rrds'][$rrdid]['show'] = ($_POST['hosts'][$hostid]['rrds'][$rrdid]['show'] == "on");
}
}
return $conf;
} else {
setup_html($conf);
}
}
function show_rrd($conf) {
$hostid = isset($_GET['host']) ? $_GET['host'] : -1;
$rrdid = isset($_GET['rrd']) ? $_GET['rrd'] : -1;
if (!isset($conf['hosts'][$hostid]['rrds'][$rrdid]['rrd']))
return;
$view = isset($_GET['view']) ? -$_GET['view'] : -$conf['default_view'];
$rrdfile = BASE_DIR.$conf['hosts'][$hostid]['rrds'][$rrdid]['rrd'];
$title = $conf['hosts'][$hostid]['rrds'][$rrdid]['title'];
$height = $conf['height'];
$width = $conf['width'];
$cmd = RRDTOOL." graph - --imgformat PNG --start {$view} --end -10 --title \"{$title}\" --rigid ";
$tmp1 = explode('-', basename($rrdfile));
$tmp2 = explode('_', $tmp1[0]);
$tmp3 = explode('.', $tmp2[0]);
switch ($tmp3[0]) {
case 'apache':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"Workers\" ".
"DEF:aa={$rrdfile}:total_accesses:AVERAGE ".
"DEF:b={$rrdfile}:total_kbytes:AVERAGE ".
"DEF:c={$rrdfile}:busy_workers:AVERAGE ".
"DEF:d={$rrdfile}:idle_workers:AVERAGE ".
'CDEF:a=aa,60,* '.
'AREA:c#FF0000:"Busy Workers" GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:d#00CF00:"Idle Workers" GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE2:a#0000FF:"Accesses " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s" '.
'';
break;
case 'cpu':
$height *= 2;
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"percent\" ".
"DEF:a={$rrdfile}:user:AVERAGE ".
"DEF:b={$rrdfile}:nice:AVERAGE ".
"DEF:c={$rrdfile}:system:AVERAGE ".
"DEF:e={$rrdfile}:iowait:AVERAGE ".
"DEF:f={$rrdfile}:irq:AVERAGE ".
"DEF:g={$rrdfile}:softirq:AVERAGE ".
"DEF:h={$rrdfile}:steal:AVERAGE ".
"DEF:amax={$rrdfile}:user:MAX ".
"DEF:bmax={$rrdfile}:nice:MAX ".
"DEF:cmax={$rrdfile}:system:MAX ".
"DEF:emax={$rrdfile}:iowait:MAX ".
"DEF:fmax={$rrdfile}:irq:MAX ".
"DEF:gmax={$rrdfile}:softirq:MAX ".
"DEF:hmax={$rrdfile}:steal:MAX ".
"CDEF:allmax=amax,bmax,cmax,emax,fmax,gmax,hmax,+,+,+,+,+,+ ".
'AREA:allmax#C0C0C0 LINE1:allmax#808080 '.
'AREA:h#000000:"Stolen " GPRINT:h:LAST:"Current\:%8.2lf %s" GPRINT:h:AVERAGE:"Average\:%8.2lf %s" GPRINT:h:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#FF0000:"System " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:f#EA8F00:"IRQ " GPRINT:f:LAST:"Current\:%8.2lf %s" GPRINT:f:AVERAGE:"Average\:%8.2lf %s" GPRINT:f:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:g#FFFF00:"Soft-IRQ" GPRINT:g:LAST:"Current\:%8.2lf %s" GPRINT:g:AVERAGE:"Average\:%8.2lf %s" GPRINT:g:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:e#0000FF:"IO-Wait " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:a#00CFCF:"User " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Nice " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" ';
break;
case 'ctstat':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"calls\" ".
"DEF:a={$rrdfile}:searched:AVERAGE ".
"DEF:b={$rrdfile}:found:AVERAGE ".
"DEF:c={$rrdfile}:new:AVERAGE ".
"DEF:d={$rrdfile}:invalid:AVERAGE ".
"DEF:e={$rrdfile}:ignore:AVERAGE ".
"DEF:f={$rrdfile}:delete:AVERAGE ".
"DEF:g={$rrdfile}:delete_list:AVERAGE ".
"DEF:h={$rrdfile}:insert:AVERAGE ".
"DEF:i={$rrdfile}:insert_failed:AVERAGE ".
"DEF:j={$rrdfile}:drop:AVERAGE ".
"DEF:k={$rrdfile}:early_drop:AVERAGE ".
"DEF:l={$rrdfile}:icmp_error:AVERAGE ".
"DEF:m={$rrdfile}:expect_new:AVERAGE ".
"DEF:n={$rrdfile}:expect_create:AVERAGE ".
"DEF:o={$rrdfile}:expect_delete:AVERAGE ".
'CDEF:ii=i,-1,* '.
'CDEF:jj=j,-1,* '.
'CDEF:kk=k,-1,* '.
'CDEF:ll=l,-1,* '.
'CDEF:mm=m,-1,* '.
'CDEF:nn=n,-1,* '.
'CDEF:oo=o,-1,* '.
'LINE1:a#FF0000:"searched " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"found " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"new " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"invalid " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"ignore " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:f#00FF00:"delete " GPRINT:f:LAST:"Current\:%8.0lf" GPRINT:f:AVERAGE:"Average\:%8.0lf" GPRINT:f:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:g#FFFF00:"delete_list " GPRINT:g:LAST:"Current\:%8.0lf" GPRINT:g:AVERAGE:"Average\:%8.0lf" GPRINT:g:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:h#FF7F00:"insert " GPRINT:h:LAST:"Current\:%8.0lf" GPRINT:h:AVERAGE:"Average\:%8.0lf" GPRINT:h:MAX:"Maximum\:%8.0lf\n" '.
'HRULE:0#000000:"-\n" '.
'LINE1:ii#FF0000:"insert_failed " GPRINT:i:LAST:"Current\:%8.0lf" GPRINT:i:AVERAGE:"Average\:%8.0lf" GPRINT:i:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:jj#FF00FF:"drop " GPRINT:j:LAST:"Current\:%8.0lf" GPRINT:j:AVERAGE:"Average\:%8.0lf" GPRINT:j:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:kk#0000FF:"early_drop " GPRINT:k:LAST:"Current\:%8.0lf" GPRINT:k:AVERAGE:"Average\:%8.0lf" GPRINT:k:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:ll#007FFF:"icmp_errore " GPRINT:l:LAST:"Current\:%8.0lf" GPRINT:l:AVERAGE:"Average\:%8.0lf" GPRINT:l:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:mm#00FFFF:"expect_new " GPRINT:m:LAST:"Current\:%8.0lf" GPRINT:m:AVERAGE:"Average\:%8.0lf" GPRINT:m:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:nn#00FF00:"expect_create " GPRINT:n:LAST:"Current\:%8.0lf" GPRINT:n:AVERAGE:"Average\:%8.0lf" GPRINT:n:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:oo#FFFF00:"expect_delete " GPRINT:o:LAST:"Current\:%8.0lf" GPRINT:o:AVERAGE:"Average\:%8.0lf" GPRINT:o:MAX:"Maximum\:%8.0lf\n" ';
break;
case 'load':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"load\" ".
"DEF:a={$rrdfile}:1min:MAX ".
"DEF:b={$rrdfile}:5min:MAX ".
"DEF:c={$rrdfile}:15min:MAX ".
'CDEF:x=a,b,c,MAX,MAX '.
'AREA:a#EACC00:" 1 Minute Maximum " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:b#EA8F00:" 5 Minute Maximum " GPRINT:b:LAST:"Current\:%8.2lf %s\n" '.
'AREA:c#FF0000:"15 Minute Maximum " GPRINT:c:LAST:"Current\:%8.2lf %s\n" '.
'LINE1:x#404040:"Total"';
break;
case 'memory':
$cmd .= "--base=1024 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"kB\" ".
"DEF:aa={$rrdfile}:total:AVERAGE ".
"DEF:bb={$rrdfile}:free:AVERAGE ".
"DEF:cc={$rrdfile}:buffers:AVERAGE ".
"DEF:dd={$rrdfile}:cached:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=bb,1024,* '.
'CDEF:c=cc,1024,* '.
'CDEF:d=dd,1024,* '.
'CDEF:x=aa,bb,cc,dd,+,+,-,1024,* '.
'CDEF:xc=x,c,+ '.
'CDEF:xcd=x,c,d,+,+ '.
'LINE1:a#000000:"Total Memory " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:x#FF0000:"Used Memory " GPRINT:x:LAST:"Current\:%8.2lf %s" GPRINT:x:AVERAGE:"Average\:%8.2lf %s" GPRINT:x:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#FF7D00:"Buffer Memory " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:d#FFC73B:"Cache Memory " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Free Memory " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s" '.
'LINE1:x#404040 LINE1:xc#404040 LINE1:xcd#404040';
break;
case 'mount':
$cmd .= "--base=1024 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"kB\" ".
"DEF:aa={$rrdfile}:block_total:AVERAGE ".
"DEF:cc={$rrdfile}:block_free:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=aa,cc,-,1024,* '.
'CDEF:c=cc,1024,* '.
'LINE1:a#000000:"Total " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:b#FF0000:"Used " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#00CF00:"Free " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s" '.
'LINE1:b#404040 ';
break;
case 'mysql':
switch ($tmp1[1]) {
case 'commands':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"commands\" ".
"DEF:aa={$rrdfile}:com_delete:AVERAGE ".
"DEF:bb={$rrdfile}:com_insert:AVERAGE ".
"DEF:cc={$rrdfile}:com_select:AVERAGE ".
"DEF:dd={$rrdfile}:com_update:AVERAGE ".
"DEF:ee={$rrdfile}:questions:AVERAGE ".
'CDEF:a=aa,60,* '.
'CDEF:b=bb,60,* '.
'CDEF:c=cc,60,* '.
'CDEF:d=dd,60,* '.
'CDEF:e=ee,60,* '.
'AREA:e#0000FF:"All Commands " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s\n" '.
'AREA:a#FF0000:"DELETE ... " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#FF7D00:"INSERT ... " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:d#FFC73B:"UPDATE ... " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:c#00CF00:"SELECT ... " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'';
break;
case 'qcache':
$cmd .= "--base=1024 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"???\" ".
"DEF:a={$rrdfile}:qc_free_blocks:AVERAGE ".
"DEF:b={$rrdfile}:qc_free_memory:AVERAGE ".
"DEF:cc={$rrdfile}:qc_hits:AVERAGE ".
"DEF:dd={$rrdfile}:qc_inserts:AVERAGE ".
"DEF:ee={$rrdfile}:qc_lowmem_prunes:AVERAGE ".
"DEF:ff={$rrdfile}:qc_not_cached:AVERAGE ".
"DEF:g={$rrdfile}:qc_queries_in_cache:AVERAGE ".
"DEF:h={$rrdfile}:qc_total_blocks:AVERAGE ".
'CDEF:c=cc,60,* '.
'CDEF:d=dd,60,* '.
'CDEF:e=ee,60,* '.
'CDEF:f=ff,60,* '.
'LINE1:a#FF0000:"qc_free_blocks " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:b#FFFF00:"qc_free_memory " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:c#00FF00:"qc_hits " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:d#00FFFF:"qc_inserts " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:e#0000FF:"qc_lowmemprunes " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:f#FF00FF:"qc_not_cached " GPRINT:f:LAST:"Current\:%8.2lf %s" GPRINT:f:AVERAGE:"Average\:%8.2lf %s" GPRINT:f:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:g#FF00FF:"qc_queries_in_cache" GPRINT:g:LAST:"Current\:%8.2lf %s" GPRINT:g:AVERAGE:"Average\:%8.2lf %s" GPRINT:g:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:h#000000:"qc_total_blocks " GPRINT:h:LAST:"Current\:%8.2lf %s" GPRINT:h:AVERAGE:"Average\:%8.2lf %s" GPRINT:h:MAX:"Maximum\:%8.2lf %s\n" '.
'';
break;
case 'threads':
$cmd .= "--base=1024 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"threads\" ".
"DEF:a={$rrdfile}:threads_cached:AVERAGE ".
"DEF:b={$rrdfile}:threads_connected:AVERAGE ".
"DEF:cc={$rrdfile}:threads_created:AVERAGE ".
"DEF:d={$rrdfile}:threads_running:AVERAGE ".
'CDEF:c=cc,60,* '.
'LINE1:c#00CF00:"threads created " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:d#FF0000:"threads running " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:b#00FFFF:"threads connected" GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:a#0000FF:"threads cached " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'';
break;
case 'traffic':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"bytes per second\" ".
"DEF:imax={$rrdfile}:bytes_received:MAX ".
"DEF:iavg={$rrdfile}:bytes_received:AVERAGE ".
"DEF:imin={$rrdfile}:bytes_received:MIN ".
"DEF:omax={$rrdfile}:bytes_sent:MAX ".
"DEF:oavg={$rrdfile}:bytes_sent:AVERAGE ".
"DEF:omin={$rrdfile}:bytes_sent:MIN ".
'CDEF:omaxn=omax,-1,* CDEF:oavgn=oavg,-1,* CDEF:ominn=omin,-1,* '.
'CDEF:imid=imax,imin,- CDEF:omid=omaxn,ominn,- '.
'HRULE:0#FF0000 '.
'AREA:imin STACK:imid#A0FFA0:"min/max Inbound " GPRINT:imin:MIN:"%6.2lf%s" GPRINT:imax:MAX:"%6.2lf%s" '.
'LINE1:imin#a0a0a0 LINE1:imax#a0a0a0 LINE1:iavg#008000:"avg Inbound " '.
'GPRINT:iavg:MIN:"min\: %6.2lf%s" GPRINT:iavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:iavg:MAX:"max\: %6.2lf%s\n" '.
'AREA:ominn STACK:omid#C0C0FF:"min/max Outbound" GPRINT:omin:MIN:"%6.2lf%s" GPRINT:omax:MAX:"%6.2lf%s" '.
'LINE1:ominn#a0a0a0 LINE1:omaxn#a0a0a0 LINE1:oavgn#000080:"avg Outbound" '.
'GPRINT:oavg:MIN:"min\: %6.2lf%s" GPRINT:oavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:oavg:MAX:"max\: %6.2lf%s\n" ';
break;
}
break;
case 'net':
$height *= 2;
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"bytes per second\" ".
"DEF:imax={$rrdfile}:byte_in:MAX ".
"DEF:iavg={$rrdfile}:byte_in:AVERAGE ".
"DEF:imin={$rrdfile}:byte_in:MIN ".
"DEF:omax={$rrdfile}:byte_out:MAX ".
"DEF:oavg={$rrdfile}:byte_out:AVERAGE ".
"DEF:omin={$rrdfile}:byte_out:MIN ".
'CDEF:omaxn=omax,-1,* CDEF:oavgn=oavg,-1,* CDEF:ominn=omin,-1,* '.
'CDEF:imid=imax,imin,- CDEF:omid=omaxn,ominn,- '.
'HRULE:0#FF0000 '.
'AREA:imin STACK:imid#A0FFA0:"min/max Inbound " GPRINT:imin:MIN:"%6.2lf%s" GPRINT:imax:MAX:"%6.2lf%s" '.
'LINE1:imin#a0a0a0 LINE1:imax#a0a0a0 LINE1:iavg#008000:"avg Inbound " '.
'GPRINT:iavg:MIN:"min\: %6.2lf%s" GPRINT:iavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:iavg:MAX:"max\: %6.2lf%s\n" '.
'AREA:ominn STACK:omid#C0C0FF:"min/max Outbound" GPRINT:omin:MIN:"%6.2lf%s" GPRINT:omax:MAX:"%6.2lf%s" '.
'LINE1:ominn#a0a0a0 LINE1:omaxn#a0a0a0 LINE1:oavgn#000080:"avg Outbound" '.
'GPRINT:oavg:MIN:"min\: %6.2lf%s" GPRINT:oavg:AVERAGE:"avg\: %6.2lf%s" GPRINT:oavg:MAX:"max\: %6.2lf%s\n" ';
break;
case 'proc':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"per second\" ".
"DEF:a={$rrdfile}:intr:AVERAGE ".
"DEF:b={$rrdfile}:ctxt:AVERAGE ".
"DEF:c={$rrdfile}:fork:AVERAGE ".
'AREA:b#00AF00:"Context " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:a#FF0000:"Interrupts" GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:c#0000FF:"Forks " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" ';
break;
case 'random':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit 0 --vertical-label=\"bytes\" ".
"DEF:a={$rrdfile}:entropy:AVERAGE ".
'AREA:a#00CF00:"Available Entropy" GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s" '.
'LINE1:a#404040 ';
break;
case 'rtcache':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"calls\" ".
"DEF:a={$rrdfile}:entries:AVERAGE ".
"DEF:b={$rrdfile}:gc_total:AVERAGE ".
"DEF:c={$rrdfile}:gc_ignored:AVERAGE ".
"DEF:d={$rrdfile}:gc_goal_miss:AVERAGE ".
"DEF:e={$rrdfile}:gc_dst_overflow:AVERAGE ".
'LINE1:a#FF0000:"entries " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"gc_total " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"gc_ignored " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"gc_goal_miss " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"gc_dst_overflow " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" ';
break;
case 'rtstat':
$height *= 2;
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"calls\" ".
"DEF:a={$rrdfile}:in_hit:AVERAGE ".
"DEF:b={$rrdfile}:in_slow_tot:AVERAGE ".
"DEF:c={$rrdfile}:in_slow_mc:AVERAGE ".
"DEF:d={$rrdfile}:in_no_route:AVERAGE ".
"DEF:e={$rrdfile}:in_brd:AVERAGE ".
"DEF:f={$rrdfile}:in_martian_dst:AVERAGE ".
"DEF:g={$rrdfile}:in_martian_src:AVERAGE ".
"DEF:h={$rrdfile}:in_hlist_search:AVERAGE ".
"DEF:i={$rrdfile}:out_hit:AVERAGE ".
"DEF:j={$rrdfile}:out_slow_tot:AVERAGE ".
"DEF:k={$rrdfile}:out_slow_mc:AVERAGE ".
"DEF:l={$rrdfile}:out_hlist_search:AVERAGE ".
'CDEF:ii=i,-1,* '.
'CDEF:jj=j,-1,* '.
'CDEF:kk=k,-1,* '.
'CDEF:ll=l,-1,* '.
'LINE1:a#FF0000:"in_hit " GPRINT:a:LAST:"Current\:%8.0lf" GPRINT:a:AVERAGE:"Average\:%8.0lf" GPRINT:a:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:b#FF00FF:"in_slow_tot " GPRINT:b:LAST:"Current\:%8.0lf" GPRINT:b:AVERAGE:"Average\:%8.0lf" GPRINT:b:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:c#0000FF:"in_slow_mc " GPRINT:c:LAST:"Current\:%8.0lf" GPRINT:c:AVERAGE:"Average\:%8.0lf" GPRINT:c:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:d#007FFF:"in_no_route " GPRINT:d:LAST:"Current\:%8.0lf" GPRINT:d:AVERAGE:"Average\:%8.0lf" GPRINT:d:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:e#00FFFF:"in_brd " GPRINT:e:LAST:"Current\:%8.0lf" GPRINT:e:AVERAGE:"Average\:%8.0lf" GPRINT:e:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:f#00FF00:"in_martian_dst " GPRINT:f:LAST:"Current\:%8.0lf" GPRINT:f:AVERAGE:"Average\:%8.0lf" GPRINT:f:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:g#FFFF00:"in_martian_src " GPRINT:g:LAST:"Current\:%8.0lf" GPRINT:g:AVERAGE:"Average\:%8.0lf" GPRINT:g:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:h#FF7F00:"in_hlist_search " GPRINT:h:LAST:"Current\:%8.0lf" GPRINT:h:AVERAGE:"Average\:%8.0lf" GPRINT:h:MAX:"Maximum\:%8.0lf\n" '.
'HRULE:0#FF0000:"-\n" '.
'LINE1:ii#FF0000:"out_hit " GPRINT:i:LAST:"Current\:%8.0lf" GPRINT:i:AVERAGE:"Average\:%8.0lf" GPRINT:i:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:jj#FF00FF:"out_slow_tot " GPRINT:j:LAST:"Current\:%8.0lf" GPRINT:j:AVERAGE:"Average\:%8.0lf" GPRINT:j:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:kk#0000FF:"out_slow_mc " GPRINT:k:LAST:"Current\:%8.0lf" GPRINT:k:AVERAGE:"Average\:%8.0lf" GPRINT:k:MAX:"Maximum\:%8.0lf\n" '.
'LINE1:ll#FF7F00:"out_hlist_search " GPRINT:l:LAST:"Current\:%8.0lf" GPRINT:l:AVERAGE:"Average\:%8.0lf" GPRINT:l:MAX:"Maximum\:%8.0lf\n" ';
break;
case 'swap':
$cmd .= "--base=1024 --height={$height} --width={$width} --alt-autoscale-max --lower-limit=0 --vertical-label=\"kB\" ".
"DEF:aa={$rrdfile}:total:AVERAGE ".
"DEF:bb={$rrdfile}:free:AVERAGE ".
'CDEF:a=aa,1024,* '.
'CDEF:b=bb,1024,* '.
'CDEF:x=aa,bb,-,1024,* '.
'LINE1:a#000000:"Total Swap " GPRINT:a:LAST:"Current\:%8.2lf %s\n" '.
'AREA:x#FF0000:"Used Swap " GPRINT:x:LAST:"Current\:%8.2lf %s" GPRINT:x:AVERAGE:"Average\:%8.2lf %s" GPRINT:x:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"Free Swap " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" ';
break;
case 'uptime':
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --lower-limit 0 --vertical-label=\"days\" ".
"DEF:ups={$rrdfile}:uptime:AVERAGE ".
"DEF:idles={$rrdfile}:idletime:AVERAGE ".
'CDEF:up=ups,86400,/ '.
'CDEF:idle=idles,86400,/ '.
'AREA:up#00CF00:"Uptime " '.
'LINE1:idle#002A97:"Idletime "';
break;
case 'vmstat':
$height *= 2;
$cmd .= "--base=1000 --height={$height} --width={$width} --alt-autoscale-max --vertical-label=\"allocs\" ".
"DEF:a={$rrdfile}:pgalloc_high:AVERAGE ".
"DEF:b={$rrdfile}:pgalloc_normal:AVERAGE ".
"DEF:c={$rrdfile}:pgalloc_dma:AVERAGE ".
"DEF:d={$rrdfile}:pgfree:AVERAGE ".
"DEF:e={$rrdfile}:pgfault:AVERAGE ".
"CDEF:ee=e,-1,* ".
'HRULE:0#FF0000: '.
'AREA:c#FF0000:"pgalloc_dma " GPRINT:c:LAST:"Current\:%8.2lf %s" GPRINT:c:AVERAGE:"Average\:%8.2lf %s" GPRINT:c:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:b#00CF00:"pgalloc_normal " GPRINT:b:LAST:"Current\:%8.2lf %s" GPRINT:b:AVERAGE:"Average\:%8.2lf %s" GPRINT:b:MAX:"Maximum\:%8.2lf %s\n" '.
'STACK:a#00CFCF:"pgalloc_high " GPRINT:a:LAST:"Current\:%8.2lf %s" GPRINT:a:AVERAGE:"Average\:%8.2lf %s" GPRINT:a:MAX:"Maximum\:%8.2lf %s\n" '.
'LINE1:d#FF7D00:"pgfree " GPRINT:d:LAST:"Current\:%8.2lf %s" GPRINT:d:AVERAGE:"Average\:%8.2lf %s" GPRINT:d:MAX:"Maximum\:%8.2lf %s\n" '.
'AREA:ee#0040FF:"pgfault " GPRINT:e:LAST:"Current\:%8.2lf %s" GPRINT:e:AVERAGE:"Average\:%8.2lf %s" GPRINT:e:MAX:"Maximum\:%8.2lf %s" '.
'LINE1:ee#002A97 ';
break;
}
header('Content-type: image/x-png');
passthru($cmd);
die();
}
$action = $_GET['action'];
switch ($action) {
case 'init':
$conf = create_config();
write_config(CONFIG, $conf);
header("Location: {$_SERVER['SCRIPT_NAME']}?action=setup");
break;
case 'setup':
$conf = read_config(CONFIG);
$conf = setup($conf);
if (isset($conf)) {
write_config(CONFIG, $conf);
header("Location: {$_SERVER['SCRIPT_NAME']}?action=setup");
}
break;
case 'rrd':
$conf = read_config(CONFIG);
show_rrd($conf);
break;
default:
case 'show':
$conf = read_config(CONFIG);
show_html($conf);
break;
}
?>