mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
* initial work on add the ability to save/fetch app data * update to use get_app_data for ZFS * update the poller for the new app_data stuff * ZFS now logs changes to pools * add schema update for app_data stuff * small formatting fix * add a missing \ * now adds a column * sql-schema is no longer used, so remove the file that was added here * misc cleanups * rename the method in database/migrations/2022_07_03_1947_add_app_data.php * hopefully fix the migration bit * add the column to misc/db_schema.yaml * more misc small DB fixes * update the test as the json column uses collat of utf8mb4_bin * revert the last change and try manually setting it to what is expected * remove a extra ; * update suricata as well * correct the instance -> instances in one location to prevent the old instance list from being stomped * remove a extra ; * update fail2ban to use it as well * remove two unused functions as suricata and fail2ban no longer use components * style cleanup * postgres poller updated to use it * update html side of the postgres bits * chronyd now uses app data bits now as well * portactivity now uses it as well * style fix * sort the returned arrays from app_data * correct log message for port activity * collocation change * try re-ordering it * add in the new data column to the tests * remove a extra , * hmm... ->collate('utf8mb4_unicode_ci') is not usable as apparently collate does not exist * change the column type from json to longtext * mv chronyd stuff while I sort out the rest of the tests... damn thing is always buggy * hmm... fix a missing line then likely move stuff back * style fix * add fillable * add the expexcted data for fail2ban json * escape a " I missed * add data for portactivity * add suricata app data * add app data to zfs legacy test * put the moved tests back into place and update zfs-v1 test * add app data for chronyd test * add app data for fail2ban legacy test * update zfs v1 app data * add some notes on application dev work * add Developing/Application-Notes.md to mkdocs.yml * add data column to it * added various suggestions from bennet-esyoil * convert from isset to sizeof * type fix * fully remove the old save app data function and move it into a helper function... the other still needs cleaned up prior to removal * update docs * get_app_data is fully removed now as well * a few style fixes * add $casts * update chronyd test * attempt to fix the data * more doc cleanup and try changing the cast * style fix * revert the changes to the chronyd test * apply a few of murrant's suggestions * document working with ->data as json and non-josn * remove two no-longer used in this PR exceptions * ->data now operates transparently * style fix * update data tests * fix json * test fix * update the app notes to reflect how app data now works * app test fix * app data fix for linux_lsi * json fix * minor doc cleanup * remove duplicate querty and use json_decode instead * style fix * modelize the app poller * use a anon func instead of foreach * test update * style cleanup * style cleanup * another test cleanup * more test cleanup * reverse the test changes and add in some more glue code * revert one of the test changes * another small test fix * Make things use models Left some array access, but those will still work just fine. * missed chronyd and portactivity * rename poll to avoid make it any confusion * Remove extra save and fix timestamp * save any changes made to app->data * nope, that was not it * What are magic methods and how do they work? * fix two typos * update linux_lsi test * change quote type Co-authored-by: Tony Murray <murraytony@gmail.com>
277 lines
15 KiB
PHP
277 lines
15 KiB
PHP
<?php
|
|
/*
|
|
* 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.
|
|
*
|
|
* @package LibreNMS
|
|
* @subpackage nfs-server
|
|
* @link https://www.librenms.org
|
|
* @copyright 2017 LibreNMS
|
|
* @author SvennD <svennd@svennd.be>
|
|
*/
|
|
|
|
use LibreNMS\RRD\RrdDefinition;
|
|
|
|
$name = 'nfs-server';
|
|
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.10.110.102.115.45.115.101.114.118.101.114';
|
|
|
|
$nfsstats = snmp_get($device, $oid, '-Oqv');
|
|
|
|
// rrd names
|
|
$rrd_name = [];
|
|
$rrd_name['default'] = ['app', 'nfs-server-default', $app->app_id];
|
|
$rrd_name['proc2'] = ['app', 'nfs-server-proc2', $app->app_id];
|
|
$rrd_name['proc3'] = ['app', 'nfs-server-proc3', $app->app_id];
|
|
$rrd_name['proc4'] = ['app', 'nfs-server-proc4', $app->app_id];
|
|
$rrd_name['proc4ops'] = ['app', 'nfs-server-proc4ops', $app->app_id];
|
|
|
|
// rrd definitions
|
|
$rrd_def_array['default'] = RrdDefinition::make()
|
|
->addDataset('rc_hits', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rc_misses', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rc_nocache', 'COUNTER', 0, 125000000000)
|
|
->addDataset('fh_lookup', 'COUNTER', 0, 125000000000)
|
|
->addDataset('fh_anon', 'COUNTER', 0, 125000000000)
|
|
->addDataset('fh_ncachedir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('fh_ncachenondir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('fh_stale', 'COUNTER', 0, 125000000000)
|
|
->addDataset('io_read', 'COUNTER', 0, 125000000000)
|
|
->addDataset('io_write', 'COUNTER', 0, 125000000000)
|
|
->addDataset('th_threads', 'COUNTER', 0, 125000000000)
|
|
->addDataset('th_fullcnt', 'COUNTER', 0, 125000000000)
|
|
->addDataset('th_range01', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range02', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range03', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range04', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range05', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range06', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range07', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range08', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range09', 'GAUGE', 0, 125000000000)
|
|
->addDataset('th_range10', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_cachesize', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range01', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range02', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range03', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range04', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range05', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range06', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range07', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range08', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range09', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_range10', 'GAUGE', 0, 125000000000)
|
|
->addDataset('ra_notfound', 'GAUGE', 0, 125000000000)
|
|
->addDataset('net_cnt', 'COUNTER', 0, 125000000000)
|
|
->addDataset('net_udp', 'COUNTER', 0, 125000000000)
|
|
->addDataset('net_tcp', 'COUNTER', 0, 125000000000)
|
|
->addDataset('net_tcpconn', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rpc_calls', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rpc_badcount', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rpc_badfmt', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rpc_badauth', 'COUNTER', 0, 125000000000)
|
|
->addDataset('rpc_badclnt', 'COUNTER', 0, 125000000000);
|
|
|
|
$rrd_def_array['proc2'] = RrdDefinition::make()
|
|
->addDataset('proc2_null', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_getattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_setattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_root', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_lookup', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_readlink', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_read', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_wrcache', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_write', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_create', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_remove', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_rename', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_link', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_symlink', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_mkdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_rmdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_readdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc2_fsstat', 'COUNTER', 0, 125000000000);
|
|
|
|
$rrd_def_array['proc3'] = RrdDefinition::make()
|
|
->addDataset('proc3_null', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_getattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_setattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_lookup', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_access', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_readlink', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_read', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_write', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_create', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_mkdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_symlink', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_mknod', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_remove', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_rmdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_rename', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_link', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_readdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_readdirplus', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_fsstat', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_fsinfo', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_pathconf', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc3_commit', 'COUNTER', 0, 125000000000);
|
|
|
|
$rrd_def_array['proc4'] = RrdDefinition::make()
|
|
->addDataset('proc4_null', 'COUNTER', 0, 125000000000)
|
|
->addDataset('proc4_compound', 'COUNTER', 0, 125000000000);
|
|
|
|
$rrd_def_array['proc4ops'] = RrdDefinition::make()
|
|
->addDataset('v4_op0-unused', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_op1-unused', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_op2-future', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_access', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_close', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_commit', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_create', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_delegpurge', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_delegreturn', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_getattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_getfh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_link', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_lock', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_lockt', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_locku', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_lookup', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_lookup_root', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_nverify', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_open', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_openattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_open_conf', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_open_dgrd', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_putfh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_putpubfh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_putrootfh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_read', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_readdir', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_readlink', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_remove', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_rename', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_renew', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_restorefh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_savefh', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_secinfo', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_setattr', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_setcltid', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_setcltidconf', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_verify', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_write', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_rellockowner', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_bc_ctl', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_bind_conn', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_exchange_id', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_create_ses', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_destroy_ses', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_free_stateid', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_getdirdeleg', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_getdevinfo', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_getdevlist', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_layoutcommit', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_layoutget', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_layoutreturn', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_secinfononam', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_sequence', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_set_ssv', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_test_stateid', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_want_deleg', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_destroy_clid', 'COUNTER', 0, 125000000000)
|
|
->addDataset('v4_reclaim_comp', 'COUNTER', 0, 125000000000);
|
|
|
|
/* examples output :
|
|
rc 0 87795065 629022724
|
|
fh 0 0 0 0 0
|
|
io 35586909 1515531914
|
|
th 16 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
|
|
ra 32 229333249 0 0 0 0 0 0 0 0 0 4106423
|
|
net 717504610 0 717216613 15750
|
|
rpc 717521317 0 0 0 0
|
|
proc2 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
|
proc3 22 84 185701663 9587314 62436191 114380547 61635 233519348 60991846 8887178 203052 68539 0 5816369 163267 1946736 127750 35510 8641639 1060644 112 56 13833978
|
|
proc4 2 1 404
|
|
proc4ops 59 0 0 0 2 0 0 0 0 0 402 3 0 0 0 0 3 0 0 0 0 0 0 403 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
|
*/
|
|
|
|
$keys_nfs_server = [
|
|
'rc' => ['rc_hits', 'rc_misses', 'rc_nocache'],
|
|
'fh' => ['fh_lookup', 'fh_anon', 'fh_ncachedir', 'fh_ncachenondir', 'fh_stale'],
|
|
'io' => ['io_read', 'io_write'],
|
|
'th' => ['th_threads', 'th_fullcnt', 'th_range01', 'th_range02', 'th_range03', 'th_range04', 'th_range05', 'th_range06', 'th_range07', 'th_range08', 'th_range09', 'th_range10'],
|
|
'ra' => ['ra_cachesize', 'ra_range01', 'ra_range02', 'ra_range03', 'ra_range04', 'ra_range05', 'ra_range06', 'ra_range07', 'ra_range08', 'ra_range09', 'ra_range10', 'ra_notfound'],
|
|
'net' => ['net_cnt', 'net_udp', 'net_tcp', 'net_tcpconn'],
|
|
'rpc' => ['rpc_calls', 'rpc_badcount', 'rpc_badfmt', 'rpc_badauth', 'rpc_badclnt'],
|
|
'proc2' => ['proc2_null', 'proc2_getattr', 'proc2_setattr', 'proc2_root', 'proc2_lookup', 'proc2_readlink', 'proc2_read', 'proc2_wrcache', 'proc2_write', 'proc2_create', 'proc2_remove', 'proc2_rename', 'proc2_link', 'proc2_symlink', 'proc2_mkdir', 'proc2_rmdir', 'proc2_readdir', 'proc2_fsstat'],
|
|
'proc3' => ['proc3_null', 'proc3_getattr', 'proc3_setattr', 'proc3_lookup', 'proc3_access', 'proc3_readlink', 'proc3_read', 'proc3_write', 'proc3_create', 'proc3_mkdir', 'proc3_symlink', 'proc3_mknod', 'proc3_remove', 'proc3_rmdir', 'proc3_rename', 'proc3_link', 'proc3_readdir', 'proc3_readdirplus', 'proc3_fsstat', 'proc3_fsinfo', 'proc3_pathconf', 'proc3_commit'],
|
|
'proc4' => ['proc4_null', 'proc4_compound'],
|
|
'proc4ops' => [
|
|
'v4_op0-unused', 'v4_op1-unused', 'v4_op2-future', 'v4_access', 'v4_close',
|
|
'v4_commit', 'v4_create', 'v4_delegpurge', 'v4_delegreturn', 'v4_getattr', 'v4_getfh',
|
|
'v4_link', 'v4_lock', 'v4_lockt', 'v4_locku', 'v4_lookup', 'v4_lookup_root', 'v4_nverify',
|
|
'v4_open', 'v4_openattr', 'v4_open_conf', 'v4_open_dgrd', 'v4_putfh', 'v4_putpubfh', 'v4_putrootfh',
|
|
'v4_read', 'v4_readdir', 'v4_readlink', 'v4_remove', 'v4_rename', 'v4_renew', 'v4_restorefh', 'v4_savefh',
|
|
'v4_secinfo', 'v4_setattr', 'v4_setcltid', 'v4_setcltidconf', 'v4_verify', 'v4_write', 'v4_rellockowner',
|
|
'v4_bc_ctl', 'v4_bind_conn', 'v4_exchange_id', 'v4_create_ses', 'v4_destroy_ses', 'v4_free_stateid',
|
|
'v4_getdirdeleg', 'v4_getdevinfo', 'v4_getdevlist', 'v4_layoutcommit', 'v4_layoutget', 'v4_layoutreturn',
|
|
'v4_secinfononam', 'v4_sequence', 'v4_set_ssv', 'v4_test_stateid', 'v4_want_deleg', 'v4_destroy_clid',
|
|
'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 = [];
|
|
$metrics = [];
|
|
|
|
foreach ($lines as $line) {
|
|
$line_values = explode(' ', $line);
|
|
$line_id = array_shift($line_values);
|
|
|
|
switch ($line_id) {
|
|
case 'rc':
|
|
case 'fh':
|
|
case 'io':
|
|
case 'th':
|
|
case 'ra':
|
|
case 'net':
|
|
case 'rpc':
|
|
// combine keys + values, and then merge it in $fields array
|
|
$default_fields = array_merge($default_fields, array_combine($keys_nfs_server[$line_id], $line_values));
|
|
break;
|
|
case 'proc2':
|
|
case 'proc3':
|
|
case 'proc4':
|
|
case 'proc4ops':
|
|
// 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 = ['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 = ['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);
|