mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Application DHCP Upgrade
This commit is contained in:
@@ -48,7 +48,7 @@ class StringHelpers
|
|||||||
$replacements = [
|
$replacements = [
|
||||||
'bind' => 'BIND',
|
'bind' => 'BIND',
|
||||||
'dbm' => 'dBm',
|
'dbm' => 'dBm',
|
||||||
'dhcp-stats' => 'DHCP Stats',
|
'dhcp-stats' => 'ISC DHCP Server',
|
||||||
'entropy' => 'Random entropy',
|
'entropy' => 'Random entropy',
|
||||||
'exim-stats' => 'EXIM Stats',
|
'exim-stats' => 'EXIM Stats',
|
||||||
'fbsd-nfs-client' => 'FreeBSD NFS Client',
|
'fbsd-nfs-client' => 'FreeBSD NFS Client',
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class EventlogSensorReferenceCleanup extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::table('application_metrics', function (Blueprint $table) {
|
||||||
|
$table->string('metric', 64)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::table('application_metrics', function (Blueprint $table) {
|
||||||
|
$table->string('metric', 32)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -405,25 +405,38 @@ Extend` heading top of page.
|
|||||||
|
|
||||||
# DHCP Stats
|
# DHCP Stats
|
||||||
|
|
||||||
A small shell script that reports current DHCP leases stats.
|
A small python3 script that reports current DHCP leases stats and pool usage.
|
||||||
|
|
||||||
|
Also you have to install the dhcpd-pools Package.
|
||||||
|
Under Ubuntu/Debian just run `apt install dhcpd-pools`
|
||||||
|
|
||||||
## SNMP Extend
|
## SNMP Extend
|
||||||
|
|
||||||
1: Copy the shell script to the desired host.
|
1: Copy the shell script to the desired host.
|
||||||
|
|
||||||
```
|
```
|
||||||
wget https://github.com/librenms/librenms-agent/raw/master/snmp/dhcp-status.sh -O /etc/snmp/dhcp-status.sh
|
wget https://github.com/librenms/librenms-agent/raw/master/snmp/dhcp.py -O /etc/snmp/dhcp.py
|
||||||
```
|
```
|
||||||
|
|
||||||
2: Run `chmod +x /etc/snmp/dhcp-status.sh`
|
2: Run `chmod +x /etc/snmp/dhcp.py`
|
||||||
|
|
||||||
3: Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
|
|
||||||
|
3: edit a config file:
|
||||||
|
|
||||||
|
Content of an example /etc/snmp/dhcp.json . Please edit with your own settings.
|
||||||
|
```
|
||||||
|
{"leasefile": "/var/lib/dhcp/dhcpd.leases"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Key 'leasefile' specifies the path to your lease file.
|
||||||
|
|
||||||
|
4: Edit your snmpd.conf file (usually /etc/snmp/snmpd.conf) and add:
|
||||||
|
|
||||||
```
|
```
|
||||||
extend dhcpstats /etc/snmp/dhcp-status.sh
|
extend dhcpstats /etc/snmp/dhcp.py
|
||||||
```
|
```
|
||||||
|
|
||||||
4: Restart snmpd on your host
|
5: Restart snmpd on your host
|
||||||
|
|
||||||
The application should be auto-discovered as described at the top of
|
The application should be auto-discovered as described at the top of
|
||||||
the page. If it is not, please follow the steps set out under `SNMP
|
the page. If it is not, please follow the steps set out under `SNMP
|
||||||
|
|||||||
@@ -1279,6 +1279,7 @@ function get_postgres_databases($device_id)
|
|||||||
function get_arrays_with_application($device, $app_id, $app_name, $category = null)
|
function get_arrays_with_application($device, $app_id, $app_name, $category = null)
|
||||||
{
|
{
|
||||||
$entries = array();
|
$entries = array();
|
||||||
|
$separator = '-';
|
||||||
|
|
||||||
if ($category) {
|
if ($category) {
|
||||||
$pattern = sprintf('%s/%s-%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id, $category);
|
$pattern = sprintf('%s/%s-%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id, $category);
|
||||||
@@ -1286,10 +1287,13 @@ function get_arrays_with_application($device, $app_id, $app_name, $category = nu
|
|||||||
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id);
|
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# app_name contains a separator character? consider it
|
||||||
|
$offset = substr_count($app_name, $separator);
|
||||||
|
|
||||||
foreach (glob($pattern) as $rrd) {
|
foreach (glob($pattern) as $rrd) {
|
||||||
$filename = basename($rrd, '.rrd');
|
$filename = basename($rrd, '.rrd');
|
||||||
|
|
||||||
list(,,, $entry) = explode("-", $filename, 4);
|
$entry = explode($separator, $filename, 4 + $offset)[3 + $offset];
|
||||||
|
|
||||||
if ($entry) {
|
if ($entry) {
|
||||||
array_push($entries, $entry);
|
array_push($entries, $entry);
|
||||||
@@ -1328,6 +1332,21 @@ function get_arrays_with_seafile($device, $app_id, $category)
|
|||||||
return get_arrays_with_application($device, $app_id, $app_name, $category);
|
return get_arrays_with_application($device, $app_id, $app_name, $category);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all dhcp data from the collected
|
||||||
|
* rrd files.
|
||||||
|
*
|
||||||
|
* @param array $device device for which we get the rrd's
|
||||||
|
* @param int $app_id application id on the device
|
||||||
|
* @param string $category which category of dhcp graphs are searched
|
||||||
|
* @return array list of dhcp data
|
||||||
|
*/
|
||||||
|
function get_arrays_with_dhcpstats($device, $app_id, $category)
|
||||||
|
{
|
||||||
|
$app_name = 'dhcp-stats';
|
||||||
|
return get_arrays_with_application($device, $app_id, $app_name, $category);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all mdadm arrays from the collected
|
* Get all mdadm arrays from the collected
|
||||||
* rrd files.
|
* rrd files.
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Current';
|
||||||
|
$unitlen = 20;
|
||||||
|
$bigdescrlen = 20;
|
||||||
|
$smalldescrlen = 20;
|
||||||
|
$category = 'networks';
|
||||||
|
|
||||||
|
$rrdVar = 'current';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => $net.'/'.$subnet,
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Max';
|
||||||
|
$unitlen = 20;
|
||||||
|
$bigdescrlen = 20;
|
||||||
|
$smalldescrlen = 20;
|
||||||
|
$category = 'networks';
|
||||||
|
|
||||||
|
$rrdVar = 'max';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => $net.'/'.$subnet,
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Percent';
|
||||||
|
$unitlen = 20;
|
||||||
|
$bigdescrlen = 20;
|
||||||
|
$smalldescrlen = 20;
|
||||||
|
$category = 'networks';
|
||||||
|
|
||||||
|
$rrdVar = 'percent';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => $net.'/'.$subnet,
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Current';
|
||||||
|
$unitlen = 33;
|
||||||
|
$bigdescrlen = 33;
|
||||||
|
$smalldescrlen = 33;
|
||||||
|
$category = 'pools';
|
||||||
|
|
||||||
|
$rrdVar = 'current';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => str_replace($category.'-', '', $array),
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Max';
|
||||||
|
$unitlen = 33;
|
||||||
|
$bigdescrlen = 33;
|
||||||
|
$smalldescrlen = 33;
|
||||||
|
$category = 'pools';
|
||||||
|
|
||||||
|
$rrdVar = 'max';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => str_replace($category.'-', '', $array),
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
$unit_text = 'Percent';
|
||||||
|
$unitlen = 33;
|
||||||
|
$bigdescrlen = 33;
|
||||||
|
$smalldescrlen = 33;
|
||||||
|
$category = 'pools';
|
||||||
|
|
||||||
|
$rrdVar = 'percent';
|
||||||
|
|
||||||
|
$name = 'dhcp-stats';
|
||||||
|
$app_id = $app['app_id'];
|
||||||
|
$colours = 'mega';
|
||||||
|
$dostack = 0;
|
||||||
|
$printtotal = 0;
|
||||||
|
$addarea = 1;
|
||||||
|
$transparency = 15;
|
||||||
|
|
||||||
|
|
||||||
|
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
|
||||||
|
|
||||||
|
$int=0;
|
||||||
|
while (isset($arrays[$int])) {
|
||||||
|
$array = $arrays[$int];
|
||||||
|
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
|
||||||
|
|
||||||
|
if (rrdtool_check_rrd_exists($rrd_filename)) {
|
||||||
|
$rrd_list[] = array(
|
||||||
|
'filename' => $rrd_filename,
|
||||||
|
'descr' => str_replace($category.'-', '', $array),
|
||||||
|
'ds' => $rrdVar,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$int++;
|
||||||
|
}
|
||||||
|
|
||||||
|
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';
|
||||||
@@ -124,6 +124,12 @@ $graphs['os-updates'] = array(
|
|||||||
);
|
);
|
||||||
$graphs['dhcp-stats'] = array(
|
$graphs['dhcp-stats'] = array(
|
||||||
'stats',
|
'stats',
|
||||||
|
'pools_percent',
|
||||||
|
'pools_current',
|
||||||
|
'pools_max',
|
||||||
|
'networks_percent',
|
||||||
|
'networks_current',
|
||||||
|
'networks_max',
|
||||||
);
|
);
|
||||||
$graphs['fail2ban'] = array(
|
$graphs['fail2ban'] = array(
|
||||||
'banned',
|
'banned',
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$graphs = array(
|
$graphs = array(
|
||||||
'dhcp-stats_stats' => 'DHCP Stats',
|
'dhcp-stats_stats' => 'Stats',
|
||||||
|
'dhcp-stats_pools_percent' => 'Pools Percent',
|
||||||
|
'dhcp-stats_pools_current' => 'Pools Current',
|
||||||
|
'dhcp-stats_pools_max' => 'Pools Max',
|
||||||
|
'dhcp-stats_networks_percent' => 'Networks Percent',
|
||||||
|
'dhcp-stats_networks_current' => 'Networks Current',
|
||||||
|
'dhcp-stats_networks_max' => 'Networks Max',
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($graphs as $key => $text) {
|
foreach ($graphs as $key => $text) {
|
||||||
$graph_type = $key;
|
$graph_type = $key;
|
||||||
$graph_array['height'] = '100';
|
$graph_array['height'] = '100';
|
||||||
$graph_array['width'] = '215';
|
$graph_array['width'] = '215';
|
||||||
$graph_array['to'] = \LibreNMS\Config::get('time.now');
|
$graph_array['to'] = time();
|
||||||
$graph_array['id'] = $app['app_id'];
|
$graph_array['id'] = $app['app_id'];
|
||||||
$graph_array['type'] = 'application_'.$key;
|
$graph_array['type'] = 'application_'.$key;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,57 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use LibreNMS\Exceptions\JsonAppMissingKeysException;
|
||||||
|
use LibreNMS\Exceptions\JsonAppException;
|
||||||
use LibreNMS\RRD\RrdDefinition;
|
use LibreNMS\RRD\RrdDefinition;
|
||||||
|
|
||||||
|
$snmp_extend_name = 'dhcpstats';
|
||||||
$name = 'dhcp-stats';
|
$name = 'dhcp-stats';
|
||||||
$app_id = $app['app_id'];
|
$app_id = $app['app_id'];
|
||||||
$options = '-Oqv';
|
$options = '-Oqv';
|
||||||
$mib = 'NET-SNMP-EXTEND-MIB';
|
$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';
|
$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);
|
$version = 1;
|
||||||
list($dhcp_total,$dhcp_active,$dhcp_expired,$dhcp_released,$dhcp_abandoned,$dhcp_reset,$dhcp_bootp,$dhcp_backup,$dhcp_free) = explode("\n", $dhcpstats);
|
$output = 'OK';
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dhcp_data = json_app_get($device, $snmp_extend_name, 1);
|
||||||
|
$dhcpstats = $dhcp_data['data'];
|
||||||
|
$version = $dhcp_data['version'];
|
||||||
|
} catch (JsonAppMissingKeysException $e) {
|
||||||
|
$dhcpstats = $e->getParsedJson();
|
||||||
|
$output = 'ERROR';
|
||||||
|
} catch (JsonAppException $e) {
|
||||||
|
$dhcpstats = snmp_walk($device, $oid, $options, $mib);
|
||||||
|
}
|
||||||
|
|
||||||
|
$version = intval($version);
|
||||||
|
|
||||||
|
if ($version == 1) {
|
||||||
|
$output = 'LEGACY';
|
||||||
|
} elseif ($version == 2) {
|
||||||
|
$output = 'OK';
|
||||||
|
} else {
|
||||||
|
$output = 'UNSUPPORTED';
|
||||||
|
}
|
||||||
|
|
||||||
|
$metrics = array();
|
||||||
|
$category = 'stats';
|
||||||
|
if (intval($version) == 1) {
|
||||||
|
list($dhcp_total, $dhcp_active, $dhcp_expired, $dhcp_released, $dhcp_abandoned, $dhcp_reset, $dhcp_bootp, $dhcp_backup, $dhcp_free) = explode("\n", $dhcpstats);
|
||||||
|
} elseif ($version == 2) {
|
||||||
|
$lease_data = $dhcpstats['leases'];
|
||||||
|
|
||||||
|
$dhcp_total = $lease_data['total'];
|
||||||
|
$dhcp_active = $lease_data['active'];
|
||||||
|
$dhcp_expired = $lease_data['expired'];
|
||||||
|
$dhcp_released = $lease_data['released'];
|
||||||
|
$dhcp_abandoned = $lease_data['abandoned'];
|
||||||
|
$dhcp_reset = $lease_data['reset'];
|
||||||
|
$dhcp_bootp = $lease_data['bootp'];
|
||||||
|
$dhcp_backup = $lease_data['backup'];
|
||||||
|
$dhcp_free = $lease_data['free'];
|
||||||
|
}
|
||||||
|
|
||||||
$rrd_name = array('app', $name, $app_id);
|
$rrd_name = array('app', $name, $app_id);
|
||||||
$rrd_def = RrdDefinition::make()
|
$rrd_def = RrdDefinition::make()
|
||||||
@@ -24,17 +66,81 @@ $rrd_def = RrdDefinition::make()
|
|||||||
->addDataset('dhcp_free', 'GAUGE', 0);
|
->addDataset('dhcp_free', 'GAUGE', 0);
|
||||||
|
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'dhcp_total' => $dhcp_total,
|
'dhcp_total' => $dhcp_total,
|
||||||
'dhcp_active' => $dhcp_active,
|
'dhcp_active' => $dhcp_active,
|
||||||
'dhcp_expired' => $dhcp_expired,
|
'dhcp_expired' => $dhcp_expired,
|
||||||
'dhcp_released' => $dhcp_released,
|
'dhcp_released' => $dhcp_released,
|
||||||
'dhcp_abandoned' => $dhcp_abandoned,
|
'dhcp_abandoned' => $dhcp_abandoned,
|
||||||
'dhcp_reset' => $dhcp_reset,
|
'dhcp_reset' => $dhcp_reset,
|
||||||
'dhcp_bootp' => $dhcp_bootp,
|
'dhcp_bootp' => $dhcp_bootp,
|
||||||
'dhcp_backup' => $dhcp_backup,
|
'dhcp_backup' => $dhcp_backup,
|
||||||
'dhcp_free' => $dhcp_free,
|
'dhcp_free' => $dhcp_free,
|
||||||
);
|
);
|
||||||
|
$metrics[$name . '_' . $category] = $fields;
|
||||||
|
|
||||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||||
data_update($device, 'app', $tags, $fields);
|
data_update($device, 'app', $tags, $fields);
|
||||||
update_application($app, $dhcpstats, $fields);
|
|
||||||
|
if ($version == 2) {
|
||||||
|
$category = 'pools';
|
||||||
|
$pool_data = $dhcpstats['pools'];
|
||||||
|
|
||||||
|
$rrd_def = RrdDefinition::make()
|
||||||
|
->addDataset('current', 'GAUGE', 0)
|
||||||
|
->addDataset('max', 'GAUGE', 0)
|
||||||
|
->addDataset('percent', 'GAUGE', 0);
|
||||||
|
|
||||||
|
foreach ($pool_data as $data) {
|
||||||
|
$dhcp_pool_name = $data['first_ip'].'_-_'.$data['last_ip'];
|
||||||
|
$dhcp_current = $data['cur'];
|
||||||
|
$dhcp_max = $data['max'];
|
||||||
|
$dhcp_percent = $data['percent'];
|
||||||
|
|
||||||
|
$rrd_name = array('app', $name, $app_id, $category, $dhcp_pool_name);
|
||||||
|
|
||||||
|
$fields = array(
|
||||||
|
'current' => $dhcp_current,
|
||||||
|
'max' => $dhcp_max,
|
||||||
|
'percent' => $dhcp_percent,
|
||||||
|
);
|
||||||
|
|
||||||
|
$metrics[$dhcp_pool_name.'_'.$category] = $fields;
|
||||||
|
$tags = array('name' => $dhcp_pool_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||||
|
data_update($device, 'app', $tags, $fields);
|
||||||
|
}
|
||||||
|
|
||||||
|
$category = 'networks';
|
||||||
|
$network_data = $dhcpstats['networks'];
|
||||||
|
|
||||||
|
$rrd_def = RrdDefinition::make()
|
||||||
|
->addDataset('current', 'GAUGE', 0)
|
||||||
|
->addDataset('max', 'GAUGE', 0)
|
||||||
|
->addDataset('percent', 'GAUGE', 0);
|
||||||
|
|
||||||
|
foreach ($network_data as $data) {
|
||||||
|
$dhcp_network_name = str_replace('/', '_', $data['network']);
|
||||||
|
$dhcp_current = $data['cur'];
|
||||||
|
$dhcp_max = $data['max'];
|
||||||
|
$dhcp_percent = $data['percent'] == 'nan' ? '0' : $data['percent'];
|
||||||
|
|
||||||
|
$rrd_name = array('app', $name, $app_id, $category, $dhcp_network_name);
|
||||||
|
|
||||||
|
$fields = array(
|
||||||
|
'current' => $dhcp_current,
|
||||||
|
'max' => $dhcp_max,
|
||||||
|
'percent' => $dhcp_percent,
|
||||||
|
);
|
||||||
|
|
||||||
|
$metrics[$dhcp_network_name.'_'.$category] = $fields;
|
||||||
|
$tags = array('name' => $dhcp_network_name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||||
|
data_update($device, 'app', $tags, $fields);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($version == 1) {
|
||||||
|
$app_state = $dhcp_active . '/' . $dhcp_total;
|
||||||
|
} else {
|
||||||
|
$app_state = $dhcpstats['all_networks']['cur'] . '/' . $dhcpstats['all_networks']['max'];
|
||||||
|
}
|
||||||
|
|
||||||
|
update_application($app, $output, $metrics, $app_state);
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ applications:
|
|||||||
application_metrics:
|
application_metrics:
|
||||||
Columns:
|
Columns:
|
||||||
- { Field: app_id, Type: 'int(10) unsigned', 'Null': false, Extra: '' }
|
- { Field: app_id, Type: 'int(10) unsigned', 'Null': false, Extra: '' }
|
||||||
- { Field: metric, Type: varchar(32), 'Null': false, Extra: '' }
|
- { Field: metric, Type: varchar(64), 'Null': false, Extra: '' }
|
||||||
- { Field: value, Type: double, 'Null': true, Extra: '' }
|
- { Field: value, Type: double, 'Null': true, Extra: '' }
|
||||||
- { Field: value_prev, Type: double, 'Null': true, Extra: '' }
|
- { Field: value_prev, Type: double, 'Null': true, Extra: '' }
|
||||||
Indexes:
|
Indexes:
|
||||||
|
|||||||
Reference in New Issue
Block a user