From 0a547add2f4cc264380d2dab2c472efe5a1d7094 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Sat, 3 May 2014 19:17:16 +0200 Subject: graph.php: use JSON plugins instead of including PHP plugin files A couple of big changes here. A lot of logic moved to graph.php. The PHP plugin files have been rewritten to JSON. In these JSON files *everything* is optional. Also *NOT* having a JSON plugin file won't block you from having a graph. The JSON will just make the graphs prettier (by having a title, y-axis title, legend, colors, etc..). The Collectd types.db file is parsed and used to determine RRD content. When things are not defined in the JSON it will fallback to a default. --- inc/collectd.inc.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'inc/collectd.inc.php') diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index 3bfc6ff..695d79c 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php @@ -167,3 +167,27 @@ function plugin_sort($data) { return $data; } + +function parse_typesdb_file($file = '/usr/share/collectd/types.db') { + if (!file_exists($file)) + $file = 'inc/types.db'; + + $types = array(); + foreach (file($file) as $type) { + if(!preg_match('/^(?P[\w_]+)\s+(?P.*)/', $type, $matches)) + continue; + $dataset = $matches['dataset']; + $datasources = explode(', ', $matches['datasources']); + + foreach ($datasources as $ds) { + if (!preg_match('/^(?P\w+):(?P[\w]+):(?P[\-\dU\.]+):(?P[\dU\.]+)/', $ds, $matches)) + error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); + $types[$dataset][$matches['dsname']] = array( + 'dstype' => $matches['dstype'], + 'min' => $matches['min'], + 'max' => $matches['max'], + ); + } + } + return $types; +} -- cgit v1.1