mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Merge pull request #3970 from crcro/app-dhcp-stats
app-dhcp-stats initial release
This commit is contained in:
@@ -11,7 +11,7 @@ Different applications support a variety of ways collect data: by direct connect
|
||||
5. [PowerDNS Recursor](#powerdns-recursor) - Agent
|
||||
6. [TinyDNS/djbdns](#tinydns-aka-djbdns) - Agent
|
||||
7. [OS Updates](#os-updates) - extend SNMP
|
||||
|
||||
8. [DHCP Stats](#dhcp-stats) - extend SNMP
|
||||
|
||||
* [Agent Setup](#agent-setup)
|
||||
|
||||
@@ -143,6 +143,20 @@ extend osupdate /opt/os-updates.sh
|
||||
_Note_: apt-get depends on an updated package index. There are several ways to have your system run `apt-get update` automatically. The easiest is to create `/etc/apt/apt.conf.d/10periodic` and pasting the following in it: `APT::Periodic::Update-Package-Lists "1";`.
|
||||
If you have apticron, cron-apt or apt-listchanges installed and configured, chances are that packages are already updated periodically.
|
||||
|
||||
### DHCP Stats
|
||||
A small shell script that reports current DHCP leases stats.
|
||||
|
||||
##### Extend SNMP
|
||||
1. Copy the shell script to the desired host (the host must be added to LibreNMS devices)
|
||||
2. Make the script executable (chmod +x /opt/dhcp-status.sh)
|
||||
3. Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
|
||||
```
|
||||
extend dhcpstats /opt/dhcp-status.sh
|
||||
```
|
||||
4. Restart snmpd on your host
|
||||
5. On the device page in Librenms, edit your host and check the `DHCP Stats` under the Applications tab.
|
||||
|
||||
|
||||
Agent Setup
|
||||
-----------
|
||||
|
||||
|
@@ -77,6 +77,9 @@ function nicecase($item)
|
||||
case 'powerdns-recursor':
|
||||
return 'PowerDNS Recursor';
|
||||
|
||||
case 'dhcp-stats':
|
||||
return 'DHCP Stats';
|
||||
|
||||
default:
|
||||
return ucfirst($item);
|
||||
}
|
||||
|
44
html/includes/graphs/application/dhcp-stats.inc.php
Normal file
44
html/includes/graphs/application/dhcp-stats.inc.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
require 'includes/graphs/common.inc.php';
|
||||
$name = 'dhcp-stats';
|
||||
$app_id = $app['app_id'];
|
||||
$scale_min = 0;
|
||||
$colours = 'mixed';
|
||||
$unit_text = 'Leases';
|
||||
$unitlen = 10;
|
||||
$bigdescrlen = 15;
|
||||
$smalldescrlen = 15;
|
||||
$dostack = 0;
|
||||
$printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 15;
|
||||
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id));
|
||||
|
||||
$array = array(
|
||||
'dhcp_total' => array('descr' => 'Total','colour' => '582A72',),
|
||||
'dhcp_active' => array('descr' => 'Active','colour' => '28774F',),
|
||||
'dhcp_expired' => array('descr' => 'Expired','colour' => 'AA6C39',),
|
||||
'dhcp_released' => array('descr' => 'Released','colour' => '88CC88',),
|
||||
'dhcp_abandoned' => array('descr' => 'Abandoned','colour' => 'D46A6A',),
|
||||
'dhcp_reset' => array('descr' => 'Reset','colour' => 'FFD1AA',),
|
||||
'dhcp_bootp' => array('descr' => 'BootP','colour' => '582A72',),
|
||||
'dhcp_backup' => array('descr' => 'Backup','colour' => 'AA5439',),
|
||||
'dhcp_free' => array('descr' => 'Free','colour' => '28536C',),
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
if (is_file($rrd_filename)) {
|
||||
foreach ($array as $ds => $vars) {
|
||||
$rrd_list[$i]['filename'] = $rrd_filename;
|
||||
$rrd_list[$i]['descr'] = $vars['descr'];
|
||||
$rrd_list[$i]['ds'] = $ds;
|
||||
$rrd_list[$i]['colour'] = $vars['colour'];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
echo "file missing: $rrd_filename";
|
||||
}
|
||||
|
||||
require 'includes/graphs/generic_v3_multiline.inc.php';
|
28
html/pages/device/apps/dhcp-stats.inc.php
Normal file
28
html/pages/device/apps/dhcp-stats.inc.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
global $config;
|
||||
|
||||
$graphs = array(
|
||||
'dhcp-stats' => 'DHCP Stats',
|
||||
);
|
||||
|
||||
foreach ($graphs as $key => $text) {
|
||||
$graph_type = $key;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['time']['now'];
|
||||
$graph_array['id'] = $app['app_id'];
|
||||
$graph_array['type'] = 'application_'.$key;
|
||||
|
||||
echo '<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">'.$text.'</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">';
|
||||
include 'includes/print-graphrow.inc.php';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
37
includes/polling/applications/dhcp-stats.inc.php
Normal file
37
includes/polling/applications/dhcp-stats.inc.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
$name = 'dhcp-stats';
|
||||
$app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$mib = 'NET-SNMP-EXTEND-MIB';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.9.100.104.99.112.115.116.97.116.115';
|
||||
|
||||
$dhcpstats = snmp_walk($device, $oid, $options, $mib);
|
||||
list($dhcp_total,$dhcp_active,$dhcp_expired,$dhcp_released,$dhcp_abandoned,$dhcp_reset,$dhcp_bootp,$dhcp_backup,$dhcp_free) = explode("\n",$dhcpstats);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = array(
|
||||
'DS:dhcp_total:GAUGE:600:0:U',
|
||||
'DS:dhcp_active:GAUGE:600:0:U',
|
||||
'DS:dhcp_expired:GAUGE:600:0:U',
|
||||
'DS:dhcp_released:GAUGE:600:0:U',
|
||||
'DS:dhcp_abandoned:GAUGE:600:0:U',
|
||||
'DS:dhcp_reset:GAUGE:600:0:U',
|
||||
'DS:dhcp_bootp:GAUGE:600:0:U',
|
||||
'DS:dhcp_backup:GAUGE:600:0:U',
|
||||
'DS:dhcp_free:GAUGE:600:0:U',
|
||||
);
|
||||
|
||||
$fields = array(
|
||||
'dhcp_total' => $dhcp_total,
|
||||
'dhcp_active' => $dhcp_active,
|
||||
'dhcp_expired' => $dhcp_expired,
|
||||
'dhcp_released' => $dhcp_released,
|
||||
'dhcp_abandoned' => $dhcp_abandoned,
|
||||
'dhcp_reset' => $dhcp_reset,
|
||||
'dhcp_bootp' => $dhcp_bootp,
|
||||
'dhcp_backup' => $dhcp_backup,
|
||||
'dhcp_free' => $dhcp_free,
|
||||
);
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
Reference in New Issue
Block a user