diff options
| author | Pim van den Berg | 2014-05-03 19:17:16 +0200 |
|---|---|---|
| committer | Pim van den Berg | 2014-05-12 21:32:24 +0200 |
| commit | 0a547add2f4cc264380d2dab2c472efe5a1d7094 (patch) | |
| tree | 55bb43a3e31c5814848d61eea92c8438e4a37886 /inc/collectd.inc.php | |
| parent | type/base: set default title to "Plugin Type (PluginInstance) (Category)" (diff) | |
| download | apt-panopticon_cgp-0a547add2f4cc264380d2dab2c472efe5a1d7094.zip apt-panopticon_cgp-0a547add2f4cc264380d2dab2c472efe5a1d7094.tar.gz apt-panopticon_cgp-0a547add2f4cc264380d2dab2c472efe5a1d7094.tar.bz2 apt-panopticon_cgp-0a547add2f4cc264380d2dab2c472efe5a1d7094.tar.xz | |
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.
Diffstat (limited to 'inc/collectd.inc.php')
| -rw-r--r-- | inc/collectd.inc.php | 24 |
1 files changed, 24 insertions, 0 deletions
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) { | |||
| 167 | 167 | ||
| 168 | return $data; | 168 | return $data; |
| 169 | } | 169 | } |
| 170 | |||
| 171 | function parse_typesdb_file($file = '/usr/share/collectd/types.db') { | ||
| 172 | if (!file_exists($file)) | ||
| 173 | $file = 'inc/types.db'; | ||
| 174 | |||
| 175 | $types = array(); | ||
| 176 | foreach (file($file) as $type) { | ||
| 177 | if(!preg_match('/^(?P<dataset>[\w_]+)\s+(?P<datasources>.*)/', $type, $matches)) | ||
| 178 | continue; | ||
| 179 | $dataset = $matches['dataset']; | ||
| 180 | $datasources = explode(', ', $matches['datasources']); | ||
| 181 | |||
| 182 | foreach ($datasources as $ds) { | ||
| 183 | if (!preg_match('/^(?P<dsname>\w+):(?P<dstype>[\w]+):(?P<min>[\-\dU\.]+):(?P<max>[\dU\.]+)/', $ds, $matches)) | ||
| 184 | error_log(sprintf('CGP Error: DS "%s" from dataset "%s" did not match', $ds, $dataset)); | ||
| 185 | $types[$dataset][$matches['dsname']] = array( | ||
| 186 | 'dstype' => $matches['dstype'], | ||
| 187 | 'min' => $matches['min'], | ||
| 188 | 'max' => $matches['max'], | ||
| 189 | ); | ||
| 190 | } | ||
| 191 | } | ||
| 192 | return $types; | ||
| 193 | } | ||
