Added ping response graphs and some small updates

This commit is contained in:
laf
2014-09-29 23:03:59 +01:00
parent 6a1ebd9db4
commit 9a178363a0
5 changed files with 64 additions and 8 deletions

View File

@@ -0,0 +1,27 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$scale_min = "0";
include("includes/graphs/common.inc.php");
$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ping-perf.rrd";
$rrd_options .= " DEF:ping=".$rrd_filename.":ping:AVERAGE";
$rrd_options .= " 'COMMENT:Seconds Current Minimum Maximum Average\\n'";
$rrd_options .= " LINE1.25:ping#36393D:Ping";
$rrd_options .= " GPRINT:ping:LAST:%6.2lf GPRINT:ping:AVERAGE:%6.2lf";
$rrd_options .= " GPRINT:ping:MAX:%6.2lf 'GPRINT:ping:AVERAGE:%6.2lf\\n'";
?>

View File

@@ -25,6 +25,7 @@ foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY g
// These are standard graphs we should have for all systems
$graph_enable['poller']['poller_perf'] = 'device_poller_perf';
$graph_enable['poller']['ping_perf'] = 'device_ping_perf';
#foreach ($config['graph_sections'] as $section)
foreach ($graph_enable as $section => $nothing)

View File

@@ -1060,7 +1060,10 @@ $config['graph_types']['device']['uptime']['order'] = '0';
$config['graph_types']['device']['uptime']['descr'] = 'System Uptime';
$config['graph_types']['device']['poller_perf']['section'] = 'poller';
$config['graph_types']['device']['poller_perf']['order'] = '0';
$config['graph_types']['device']['poller_perf']['descr'] = 'Poller Performance';
$config['graph_types']['device']['poller_perf']['descr'] = 'Poller Time';
$config['graph_types']['device']['ping_perf']['section'] = 'poller';
$config['graph_types']['device']['ping_perf']['order'] = '0';
$config['graph_types']['device']['ping_perf']['descr'] = 'Ping Response';
$config['graph_types']['device']['vpdn_sessions_l2tp']['section'] = 'vpdn';
$config['graph_types']['device']['vpdn_sessions_l2tp']['order'] = '0';

View File

@@ -459,23 +459,33 @@ function isSNMPable($device)
}
}
function isPingable($hostname)
function isPingable($hostname,$device_id)
{
global $config;
$status = shell_exec($config['fping'] . " $hostname 2>/dev/null");
$status = shell_exec($config['fping'] . " -e $hostname 2>/dev/null");
if (strstr($status, "alive"))
{
return TRUE;
if(is_numeric($device_id) && !empty($device_id))
{
preg_match('/(\d+\.*\d*) (ms)/', $status, $time);
$response['last_ping_timetaken'] = $time[1];
$response['result'] = TRUE;
}
else
{
$response['result'] = TRUE;
}
} else {
$status = shell_exec($config['fping6'] . " $hostname 2>/dev/null");
if (strstr($status, "alive"))
{
return TRUE;
$response['result'] = TRUE;
} else {
return FALSE;
$response['result'] = FALSE;
}
}
return($response);
}
function is_odd($number)

View File

@@ -110,7 +110,9 @@ function poll_device($device, $options)
$host_rrd = $config['rrd_dir'] . "/" . $device['hostname'];
if (!is_dir($host_rrd)) { mkdir($host_rrd); echo("Created directory : $host_rrd\n"); }
$device['pingable'] = isPingable($device['hostname']);
$ping_response = isPingable($device['hostname'],$device['device_id']);
$device['pingable'] = $ping_response['result'];
$ping_time = $ping_response['last_ping_timetaken'];
if ($device['pingable'])
{
$device['snmpable'] = isSNMPable($device);
@@ -196,6 +198,7 @@ function poll_device($device, $options)
$device_end = utime(); $device_run = $device_end - $device_start; $device_time = substr($device_run, 0, 5);
// Poller performance rrd
$poller_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/poller-perf.rrd";
if (!is_file($poller_rrd))
{
@@ -203,11 +206,23 @@ function poll_device($device, $options)
}
if(!empty($device_time))
{
rrdtool_update($poller_rrd, "N:".$device_time);
rrdtool_update($poller_rrd, "N:$device_time");
}
// Ping response rrd
$ping_rrd = $config['rrd_dir'] . "/" . $device['hostname'] . "/ping-perf.rrd";
if (!is_file($ping_rrd))
{
rrdtool_create ($ping_rrd, "DS:ping:GAUGE:600:0:65535 ".$config['rrd_rra']);
}
if(!empty($ping_time))
{
rrdtool_update($ping_rrd, "N:$ping_time");
}
$update_array['last_polled'] = array('NOW()');
$update_array['last_polled_timetaken'] = $device_time;
$update_array['last_ping'] = array('NOW()');
$update_array['last_ping_timetaken'] = $ping_time;
#echo("$device_end - $device_start; $device_time $device_run");
echo("Polled in $device_time seconds\n");