mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
committed by
Neil Lathwood
parent
db84d3bfe9
commit
294ec4d73d
60
includes/opentsdb.inc.php
Normal file
60
includes/opentsdb.inc.php
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user