diff --git a/LibreNMS/Data/Store/InfluxDBv2.php b/LibreNMS/Data/Store/InfluxDBv2.php index f59859be84..2ee0e8af8c 100644 --- a/LibreNMS/Data/Store/InfluxDBv2.php +++ b/LibreNMS/Data/Store/InfluxDBv2.php @@ -26,6 +26,7 @@ namespace LibreNMS\Data\Store; +use App\Facades\DeviceCache; use App\Polling\Measure\Measurement; use InfluxDB2\Client; use InfluxDB2\Model\WritePrecision; @@ -62,6 +63,21 @@ class InfluxDBv2 extends BaseDatastore */ public function put($device, $measurement, $tags, $fields) { + $device_data = DeviceCache::get($device['device_id']); + $excluded_groups = Config::get('influxdbv2.groups-exclude'); + + if (! empty($excluded_groups)) { + $device_groups = $device_data->groups; + foreach ($device_groups as $group) { + // The group name will always be parsed as lowercase, even when uppercase in the GUI. + if (in_array(strtoupper($group->name), array_map('strtoupper', $excluded_groups))) { + Log::warning('Skipped parsing to InfluxDBv2, device is in group: ' . $group->name); + + return; + } + } + } + $stat = Measurement::start('write'); $tmp_fields = []; $tmp_tags['hostname'] = $device['hostname']; @@ -87,11 +103,13 @@ class InfluxDBv2 extends BaseDatastore return; } - Log::debug('InfluxDB data: ', [ - 'measurement' => $measurement, - 'tags' => $tmp_tags, - 'fields' => $tmp_fields, - ]); + if (Config::get('influxdbv2.debug') === true) { + Log::debug('InfluxDB data: ', [ + 'measurement' => $measurement, + 'tags' => $tmp_tags, + 'fields' => $tmp_fields, + ]); + } // Get a WriteApi instance from the client $client = self::createFromConfig(); @@ -133,7 +151,7 @@ class InfluxDBv2 extends BaseDatastore $organization = Config::get('influxdbv2.organization', ''); $allow_redirects = Config::get('influxdbv2.allow_redirects', true); $token = Config::get('influxdbv2.token', ''); - + $debug = Config::get('influxdbv2.debug', false); $client = new Client([ 'url' => $transport . '://' . $host . ':' . $port, 'token' => $token, @@ -141,7 +159,7 @@ class InfluxDBv2 extends BaseDatastore 'org' => $organization, 'precision' => WritePrecision::S, 'allow_redirects' => $allow_redirects, - 'debug' => true, + 'debug' => $debug, ]); return $client; diff --git a/doc/Extensions/metrics/InfluxDBv2.md b/doc/Extensions/metrics/InfluxDBv2.md index 62ef438135..9ecbede016 100644 --- a/doc/Extensions/metrics/InfluxDBv2.md +++ b/doc/Extensions/metrics/InfluxDBv2.md @@ -39,8 +39,12 @@ continue to function as normal. lnms config:set influxdbv2.token 'admin' lnms config:set influxdbv2.allow_redirect true lmns config:set influxdbv2.organization 'librenms' + lmns config:set influxdbv2.debug false + lmns config:set influxdbv2.groups-exclude ["group_name_1","group_name_2"] ``` The same data stored within rrd will be sent to InfluxDB and recorded. You can then create graphs within Grafana or InfluxDB to display the information you need. + +Please note that polling will slow down when the poller isn't able to reach or write data to InfluxDBv2. diff --git a/lang/en/settings.php b/lang/en/settings.php index 2220b2e64d..84ee223076 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -978,7 +978,14 @@ return [ 'description' => 'Allow Redirects', 'help' => 'To allow redirect from the InfluxDB server', ], - + 'debug' => [ + 'description' => 'Debug', + 'help' => 'To enable or disable verbose output to CLI', + ], + 'groups-exclude' => [ + 'description' => 'Excluded device groups', + 'help' => 'Device groups excluded from sending data to InfluxDBv2', + ], ], 'ipmitool' => [ 'description' => 'Path to ipmtool', diff --git a/misc/config_definitions.json b/misc/config_definitions.json index 022c6dd234..48a8b1e80c 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -4122,6 +4122,21 @@ "section": "influxdbv2", "order": 7 }, + "influxdbv2.debug": { + "default": false, + "type": "boolean", + "group": "poller", + "section": "influxdbv2", + "order": 8 + }, + "influxdbv2.groups-exclude": { + "group": "poller", + "section": "influxdbv2", + "order": 9, + "type": "array", + "default": [ + ] + }, "install_dir": { "type": "directory" },