mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: Update all applications to store metrics (#7853)
* Update all applications to store metrics * fix db schema * Add glue test
This commit is contained in:
committed by
Neil Lathwood
parent
0dd3ec25d3
commit
b620692426
+7
-3
@@ -1372,12 +1372,16 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
|
||||
foreach ($tables as $table) {
|
||||
if ($table == 'state_translations' && ($target == 'device_id' || $target == 'sensor_id')) {
|
||||
// workaround for state_translations
|
||||
$st_tables = array(
|
||||
return array_merge($last, array(
|
||||
'state_translations.state_index_id',
|
||||
'sensors_to_state_indexes.sensor_id',
|
||||
"sensors.$target",
|
||||
);
|
||||
return array_merge($last, $st_tables);
|
||||
));
|
||||
} elseif ($table == 'application_metrics' && $target = 'device_id') {
|
||||
return array_merge($last, array(
|
||||
'application_metrics.app_id',
|
||||
"applications.$target",
|
||||
));
|
||||
}
|
||||
|
||||
$glues = dbFetchRows('SELECT COLUMN_NAME FROM information_schema.COLUMNS WHERE TABLE_NAME = ? && COLUMN_NAME LIKE "%\_id"', array($table));
|
||||
|
||||
@@ -11,7 +11,6 @@ if (!empty($agent_data['app'][$name])) {
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.6.97.112.97.99.104.101';
|
||||
$apache = snmp_get($device, $oid, $options);
|
||||
update_application($app, $apache);
|
||||
}
|
||||
|
||||
echo ' apache';
|
||||
@@ -69,3 +68,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $apache, $fields);
|
||||
|
||||
@@ -15,7 +15,6 @@ if (!empty($agent_data['app'][$name])) {
|
||||
$oid = 'nsExtendOutputFull.4.98.105.110.100';
|
||||
$bind = snmp_get($device, $oid, $options, $mib);
|
||||
}
|
||||
update_application($app, $bind);
|
||||
|
||||
list ($incoming, $outgoing, $server, $resolver, $cache, $rrsets, $adb, $sockets) = explode("\n", $bind);
|
||||
|
||||
@@ -26,6 +25,7 @@ list ($a, $aaaa, $afsdb, $apl, $caa, $cdnskey, $cds, $cert, $cname, $dhcid, $dlv
|
||||
$loc, $mx, $naptr, $ns, $nsec, $nsec3, $nsec3param, $ptr, $rrsig, $rp, $sig, $soa, $srv, $sshfp, $ta, $tkey, $tlsa,
|
||||
$tsig, $txt, $uri, $dname, $any, $axfr, $ixfr, $opt, $spf) = explode(',', $incoming);
|
||||
|
||||
$metrics = array();
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('any', 'DERIVE', 0)
|
||||
@@ -51,6 +51,7 @@ $fields = array(
|
||||
'srv' => $srv,
|
||||
'spf' => $spf,
|
||||
);
|
||||
$metrics['queries'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -124,6 +125,7 @@ $fields = array(
|
||||
'ixfr' => $ixfr,
|
||||
'opt' => $opt,
|
||||
);
|
||||
$metrics['incoming'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -224,6 +226,7 @@ $fields = array(
|
||||
'ixfr' => $ixfr,
|
||||
'opt' => $opt,
|
||||
);
|
||||
$metrics['outgoing'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -283,6 +286,7 @@ $fields = array(
|
||||
'oeor' => $oeor,
|
||||
'qd' => $qd,
|
||||
);
|
||||
$metrics['server'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -348,6 +352,7 @@ $fields = array(
|
||||
'bs' => $bs,
|
||||
'rr' => $rr,
|
||||
);
|
||||
$metrics['resolver'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -391,6 +396,7 @@ $fields = array(
|
||||
'chmiu' => $chmiu,
|
||||
'chhmiu' => $chhmiu,
|
||||
);
|
||||
$metrics['cache'] = $fields;
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -413,6 +419,7 @@ $fields = array(
|
||||
'nhts' => $nhts,
|
||||
'niht' => $niht
|
||||
);
|
||||
$metrics['adb'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -502,6 +509,7 @@ $fields = array(
|
||||
'ti6sa' => $ti6sa,
|
||||
'rsa' => $ti6sa,
|
||||
);
|
||||
$metrics['sockets'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -610,6 +618,7 @@ $fields = array(
|
||||
'ixfr' => $ixfr,
|
||||
'opt' => $opt,
|
||||
);
|
||||
$metrics['rrpositive'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -662,6 +671,8 @@ $fields = array(
|
||||
'ixfr' => $notixfr,
|
||||
'opt' => $notopt,
|
||||
);
|
||||
$metrics['rrnegative'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $bind, $metrics);
|
||||
|
||||
@@ -4,15 +4,16 @@ use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
$name = 'ceph';
|
||||
if (!empty($agent_data['app'][$name])) {
|
||||
$ceph_data = $agent_data['app'][$name];
|
||||
$app_id = $app['app_id'];
|
||||
|
||||
foreach (explode('<', $agent_data['app'][$name]) as $section) {
|
||||
$metrics = array();
|
||||
foreach (explode('<', $ceph_data) as $section) {
|
||||
if (empty($section)) {
|
||||
continue;
|
||||
}
|
||||
list($section, $data) = explode('>', $section);
|
||||
|
||||
update_application($app, $section);
|
||||
if ($section == "poolstats") {
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('ops', 'GAUGE', 0)
|
||||
@@ -32,6 +33,7 @@ if (!empty($agent_data['app'][$name])) {
|
||||
'wrbytes' => $wrbytes,
|
||||
'rbytes' => $rbytes
|
||||
);
|
||||
$metrics["pool_$pool"] = $fields;
|
||||
$tags = compact('name', 'app_id', 'pool', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
@@ -52,6 +54,7 @@ if (!empty($agent_data['app'][$name])) {
|
||||
'apply_ms' => $apply,
|
||||
'commit_ms' => $commit
|
||||
);
|
||||
$metrics["osd_$osd"] = $fields;
|
||||
$tags = compact('name', 'app_id', 'osd', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
@@ -68,16 +71,19 @@ if (!empty($agent_data['app'][$name])) {
|
||||
list($df,$avail,$used,$objects) = explode(':', $line);
|
||||
$rrd_name = array('app', $name, $app_id, 'df', $df);
|
||||
|
||||
print "Ceph Pool DF: $pool, Avail: $avail, Used: $used, Objects: $objects\n";
|
||||
print "Ceph Pool DF: $df, Avail: $avail, Used: $used, Objects: $objects\n";
|
||||
$fields = array(
|
||||
'avail' => $avail,
|
||||
'used' => $used,
|
||||
'objects' => $objects
|
||||
);
|
||||
|
||||
$metrics["df_$df"] = $fields;
|
||||
$tags = compact('name', 'app_id', 'df', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
}
|
||||
}
|
||||
update_application($app, $ceph_data, $metrics);
|
||||
}
|
||||
|
||||
unset($ceph_data, $metrics);
|
||||
|
||||
@@ -9,7 +9,6 @@ $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);
|
||||
update_application($app, $dhcpstats);
|
||||
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);
|
||||
@@ -38,3 +37,4 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $dhcpstats, $fields);
|
||||
|
||||
@@ -5,13 +5,13 @@ use LibreNMS\RRD\RrdDefinition;
|
||||
$name = 'drbd';
|
||||
$app_instance = $app['app_instance'];
|
||||
$app_id = $app['app_id'];
|
||||
foreach (explode('|', $agent_data['app'][$name][$app_instance]) as $part) {
|
||||
$drbd_data = $agent_data['app'][$name][$app_instance];
|
||||
foreach (explode('|', $drbd_data) as $part) {
|
||||
list($stat, $val) = explode('=', $part);
|
||||
if (!empty($stat)) {
|
||||
$drbd[$stat] = $val;
|
||||
}
|
||||
}
|
||||
update_application($app, $agent_data['app'][$name][$app_instance]);
|
||||
|
||||
$rrd_name = array('app', $name, $app_instance);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -44,5 +44,6 @@ $fields = array(
|
||||
|
||||
$tags = array('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $drbd_data, $fields);
|
||||
|
||||
unset($drbd);
|
||||
unset($drbd, $drbd_data);
|
||||
|
||||
@@ -29,8 +29,6 @@ $stats = snmp_get($device, $oid, '-Oqv');
|
||||
|
||||
echo ' '.$name;
|
||||
|
||||
update_application($app, $stats);
|
||||
|
||||
list ($frozen, $queue) = explode("\n", $stats);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
@@ -45,3 +43,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $stats, $fields);
|
||||
|
||||
@@ -11,8 +11,8 @@ $options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.8.102.97.105.108.50.98.97.110';
|
||||
$f2b = snmp_walk($device, $oid, $options);
|
||||
$f2b = trim($f2b, '"');
|
||||
update_application($app, $f2b);
|
||||
|
||||
$metrics = array();
|
||||
$bannedStuff = explode("\n", $f2b);
|
||||
|
||||
$total_banned=$bannedStuff[0];
|
||||
@@ -27,6 +27,7 @@ $fields = array(
|
||||
'banned' =>$total_banned,
|
||||
'firewalled' => $firewalled,
|
||||
);
|
||||
$metrics['total'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -44,6 +45,7 @@ while (isset($bannedStuff[$int])) {
|
||||
$rrd_def = RrdDefinition::make()->addDataset('banned', 'GAUGE', 0);
|
||||
$fields = array('banned' => $banned);
|
||||
|
||||
$metrics["jail_$jail"] = $fields;
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
@@ -51,6 +53,8 @@ while (isset($bannedStuff[$int])) {
|
||||
$int++;
|
||||
}
|
||||
|
||||
update_application($app, $f2b, $metrics);
|
||||
|
||||
//
|
||||
// component processing for fail2ban
|
||||
//
|
||||
|
||||
@@ -7,7 +7,6 @@ use LibreNMS\RRD\RrdDefinition;
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.13.102.98.115.100.110.102.115.99.108.105.101.110.116';
|
||||
$nfsclient = snmp_walk($device, $oid, $options);
|
||||
update_application($app, $nfsclient);
|
||||
|
||||
list($getattr, $setattr, $lookup, $readlink, $read, $write, $create, $remove, $rename, $link, $symlink, $mkdir, $rmdir,
|
||||
$readdir, $rdirplus, $access, $mknod, $fsstat, $fsinfo, $pathconf, $commit, $timedout, $invalid, $xreplies, $retries,
|
||||
@@ -106,3 +105,4 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $nfsclient, $fields);
|
||||
|
||||
@@ -7,7 +7,6 @@ $app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.13.102.98.115.100.110.102.115.115.101.114.118.101.114';
|
||||
$nfsserver = snmp_walk($device, $oid, $options);
|
||||
update_application($app, $nfsserver);
|
||||
|
||||
list($getattr, $setattr, $lookup, $readlink, $read, $write, $create, $remove, $rename, $link, $symlink,
|
||||
$mkdir, $rmdir, $readdir, $rdirplus, $access, $mknod, $fsstat, $fsinfo, $pathconf, $commit, $retfailed,
|
||||
@@ -81,3 +80,4 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $nfsserver, $fields);
|
||||
|
||||
@@ -6,13 +6,11 @@ $name = 'freeswitch';
|
||||
$app_id = $app['app_id'];
|
||||
if (!empty($agent_data[$name])) {
|
||||
$rawdata = $agent_data[$name];
|
||||
update_application($app, $rawdata);
|
||||
} else {
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.10.102.114.101.101.115.119.105.116.99.104';
|
||||
$rawdata = snmp_walk($device, $oid, $options);
|
||||
$rawdata = str_replace("<<<freeswitch>>>\n", '', $rawdata);
|
||||
update_application($app, $rawdata);
|
||||
}
|
||||
# Format Data
|
||||
$lines = explode("\n", $rawdata);
|
||||
@@ -31,15 +29,17 @@ $rrd_def = RrdDefinition::make()
|
||||
->addDataset('in_okay', 'COUNTER', 0, 4294967295)
|
||||
->addDataset('out_failed', 'COUNTER', 0, 4294967295)
|
||||
->addDataset('out_okay', 'COUNTER', 0, 4294967295);
|
||||
$fields = array (
|
||||
'calls' => $freeswitch['Calls'],
|
||||
'channels' => $freeswitch['Channels'],
|
||||
'peak' => $freeswitch['Peak'],
|
||||
$fields = array(
|
||||
'calls' => $freeswitch['Calls'],
|
||||
'channels' => $freeswitch['Channels'],
|
||||
'peak' => $freeswitch['Peak'],
|
||||
'in_failed' => $freeswitch['InFailed'],
|
||||
'in_okay' => $freeswitch['InTotal']-$freeswitch['InFailed'],
|
||||
'in_okay' => $freeswitch['InTotal'] - $freeswitch['InFailed'],
|
||||
'out_failed' => $freeswitch['OutFailed'],
|
||||
'out_okay' => $freeswitch['OutTotal']-$freeswitch['OutFailed']
|
||||
);
|
||||
'out_okay' => $freeswitch['OutTotal'] - $freeswitch['OutFailed']
|
||||
);
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $rawdata, $fields);
|
||||
|
||||
unset($lines, $freeswitch, $rrd_name, $rrd_def, $fields, $tags);
|
||||
|
||||
@@ -32,7 +32,6 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) {
|
||||
echo ' '.$name;
|
||||
$gpsd = $agent_data['app'][$name];
|
||||
$gpsd_parsed = array();
|
||||
update_application($app, $gpsd);
|
||||
|
||||
foreach (explode("\n", $gpsd) as $line) {
|
||||
list ($field, $data) = explode(':', $line);
|
||||
@@ -65,4 +64,5 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) {
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $gpsd, $fields);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ $options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.11.109.97.105.108.115.99.97.110.110.101.114';
|
||||
|
||||
$mailscanner = snmp_get($device, $oid, $options);
|
||||
update_application($app, $mailscanner);
|
||||
|
||||
echo ' mailscanner';
|
||||
|
||||
@@ -38,3 +37,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $mailscanner, $fields);
|
||||
|
||||
@@ -14,7 +14,6 @@ if (!empty($agent_data['app']['memcached'])) {
|
||||
$data = reset($result);
|
||||
}
|
||||
|
||||
update_application($app, $data['pid']);
|
||||
echo ' memcached('.$app['app_instance'].')';
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
@@ -61,3 +60,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $data, $fields);
|
||||
|
||||
@@ -12,8 +12,8 @@ if (!empty($agent_data['app'][$name])) {
|
||||
$mysql = snmp_get($device, '.1.3.6.1.4.1.8072.1.3.2.3.1.2.5.109.121.115.113.108', '-Ovq');
|
||||
}
|
||||
|
||||
update_application($app, $mysql);
|
||||
echo ' mysql';
|
||||
$metrics = array();
|
||||
|
||||
// General Stats
|
||||
$mapping = array(
|
||||
@@ -110,6 +110,7 @@ $fields = array();
|
||||
foreach ($mapping as $k => $v) {
|
||||
$fields[$k] = (isset($map[$v]) && $map[$v] >= 0) ? $map[$v] : 'U';
|
||||
}
|
||||
$metrics = $fields;
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -218,12 +219,14 @@ $mapping_status = array(
|
||||
|
||||
$rrd_name = array('app', $name, $app_id, 'status');
|
||||
$rrd_def = new RrdDefinition();
|
||||
unset($fields);
|
||||
|
||||
$fields = array();
|
||||
foreach ($mapping_status as $desc => $id) {
|
||||
$fields[$desc] = (isset($map[$id]) && $map[$id] >= 0) ? $map[$id] : 'U';
|
||||
$rrd_def->addDataset($id, 'GAUGE', 0, 125000000000);
|
||||
}
|
||||
$metrics += $fields;
|
||||
$status = true;
|
||||
$tags = compact('name', 'app_id', 'status', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $mysql, $metrics);
|
||||
|
||||
@@ -22,8 +22,6 @@ echo ' ' . $name;
|
||||
|
||||
$nfsstats = snmp_get($device, $oid, '-Oqv');
|
||||
|
||||
update_application($app, $nfsstats);
|
||||
|
||||
$app_id = $app['app_id'];
|
||||
|
||||
// rrd names
|
||||
@@ -228,16 +226,17 @@ $keys_nfs_server = array(
|
||||
'v4_reclaim_comp')
|
||||
);
|
||||
|
||||
|
||||
|
||||
// parse each output line, by the id
|
||||
// then 'map' the values to the arrays from $keys_nfs_server
|
||||
$lines = explode("\n", $nfsstats);
|
||||
$default_fields = array();
|
||||
$metrics = array();
|
||||
|
||||
foreach ($lines as $line) {
|
||||
$line_values = explode(" ", $line);
|
||||
$line_id = array_shift($line_values);
|
||||
|
||||
|
||||
switch ($line_id) {
|
||||
case 'rc':
|
||||
case 'fh':
|
||||
@@ -256,26 +255,29 @@ foreach ($lines as $line) {
|
||||
// note : proc2 is dropped for kernels 3.10.0+ (centos 7+)
|
||||
// note : proc4ops has changed a few times, and getting the keys is difficult
|
||||
// I only use the version which reports 59 value's (centos 6)
|
||||
|
||||
|
||||
// the first value of the proc* is the amount of fields that will follow;
|
||||
// we check this, and if its incorrect, do not polute the chart with wrong values
|
||||
$value_count = array_shift($line_values);
|
||||
|
||||
if ($value_count == count($keys_nfs_server[$line_id])) {
|
||||
$fields = array_combine($keys_nfs_server[$line_id], $line_values);
|
||||
|
||||
|
||||
// create or push data to rrd
|
||||
$tags = array('name' => $name, 'app_id' => $app['app_id'], 'rrd_name' => $rrd_name[$line_id], 'rrd_def' => $rrd_def_array[$line_id]);
|
||||
|
||||
$metrics[$line_id] = $fields;
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$metrics['none'] = $default_fields;
|
||||
|
||||
// push the default nfs server data to rrd
|
||||
$tags = array('name' => $name, 'app_id' => $app['app_id'], 'rrd_name' => $rrd_name['default'], 'rrd_def' => $rrd_def_array['default']);
|
||||
data_update($device, 'app', $tags, $default_fields);
|
||||
update_application($app, $nfsstats, $metrics);
|
||||
|
||||
|
||||
// clean up scope
|
||||
unset($nfsstats, $rrd_name, $rrd_def_array, $default_fields, $fields, $tags);
|
||||
|
||||
@@ -9,7 +9,6 @@ $oid = '.1.3.6.1.4.1.8072.1.3.2.4';
|
||||
echo ' ' . $name;
|
||||
|
||||
$nfsstats = snmp_walk($device, $oid, '-Oqv', 'NET-SNMP-EXTEND-MIB');
|
||||
update_application($app, $nfsstats);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -50,5 +49,6 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $nfsstats, $fields);
|
||||
|
||||
unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags);
|
||||
|
||||
@@ -9,7 +9,6 @@ $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.110.102.115.115.116.97.116';
|
||||
echo ' ' . $name;
|
||||
|
||||
$nfsstats = snmp_walk($device, $oid, '-Oqv', 'NET-SNMP-EXTEND-MIB');
|
||||
update_application($app, $nfsstats);
|
||||
|
||||
$rrd_name = array('app', 'nfs-stats', $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -126,5 +125,6 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $nfsstats, $fields);
|
||||
|
||||
unset($nfsstats, $rrd_name, $rrd_def, $data, $fields, $tags);
|
||||
|
||||
@@ -35,7 +35,7 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $nginx, '', $fields);
|
||||
update_application($app, $nginx, $fields);
|
||||
|
||||
// Unset the variables we set here
|
||||
unset($nginx, $active, $reading, $writing, $waiting, $req, $rrd_name, $rrd_def, $tags);
|
||||
|
||||
@@ -8,7 +8,6 @@ $app_id = $app['app_id'];
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.110.116.112.45.99.108.105.101.110.116';
|
||||
$ntpclient = snmp_get($device, $oid, '-Oqv');
|
||||
$ntpclient = str_replace('"', '', $ntpclient);
|
||||
update_application($app, $ntpclient);
|
||||
|
||||
echo ' '.$name;
|
||||
|
||||
@@ -32,3 +31,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $ntpclient, $fields);
|
||||
|
||||
@@ -8,7 +8,6 @@ $app_id = $app['app_id'];
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.110.116.112.45.115.101.114.118.101.114';
|
||||
$ntpserver_data = snmp_get($device, $oid, '-Oqv');
|
||||
$ntpserver_data = str_replace('"', '', $ntpserver_data);
|
||||
update_application($app, $ntpserver_data);
|
||||
list ($stratum, $offset, $frequency, $jitter, $noise, $stability, $uptime, $buffer_recv, $buffer_free, $buffer_used, $packets_drop, $packets_ignore, $packets_recv, $packets_sent) = explode("\n", $ntpserver_data);
|
||||
|
||||
echo ' '.$name;
|
||||
@@ -51,3 +50,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $ntpserver_data, $fields);
|
||||
|
||||
@@ -30,6 +30,8 @@ $rrd_def = RrdDefinition::make()
|
||||
->addDataset('rxpci', 'GAUGE', 0)
|
||||
->addDataset('txpci', 'GAUGE', 0);
|
||||
|
||||
$sm_total = 0;
|
||||
$metrics = array();
|
||||
foreach ($gpuArray as $index => $gpu) {
|
||||
$stats = explode(",", $gpu);
|
||||
$sm_total += $stats[3];
|
||||
@@ -58,10 +60,11 @@ foreach ($gpuArray as $index => $gpu) {
|
||||
'rxpci' => $rxpci,
|
||||
'txpci' => $txpci
|
||||
);
|
||||
$metrics[$index] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
$sm_average = ($sm_total ? ($sm_total / count($gpuArray)) : 0);
|
||||
|
||||
update_application($app, $gpus, $sm_average);
|
||||
update_application($app, $gpus, $metrics, $sm_average);
|
||||
|
||||
@@ -24,9 +24,6 @@ echo ' ' . $name;
|
||||
// get data through snmp
|
||||
$ogs_data = snmp_get($device, $oid, '-Oqv');
|
||||
|
||||
// let librenms know that we got good data
|
||||
update_application($app, $ogs_data);
|
||||
|
||||
// define the rrd
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -47,6 +44,8 @@ $fields = array(
|
||||
// push the data in an array and into the rrd
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $ogs_data, $fields);
|
||||
|
||||
|
||||
// cleanup
|
||||
unset($ogs_data, $rrd_name, $rrd_def, $data, $fields, $tags);
|
||||
|
||||
@@ -11,9 +11,9 @@ $rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()->addDataset('packages', 'GAUGE', 0);
|
||||
|
||||
$osupdates = snmp_get($device, $oid, $options, $mib);
|
||||
update_application($app, $osupdates, $osupdates);
|
||||
|
||||
$fields = array('packages' => $osupdates,);
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $osupdates, $fields, $osupdates);
|
||||
|
||||
@@ -8,7 +8,6 @@ $app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.8.112.104.112.102.112.109.115.112';
|
||||
$phpfpm = snmp_walk($device, $oid, $options);
|
||||
update_application($app, $phpfpm);
|
||||
|
||||
list($pool,$start_time,$start_since,$accepted_conn,$listen_queue,$max_listen_queue,$listen_queue_len,$idle_processes,
|
||||
$active_processes,$total_processes,$max_active_processes,$max_children_reached,$slow_requests) = explode("\n", $phpfpm);
|
||||
@@ -37,3 +36,4 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $phpfpm, $fields);
|
||||
|
||||
@@ -23,7 +23,6 @@ $oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.112.105.45.104.111.108.101';
|
||||
$pihole = snmp_walk($device, $oid, $options);
|
||||
|
||||
if ($pihole) {
|
||||
update_application($app, $pihole);
|
||||
list($domains_blocked, $dns_query, $ads_blocked, $ads_percentage, $unique_domains, $queries_forwarded, $queries_cached, $query_a, $query_aaaa, $query_ptr, $query_srv) = explode("\n", $pihole);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
@@ -56,6 +55,7 @@ if ($pihole) {
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $pihole, $fields);
|
||||
}
|
||||
|
||||
unset($pihole);
|
||||
|
||||
@@ -9,7 +9,6 @@ $queueOID = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.5.109.97.105.108.113';
|
||||
$detailOID = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.15.112.111.115.116.102.105.120.100.101.116.97.105.108.101.100';
|
||||
$mailq = snmp_walk($device, $queueOID, $options);
|
||||
$detail= snmp_walk($device, $detailOID, $options);
|
||||
update_application($app, $mailq);
|
||||
|
||||
list($incomingq, $activeq, $deferredq, $holdq) = explode("\n", $mailq);
|
||||
|
||||
@@ -95,3 +94,4 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $mailq, $fields);
|
||||
|
||||
@@ -9,12 +9,12 @@ echo "postgres";
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.8.112.111.115.116.103.114.101.115';
|
||||
$postgres = snmp_walk($device, $oid, $options);
|
||||
update_application($app, $postgres);
|
||||
|
||||
list($backends, $commits, $rollbacks, $read, $hit, $idxscan, $idxtupread, $idxtupfetch, $idxblksread,
|
||||
$idxblkshit, $seqscan, $seqtupread, $ret, $fetch, $ins, $upd, $del) = explode("\n", $postgres);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$metrics = array();
|
||||
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('backends', 'GAUGE', 0)
|
||||
@@ -54,6 +54,7 @@ $fields = array(
|
||||
'upd' => $upd,
|
||||
'del' => $del
|
||||
);
|
||||
$metrics['none'] = $fields;
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
@@ -91,11 +92,13 @@ while (isset($db_lines[$db_lines_int])) {
|
||||
'del' => $del
|
||||
);
|
||||
|
||||
$metrics[$dbname] = $fields;
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
$db_lines_int++;
|
||||
}
|
||||
update_application($app, $postgres, $metrics);
|
||||
|
||||
//
|
||||
// component processing for postgres
|
||||
|
||||
@@ -57,7 +57,6 @@ if ($agent_data['app'][$name]) {
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
update_application($app, $data);
|
||||
$ds_list = array(
|
||||
'all-outqueries' => 'DERIVE',
|
||||
'answers-slow' => 'DERIVE',
|
||||
@@ -142,6 +141,7 @@ if (!empty($data)) {
|
||||
$rrd_name = array('app', 'powerdns', 'recursor', $app_id);
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $data, $fields);
|
||||
}
|
||||
|
||||
unset($data, $stats, $rrd_def, $rrd_name, $rrd_keys, $tags, $fields);
|
||||
|
||||
@@ -15,7 +15,6 @@ if ($agent_data['app'][$name]) {
|
||||
$powerdns = snmp_get($device, $oid, $options);
|
||||
$powerdns = trim($powerdns, '"');
|
||||
}
|
||||
update_application($app, $powerdns);
|
||||
|
||||
echo ' powerdns';
|
||||
|
||||
@@ -77,3 +76,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $powerdns, $fields);
|
||||
|
||||
@@ -53,7 +53,6 @@ if (isset($config['enable_proxmox']) && $config['enable_proxmox'] && !empty($age
|
||||
}
|
||||
|
||||
if ($proxmox) {
|
||||
update_application($app, $proxmox);
|
||||
$pmxlines = explode("\n", $proxmox);
|
||||
$pmxcluster = array_shift($pmxlines);
|
||||
dbUpdate(
|
||||
@@ -63,6 +62,7 @@ if ($proxmox) {
|
||||
array($device['device_id'], $name)
|
||||
);
|
||||
|
||||
$metrics = array();
|
||||
if (count($pmxlines) > 0) {
|
||||
$pmxcache = array();
|
||||
|
||||
@@ -84,6 +84,8 @@ if ($proxmox) {
|
||||
'OUTOCTETS' => $vmpout
|
||||
);
|
||||
|
||||
$proxmox_metric_prefix = "pmxcluster{$pmxcluster}_vmid{$vmid}_vmport$vmport";
|
||||
$metrics[$proxmox_metric_prefix] = $fields;
|
||||
$tags = compact('name', 'app_id', 'pmxcluster', 'vmid', 'vmport', 'rrd_proxmox_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
@@ -114,6 +116,8 @@ if ($proxmox) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
update_application($app, $proxmox, $metrics);
|
||||
}
|
||||
|
||||
unset($pmxlines, $pmxcluster, $pmxcdir, $proxmox, $pmxcache);
|
||||
|
||||
@@ -70,8 +70,6 @@ if ($agent_data['app'][$name]) {
|
||||
}
|
||||
}
|
||||
|
||||
update_application($app, $data);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('queue_length', 'GAUGE', 0)
|
||||
@@ -95,5 +93,6 @@ foreach (explode("\n", $data) as $line) {
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $data, $fields);
|
||||
|
||||
unset($data, $rrd_name, $rrd_def, $fields, $tags);
|
||||
|
||||
@@ -31,7 +31,6 @@ d_echo($name);
|
||||
$sdfsinfo = snmp_walk($device, $oid, $options);
|
||||
|
||||
if (is_string($sdfsinfo)) {
|
||||
update_application($app, $sdfsinfo);
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -65,5 +64,7 @@ if (is_string($sdfsinfo)) {
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $sdfsinfo, $fields);
|
||||
|
||||
unset($sdfsinfo, $rrd_name, $rrd_def, $data, $fields, $tags);
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ $app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.9.115.104.111.117.116.99.97.115.116';
|
||||
$shoutcast = snmp_get($device, $oid, $options);
|
||||
update_application($app, $shoutcast);
|
||||
|
||||
echo ' shoutcast';
|
||||
|
||||
$servers = explode("\n", $shoutcast);
|
||||
|
||||
$metrics = array();
|
||||
foreach ($servers as $item => $server) {
|
||||
$server = trim($server);
|
||||
|
||||
@@ -44,8 +44,11 @@ foreach ($servers as $item => $server) {
|
||||
'max' => $data['7'],
|
||||
'unique' => $data['8'],
|
||||
);
|
||||
$metrics[$server] = $fields;
|
||||
|
||||
$tags = compact('name', 'app_id', 'host', 'port', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
update_application($app, $shoutcast, $metrics);
|
||||
|
||||
@@ -10,7 +10,6 @@ $app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.5.115.109.97.114.116';
|
||||
$output = snmp_walk($device, $oid, $options);
|
||||
update_application($app, $output);
|
||||
|
||||
$lines = explode("\n", $output);
|
||||
|
||||
@@ -42,6 +41,7 @@ $rrd_def = RrdDefinition::make()
|
||||
->addDataset('selective', 'GAUGE', 0);
|
||||
|
||||
$int=0;
|
||||
$metrics = array();
|
||||
while (isset($lines[$int])) {
|
||||
list($disk, $id5, $id10, $id173, $id177, $id183, $id184, $id187, $id188, $id190, $id194,
|
||||
$id196, $id197, $id198, $id199, $id231, $id233, $completed, $interrupted, $read_failure,
|
||||
@@ -125,8 +125,10 @@ while (isset($lines[$int])) {
|
||||
'selective'=>$selective
|
||||
);
|
||||
|
||||
$metrics[$disk] = $metrics;
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
$int++;
|
||||
}
|
||||
update_application($app, $output, $metrics);
|
||||
|
||||
@@ -46,9 +46,6 @@ $oids=array(
|
||||
'.1.3.6.1.4.1.3495.1.3.2.2.1.10.60'
|
||||
);
|
||||
$returnedoids=snmp_get_multi_oid($device, $oids);
|
||||
if (is_array($returnedoids)) {
|
||||
update_application($app, 'Data ok');
|
||||
}
|
||||
|
||||
$memmaxsize = $returnedoids['.1.3.6.1.4.1.3495.1.2.5.1.0'];
|
||||
$swapmaxsize = $returnedoids['.1.3.6.1.4.1.3495.1.2.5.2.0'];
|
||||
@@ -177,3 +174,6 @@ $fields = array(
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
|
||||
$response = ($returnedoids == false) ? false : 'Data ok';
|
||||
update_application($app, $response, $fields);
|
||||
|
||||
@@ -29,7 +29,6 @@ use LibreNMS\RRD\RrdDefinition;
|
||||
$name = 'tinydns';
|
||||
$app_id = $app['app_id'];
|
||||
if (!empty($agent_data['app'][$name]) && $app_id > 0) {
|
||||
update_application($app, $name);
|
||||
echo ' tinydns';
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
@@ -54,6 +53,35 @@ if (!empty($agent_data['app'][$name]) && $app_id > 0) {
|
||||
->addDataset('badclass', 'COUNTER', 0, 125000000000)
|
||||
->addDataset('noquery', 'COUNTER', 0, 125000000000);
|
||||
|
||||
list(
|
||||
$a, $ns, $cname, $soa, $ptr, $hinfo, $mx, $txt, $rp, $sig, $key, $aaaa, $axfr, $any,
|
||||
$total, $other, $notauth, $notimpl, $badclass, $noquery
|
||||
) = explode(':', $agent_data['app'][$name]);
|
||||
|
||||
$fields = array(
|
||||
'a' => $a,
|
||||
'ns' => $ns,
|
||||
'cname' => $cname,
|
||||
'soa' => $soa,
|
||||
'ptr' => $ptr,
|
||||
'hinfo' => $hinfo,
|
||||
'mx' => $mx,
|
||||
'txt' => $txt,
|
||||
'rp' => $rp,
|
||||
'sig' => $sig,
|
||||
'key' => $key,
|
||||
'aaaa' => $aaaa,
|
||||
'axfr' => $axfr,
|
||||
'any' => $any,
|
||||
'total' => $total,
|
||||
'other' => $other,
|
||||
'notauth' => $notauth,
|
||||
'notimpl' => $notimpl,
|
||||
'badclass' => $badclass,
|
||||
'noquery' => $noquery
|
||||
);
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $name, $fields);
|
||||
}//end if
|
||||
|
||||
@@ -6,7 +6,6 @@ $name = 'unbound';
|
||||
$app_id = $app['app_id'];
|
||||
if (!empty($agent_data['app'][$name])) {
|
||||
$rawdata = $agent_data['app'][$name];
|
||||
update_application($app, $rawdata);
|
||||
} else {
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.7.117.110.98.111.117.110.100';
|
||||
@@ -15,6 +14,7 @@ if (!empty($agent_data['app'][$name])) {
|
||||
#Format Data
|
||||
$lines = explode("\n", $rawdata);
|
||||
$unbound = array();
|
||||
$metrics = array();
|
||||
foreach ($lines as $line) {
|
||||
list($var,$value) = explode('=', $line);
|
||||
$unbound[$var] = $value;
|
||||
@@ -60,6 +60,7 @@ $fields = array (
|
||||
'any' => $unbound['num.query.type.ANY'],
|
||||
'other' => $unbound['num.query.type.other']
|
||||
);
|
||||
$metrics['queries'] = $fields;
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
#Unbound Cache
|
||||
@@ -73,7 +74,9 @@ $fields = array (
|
||||
'hits' => $unbound['total.num.cachehits'],
|
||||
'misses' => $unbound['total.num.cachemiss']
|
||||
);
|
||||
$metrics['cache'] = $fields;
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $rawdata, $metrics);
|
||||
|
||||
unset($lines, $unbound, $rrd_name, $rrd_def, $fields, $tags);
|
||||
|
||||
@@ -26,7 +26,6 @@ $name = 'ups-apcups';
|
||||
$app_id = $app['app_id'];
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.117.112.115.45.97.112.99.117.112.115';
|
||||
$ups_apcups = trim(snmp_get($device, $oid, '-Oqv'), '"');
|
||||
update_application($app, $ups_apcups);
|
||||
|
||||
echo ' '.$name;
|
||||
|
||||
@@ -54,3 +53,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $ups_apcups, $fields);
|
||||
|
||||
@@ -30,7 +30,6 @@ $name = 'ups-nut';
|
||||
$app_id = $app['app_id'];
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.7.117.112.115.45.110.117.116';
|
||||
$ups_nut = snmp_get($device, $oid, '-Oqv');
|
||||
update_application($app, $ups_nut);
|
||||
|
||||
// If "extend" (used above) fails, try "exec" support.
|
||||
// Note, exec always splits outputs on newline, so need to use snmp_walk (not a single SNMP entry!)
|
||||
@@ -70,3 +69,4 @@ $fields = array(
|
||||
|
||||
$tags = compact('name', 'app_id', 'rrd_name', 'rrd_def');
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
update_application($app, $ups_nut, $fields);
|
||||
|
||||
@@ -576,12 +576,17 @@ function location_to_latlng($device)
|
||||
/**
|
||||
* Update the application status and output in the database.
|
||||
*
|
||||
* Metric values should have key for of the matching name.
|
||||
* If you have multiple groups of metrics, you can group them with multiple sub arrays
|
||||
* The group name (key) will be prepended to each metric in that group, separated by an underscore
|
||||
* The special group "none" will not be prefixed.
|
||||
*
|
||||
* @param array $app app from the db, including app_id
|
||||
* @param string $response This should be the full output
|
||||
* @param string $status This is the current value for alerting
|
||||
* @param array $metrics an array of additional metrics to store in the database for alerting
|
||||
* @param string $status This is the current value for alerting
|
||||
*/
|
||||
function update_application($app, $response, $status = '', $metrics = array())
|
||||
function update_application($app, $response, $metrics = array(), $status = '')
|
||||
{
|
||||
if (!is_numeric($app['app_id'])) {
|
||||
d_echo('$app does not contain app_id, could not update');
|
||||
@@ -614,6 +619,26 @@ function update_application($app, $response, $status = '', $metrics = array())
|
||||
$db_metrics = dbFetchRows('SELECT * FROM `application_metrics` WHERE app_id=?', array($app['app_id']));
|
||||
$db_metrics = array_by_column($db_metrics, 'metric');
|
||||
|
||||
// allow two level metrics arrays, flatten them and prepend the group name
|
||||
if (is_array(current($metrics))) {
|
||||
$metrics = array_reduce(
|
||||
array_keys($metrics),
|
||||
function ($carry, $metric_group) use ($metrics) {
|
||||
if ($metric_group == 'none') {
|
||||
$prefix = '';
|
||||
} else {
|
||||
$prefix = $metric_group . '_';
|
||||
}
|
||||
|
||||
foreach ($metrics[$metric_group] as $metric_name => $value) {
|
||||
$carry[$prefix . $metric_name] = $value;
|
||||
}
|
||||
return $carry;
|
||||
},
|
||||
array()
|
||||
);
|
||||
}
|
||||
|
||||
echo ': ';
|
||||
foreach ($metrics as $metric_name => $value) {
|
||||
if (!isset($db_metrics[$metric_name])) {
|
||||
@@ -622,15 +647,15 @@ function update_application($app, $response, $status = '', $metrics = array())
|
||||
array(
|
||||
'app_id' => $app['app_id'],
|
||||
'metric' => $metric_name,
|
||||
'value' => $value,
|
||||
'value' => (int)$value,
|
||||
),
|
||||
'application_metrics'
|
||||
);
|
||||
echo '+';
|
||||
} elseif ($value != $db_metrics[$metric_name]['value']) {
|
||||
} elseif ((int)$value != (int)$db_metrics[$metric_name]['value']) {
|
||||
dbUpdate(
|
||||
array(
|
||||
'value' => $value,
|
||||
'value' => (int)$value,
|
||||
'value_prev' => $db_metrics[$metric_name]['value'],
|
||||
),
|
||||
'application_metrics',
|
||||
@@ -654,6 +679,8 @@ function update_application($app, $response, $status = '', $metrics = array())
|
||||
);
|
||||
echo '-';
|
||||
}
|
||||
|
||||
echo PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@ applications:
|
||||
application_metrics:
|
||||
Columns:
|
||||
- { Field: app_id, Type: int(11), 'Null': false, Extra: '' }
|
||||
- { Field: metric, Type: varchar(18), 'Null': false, Extra: '' }
|
||||
- { Field: metric, Type: varchar(32), 'Null': false, Extra: '' }
|
||||
- { Field: value, Type: int(11), 'Null': true, Extra: '' }
|
||||
- { Field: value_prev, Type: int(11), 'Null': true, Extra: '' }
|
||||
Indexes:
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
ALTER TABLE `application_metrics` CHANGE `metric` `metric` varchar(32) NOT NULL;
|
||||
@@ -166,6 +166,10 @@ class CommonFunctionsTest extends \PHPUnit_Framework_TestCase
|
||||
// $expected = array('bill_data.bill_id', 'bill_ports.port_id', 'ports.device_id');
|
||||
// $this->assertSame($expected, ResolveGlues(array('bill_data'), 'device_id'));
|
||||
|
||||
$expected = array('application_metrics.app_id', "applications.device_id");
|
||||
$this->assertSame($expected, ResolveGlues(array('application_metrics'), 'device_id'));
|
||||
|
||||
|
||||
$expected = array('state_translations.state_index_id', 'sensors_to_state_indexes.sensor_id', 'sensors.device_id');
|
||||
$this->assertSame($expected, ResolveGlues(array('state_translations'), 'device_id'));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user