Merge pull request #295 from laf/issue-laf-37

Adding ping and poller graphs for devices
This commit is contained in:
Paul Gear
2014-10-07 19:31:21 +10:00
7 changed files with 105 additions and 7 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

@@ -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'] . "/poller-perf.rrd";
$rrd_options .= " DEF:poller=".$rrd_filename.":poller:AVERAGE";
$rrd_options .= " 'COMMENT:Seconds Current Minimum Maximum Average\\n'";
$rrd_options .= " LINE1.25:poller#36393D:Poller";
$rrd_options .= " GPRINT:poller:LAST:%6.2lf GPRINT:poller:AVERAGE:%6.2lf";
$rrd_options .= " GPRINT:poller:MAX:%6.2lf 'GPRINT:poller:AVERAGE:%6.2lf\\n'";
?>

View File

@@ -23,6 +23,10 @@ foreach (dbFetchRows("SELECT * FROM device_graphs WHERE device_id = ? ORDER BY g
$graph_enable[$section][$graph['graph']] = $graph['graph'];
}
// 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

@@ -1058,6 +1058,12 @@ $config['graph_types']['device']['ucd_interrupts']['descr'] = 'Interrupts';
$config['graph_types']['device']['uptime']['section'] = 'system';
$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 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,30 @@ function isSNMPable($device)
}
}
function isPingable($hostname)
function isPingable($hostname,$device_id = FALSE)
{
global $config;
$status = shell_exec($config['fping'] . " $hostname 2>/dev/null");
$status = shell_exec($config['fping'] . " -e $hostname 2>/dev/null");
$response = array();
if (strstr($status, "alive"))
{
return TRUE;
$response['result'] = TRUE;
} else {
$status = shell_exec($config['fping6'] . " $hostname 2>/dev/null");
$status = shell_exec($config['fping6'] . " -e $hostname 2>/dev/null");
if (strstr($status, "alive"))
{
return TRUE;
$response['result'] = TRUE;
} else {
return FALSE;
$response['result'] = FALSE;
}
}
if(is_numeric($device_id) && !empty($device_id))
{
preg_match('/(\d+\.*\d*) (ms)/', $status, $time);
$response['last_ping_timetaken'] = $time[1];
}
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,8 +198,31 @@ 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))
{
rrdtool_create ($poller_rrd, "DS:poller:GAUGE:600:0:U ".$config['rrd_rra']);
}
if(!empty($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");

2
sql-schema/035.sql Normal file
View File

@@ -0,0 +1,2 @@
-- Update to add ping response time and last ping datetime
ALTER TABLE `devices` ADD `last_ping` TIMESTAMP NULL AFTER `last_discovered` , ADD `last_ping_timetaken` DOUBLE( 5, 2 ) NULL AFTER `last_ping` ;