feature: Added support for sending metrics to OpenTSDB (#7022)

* Create OpenTSDB.md

* Send collected data to OpenTSDB

* Send collected data to OpenTSDB

* Update build.sql

* Send collected data to OpenTSDB

* Delete 200.sql

* Update db_schema.yaml

* Update datastore.inc.php

* Update OpenTSDB.md

* Added OpenTSDB to mkdocs.yaml
This commit is contained in:
Yacine Benamsili
2017-07-15 11:28:27 +02:00
committed by Neil Lathwood
parent db84d3bfe9
commit 294ec4d73d
6 changed files with 88 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
source: Extensions/OpenTSDB.md
# Enabling support for OpenTSDB.
This module sends all metrics to OpenTSDB server. You need something like Grafana for graphing.
### Requirements
- OpenTSDB
- Grafana
### What you don't get
- Pretty graphs, this is why at present you need Grafana. You need to build your own graphs within Grafana.
RRD will continue to function normally so LibreNMS itself should continue to function normally.
You can add the following to `config.php`.
### Configuration
```php
// OpenTSDB default configuration
$config['opentsdb']['enable'] = true;
$config['opentsdb']['host'] = '127.0.0.1'; // your OpenTSDB server
$config['opentsdb']['port'] = 4242;
```
The same data than the one stored within rrd will be sent to OpenTSDB and recorded. You can then create graphs within Grafana to display the information you need.

View File

@@ -67,5 +67,6 @@ function data_update($device, $measurement, $tags, $fields)
rrdtool_data_update($device, $measurement, $tags, $fields);
influx_update($device, $measurement, rrd_array_filter($tags), $fields);
opentsdb_update($device, $measurement, rrd_array_filter($tags), $fields);
graphite_update($device, $measurement, $tags, $fields);
} // data_update

View File

@@ -56,6 +56,7 @@ require_once $install_dir . '/includes/common.php';
require_once $install_dir . '/includes/dbFacile.php';
require_once $install_dir . '/includes/rrdtool.inc.php';
require_once $install_dir . '/includes/influxdb.inc.php';
require_once $install_dir . '/includes/opentsdb.inc.php';
require_once $install_dir . '/includes/graphite.inc.php';
require_once $install_dir . '/includes/datastore.inc.php';
require_once $install_dir . '/includes/billing.php';

60
includes/opentsdb.inc.php Normal file
View File

@@ -0,0 +1,60 @@
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Yacine Ben <https://github.com/yac01/librenms.git >
*
* 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.
*/
function opentsdb_update($device, $measurement, $tags, $fields)
{
global $config, $opentsdb;
if ($config['opentsdb']['enable'] == true) {
if ($opentsdb != true) {
$opentsdb = fsockopen($config['opentsdb']['host'], $config['opentsdb']['port']);
d_echo("Connection made to OpenTSDB");
} else {
d_echo("Connection to OpenTSDB has failed");
}
$flag=$config['opentsdb']['co'];
$timestamp = time();
$tmp_tags = "hostname=".$device['hostname'];
foreach ($tags as $k => $v) {
$v = str_replace(array(' ',',','='), '_', $v);
if (!empty($v)) {
$tmp_tags = $tmp_tags ." ". $k ."=".$v;
}
}
if ($measurement == 'port') {
foreach ($fields as $k => $v) {
$measurement = $k;
if ($flag == true) {
$measurement = $measurement.".".$device['co'];
}
$line = sprintf('put net.port.%s %d %f %s', strtolower($measurement), $timestamp, $v, $tmp_tags);
d_echo("Sending to OPenTSDB: $line\n");
fwrite($opentsdb, $line . "\n"); // send $line into OpenTSDB
}
} else {
if ($flag == true) {
$measurement = $measurement.'.'.$device['co'];
}
foreach ($fields as $k => $v) {
$tmp_tags_key = $tmp_tags ." ". "key" ."=".$k;
$line = sprintf('put net.%s %d %f %s', strtolower($measurement), $timestamp, $v, $tmp_tags_key);
d_echo("Sending to OPenTSDB: $line\n");
fwrite($opentsdb, $line . "\n"); // send $line into OpenTSDB
}
}
}
}

View File

@@ -747,6 +747,7 @@ foreach ($ports as $port) {
influx_update($device, 'ports', rrd_array_filter($tags), $fields);
graphite_update($device, 'ports|' . $ifName, $tags, $fields);
opentsdb_update($device, 'port', array('ifName' => $this_port['ifName'], 'ifIndex' => getPortRrdName($port_id)), $fields);
// End Update IF-MIB
// Update PAgP

View File

@@ -59,6 +59,7 @@ pages:
- Extensions/Memcached.md
- Extensions/Network-Map.md
- Extensions/NFSen.md
- Extensions/OpenTSDB.md
- Extensions/Oxidized.md
- Extensions/PeeringDB.md
- Extensions/Plugin-System.md