forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphite.inc.php
33 lines (31 loc) · 1.32 KB
/
graphite.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Falk Stern <https://github.com/fstern/ >
*
* 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 graphite_update($device, $measurement, $tags, $fields)
{
global $graphite, $config;
if ($graphite !== false) {
$timestamp = time();
$graphite_prefix = $config['graphite']['prefix'];
// metrics will be built as prefix.hostname.measurement.field value timestamp
// metric fields can not contain . as this is used by graphite as a field separator
$hostname = preg_replace('/\./', '_', $device['hostname']);
$measurement = preg_replace(array('/\./', '/\//'), '_', $measurement);
$measurement = preg_replace('/\|/', '.', $measurement);
foreach ($fields as $k => $v) {
$metric = implode(".", array_filter(array($graphite_prefix, $hostname, $measurement, $k)));
$line = implode(" ", array($metric, $v, $timestamp));
d_echo("Sending $line\n");
fwrite($graphite, $line . "\n");
}
}
}