Exemplo n.º 1
0
<?php

# Collectd Ping plugin
require_once 'conf/common.inc.php';
require_once 'type/Default.class.php';
require_once 'inc/collectd.inc.php';
## LAYOUT
# ping/
# ping/ping-<host>.rrd
# ping/ping_stddev-<host>.rrd
# ping/ping_droprate-<host>.rrd
$obj = new Type_Default($CONFIG);
$obj->data_sources = array('value');
$obj->ds_names = array('ping' => 'Ping time', 'ping_stddev' => 'Ping stddev', 'ping_droprate' => 'Ping droprate');
$obj->width = $width;
$obj->heigth = $heigth;
$obj->rrd_format = '%5.1lf';
switch ($obj->args['type']) {
    case 'ping':
        if ($CONFIG['version'] < 5) {
            $obj->data_sources = array('ping');
        }
        $obj->rrd_title = 'Ping latency';
        $obj->rrd_vertical = 'Milliseconds';
        break;
    case 'ping_stddev':
        $obj->rrd_title = 'Ping stddev';
        $obj->rrd_vertical = '';
        break;
    case 'ping_droprate':
        $obj->rrd_title = 'Ping droprate';
Exemplo n.º 2
0
function host_summary($cat, $hosts)
{
    global $CONFIG;
    $rrd = new RRDTool($CONFIG['rrdtool']);
    printf('<fieldset id="%s">', htmlentities($cat));
    printf('<legend>%s</legend>', htmlentities($cat));
    echo "<div class=\"summary\">\n";
    $row_style = array(0 => "even", 1 => "odd");
    $host_counter = 0;
    foreach ($hosts as $host) {
        $host_counter++;
        printf('<div class="row %s">', $row_style[$host_counter % 2]);
        printf('<label><a href="%shost.php?h=%s">%s</a></label>', htmlentities($CONFIG['weburl']), urlencode($host), htmlentities($host));
        echo "<div class=\"hostinfo\">";
        if ($CONFIG['showload']) {
            require_once 'type/Default.class.php';
            $load = array('h' => $host, 'p' => 'load', 't' => 'load');
            $obj = new Type_Default($CONFIG, $load);
            $obj->collectd_flush();
            $rrd_info = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/load/load.rrd');
            if ($rrd_info && isset($rrd_info['ds[shortterm].last_ds']) && isset($rrd_info['ds[midterm].last_ds']) && isset($rrd_info['ds[longterm].last_ds'])) {
                $cores = count(group_plugindata(collectd_plugindata($host, 'cpu')));
                foreach (array('ds[shortterm].last_ds', 'ds[midterm].last_ds', 'ds[longterm].last_ds') as $info) {
                    $class = '';
                    if ($cores > 0 && $rrd_info[$info] > $cores * 2) {
                        $class = ' crit';
                    } elseif ($cores > 0 && $rrd_info[$info] > $cores) {
                        $class = ' warn';
                    }
                    printf('<div class="field%s">%.2f</div>', $class, $rrd_info[$info]);
                }
            }
        }
        if ($CONFIG['showmem']) {
            $rrd_info_mu = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/memory/memory-used.rrd');
            $rrd_info_mf = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/memory/memory-free.rrd');
            $rrd_info_bf = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/memory/memory-buffered.rrd');
            $rrd_info_ca = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/memory/memory-cached.rrd');
            # ignore if file does not exist
            if ($rrd_info_mu && $rrd_info_mf && $rrd_info_bf && $rrd_info_ca) {
                $info = 'ds[value].last_ds';
                if (isset($rrd_info_mu[$info]) && isset($rrd_info_mf[$info]) && isset($rrd_info_bf[$info]) && isset($rrd_info_ca[$info])) {
                    $percent_mem = $rrd_info_mu[$info] * 100 / ($rrd_info_mu[$info] + $rrd_info_mf[$info] + $rrd_info_bf[$info] + $rrd_info_ca[$info]);
                    $class = '';
                    if ($percent_mem > 90) {
                        $class = ' crit';
                    } elseif ($percent_mem > 70) {
                        $class = ' warn';
                    }
                    printf('<div class="field%s">%d%%</div>', $class, $percent_mem);
                }
            }
        }
        if ($CONFIG['showtime']) {
            $rrd_info = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/load/load.rrd');
            if ($rrd_info) {
                $time = time() - $rrd_info['last_update'];
                $class = 'wide';
                if ($time > 300) {
                    $class .= ' crit';
                } elseif ($time > 60) {
                    $class .= ' warn';
                }
                printf('<div class="field %s"><time class="timeago" datetime="%s">%d seconds ago</time></div>', $class, date('c', $rrd_info['last_update']), $time);
            }
        }
        if ($CONFIG['showamp']) {
            $rrd_info = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/snmp/gauge-Load Ampere.rrd');
            if ($rrd_info) {
                $info = 'ds[value].last_ds';
                $amp = $rrd_info[$info];
                $class = '';
                if ($amp > 5) {
                    $class .= ' crit';
                } elseif ($amp > 4) {
                    $class .= ' warn';
                }
                printf('<div class="field %s">%.2f A</div>', $class, $amp);
            }
        }
        if ($CONFIG['showatt']) {
            $rrd_info = $rrd->rrd_info($CONFIG['datadir'] . '/' . $host . '/snmp/power-Power Watts.rrd');
            if ($rrd_info) {
                $info = 'ds[value].last_ds';
                $amp = $rrd_info[$info];
                $class = '';
                if ($amp > 1000) {
                    $class .= ' crit';
                } elseif ($amp > 500) {
                    $class .= ' warn';
                }
                printf('<div class="field %s">%d Watt</div>', $class, $amp);
            }
        }
        print "</div></div>\n";
    }
    echo "</div>\n";
    echo "</fieldset>\n";
}