diff options
author | Pim van den Berg | 2009-12-31 11:42:56 +0100 |
---|---|---|
committer | Pim van den Berg | 2009-12-31 13:07:13 +0100 |
commit | 95c70c919837f588389f525fe2cf4aba479e9f91 (patch) | |
tree | ef242a0273458ffcadf8357fd8dd4d64b2fb7105 | |
parent | always show 'on $host' in the rrd title (diff) | |
download | apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.zip apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.gz apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.bz2 apt-panopticon_cgp-95c70c919837f588389f525fe2cf4aba479e9f91.tar.xz |
rewrite of type classes
A constructor is added to the Type_Default class. The constructor will
parse GET values (such as host, plugin, pinstance, type, tinstance,
seconds), create an array of all needed rrd files to generate a graph and
substract identifiers from these rrd files.
Because of the constructor (and related functions) it is not needed to
define an array of tinstances to be grouped and shown in one graph. Also
$obj->args don't have to be defined per plugin. This will result in
smaller plugin files.
The type classes are based on the fact that a plugin has multiple type
instances OR multiple rrd data sources. This is called the source and is
retrieved by rrd_get_sources in each rrd_gen_graph function. Also
variables in function rrd_gen_graph have been renamed to better ones.
-rw-r--r-- | graph.php | 14 | ||||
-rw-r--r-- | inc/collectd.inc.php | 17 | ||||
-rw-r--r-- | plugin/cpu.php | 21 | ||||
-rw-r--r-- | plugin/df.php | 16 | ||||
-rw-r--r-- | plugin/disk.php | 24 | ||||
-rw-r--r-- | plugin/entropy.php | 14 | ||||
-rw-r--r-- | plugin/interface.php | 23 | ||||
-rw-r--r-- | plugin/irq.php | 23 | ||||
-rw-r--r-- | plugin/load.php | 14 | ||||
-rw-r--r-- | plugin/memory.php | 20 | ||||
-rw-r--r-- | plugin/processes.php | 20 | ||||
-rw-r--r-- | plugin/sensors.php | 28 | ||||
-rw-r--r-- | plugin/swap.php | 22 | ||||
-rw-r--r-- | plugin/users.php | 14 | ||||
-rw-r--r-- | type/Default.class.php | 142 | ||||
-rw-r--r-- | type/GenericIO.class.php | 51 | ||||
-rw-r--r-- | type/GenericStacked.class.php | 59 |
17 files changed, 198 insertions, 324 deletions
@@ -2,26 +2,20 @@ | |||
2 | 2 | ||
3 | require_once 'conf/common.inc.php'; | 3 | require_once 'conf/common.inc.php'; |
4 | 4 | ||
5 | $host = $_GET['h']; | ||
6 | $plugin = $_GET['p']; | ||
7 | $pinstance = $_GET['pi']; | ||
8 | $type = $_GET['t']; | ||
9 | $tinstance = $_GET['ti']; | ||
10 | $width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; | 5 | $width = empty($_GET['x']) ? $CONFIG['width'] : $_GET['x']; |
11 | $heigth = empty($_GET['y']) ? $CONFIG['heigth'] : $_GET['y']; | 6 | $heigth = empty($_GET['y']) ? $CONFIG['heigth'] : $_GET['y']; |
12 | $seconds = $_GET['s']; | ||
13 | 7 | ||
14 | if (!preg_match('/^[a-z]+$/', $plugin)) { | 8 | if (!preg_match('/^[a-z]+$/', $_GET['p'])) { |
15 | die_img('Error: plugin contains unknown characters.'); | 9 | die_img('Error: plugin contains unknown characters.'); |
16 | exit; | 10 | exit; |
17 | } | 11 | } |
18 | 12 | ||
19 | if (!file_exists($CONFIG['webdir']."/plugin/$plugin.php")) { | 13 | if (!file_exists($CONFIG['webdir'].'/plugin/'.$_GET['p'].'.php')) { |
20 | die_img(sprintf('Error: plugin not available (%s).', $plugin)); | 14 | die_img(sprintf('Error: plugin not available (%s).', $_GET['p'])); |
21 | exit; | 15 | exit; |
22 | } | 16 | } |
23 | 17 | ||
24 | include $CONFIG['webdir']."/plugin/$plugin.php"; | 18 | include $CONFIG['webdir'].'/plugin/'.$_GET['p'].'.php'; |
25 | 19 | ||
26 | 20 | ||
27 | function die_img($msg) { | 21 | function die_img($msg) { |
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php index 3ef9102..2a44fba 100644 --- a/inc/collectd.inc.php +++ b/inc/collectd.inc.php | |||
@@ -221,21 +221,4 @@ function collectd_flush($identifier) { | |||
221 | } | 221 | } |
222 | } | 222 | } |
223 | 223 | ||
224 | # generate identifiers from args | ||
225 | function ident_from_args($args) { | ||
226 | if (is_array($args['tinstance'])) { | ||
227 | foreach($args['tinstance'] as $ti) { | ||
228 | $instances[] = collectd_identifier($args['host'], | ||
229 | $args['plugin'], $args['pinstance'], | ||
230 | $args['type'], $ti); | ||
231 | } | ||
232 | } else { | ||
233 | $instances[] = collectd_identifier($args['host'], | ||
234 | $args['plugin'], $args['pinstance'], | ||
235 | $args['type'], $args['tinstance']); | ||
236 | } | ||
237 | |||
238 | return $instances; | ||
239 | } | ||
240 | |||
241 | ?> | 224 | ?> |
diff --git a/plugin/cpu.php b/plugin/cpu.php index 4cc74f6..d4097b0 100644 --- a/plugin/cpu.php +++ b/plugin/cpu.php | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/GenericStacked.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # cpu-X/ | 10 | # cpu-X/ |
@@ -16,19 +17,7 @@ require_once 'type/GenericStacked.class.php'; | |||
16 | # cpu-X/cpu-user.rrd | 17 | # cpu-X/cpu-user.rrd |
17 | # cpu-X/cpu-wait.rrd | 18 | # cpu-X/cpu-wait.rrd |
18 | 19 | ||
19 | # grouped | 20 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
20 | require_once 'inc/collectd.inc.php'; | ||
21 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
22 | |||
23 | $obj = new Type_GenericStacked; | ||
24 | $obj->datadir = $CONFIG['datadir']; | ||
25 | $obj->args = array( | ||
26 | 'host' => $host, | ||
27 | 'plugin' => $plugin, | ||
28 | 'pinstance' => $pinstance, | ||
29 | 'type' => $type, | ||
30 | 'tinstance' => $tinstance, | ||
31 | ); | ||
32 | $obj->data_sources = array('value'); | 21 | $obj->data_sources = array('value'); |
33 | $obj->order = array('idle', 'nice', 'user', 'wait', 'system', 'softirq', 'interrupt', 'steal'); | 22 | $obj->order = array('idle', 'nice', 'user', 'wait', 'system', 'softirq', 'interrupt', 'steal'); |
34 | $obj->ds_names = array( | 23 | $obj->ds_names = array( |
@@ -53,14 +42,12 @@ $obj->colors = array( | |||
53 | ); | 42 | ); |
54 | $obj->width = $width; | 43 | $obj->width = $width; |
55 | $obj->heigth = $heigth; | 44 | $obj->heigth = $heigth; |
56 | $obj->seconds = $seconds; | ||
57 | 45 | ||
58 | $obj->rrd_title = sprintf('CPU-%s usage', $pinstance); | 46 | $obj->rrd_title = sprintf('CPU-%s usage', $obj->args['pinstance']); |
59 | $obj->rrd_vertical = 'Jiffies'; | 47 | $obj->rrd_vertical = 'Jiffies'; |
60 | $obj->rrd_format = '%5.2lf'; | 48 | $obj->rrd_format = '%5.2lf'; |
61 | 49 | ||
62 | collectd_flush(ident_from_args($obj->args)); | 50 | collectd_flush($obj->identifiers); |
63 | |||
64 | $obj->rrd_graph(); | 51 | $obj->rrd_graph(); |
65 | 52 | ||
66 | ?> | 53 | ?> |
diff --git a/plugin/df.php b/plugin/df.php index bf9b850..79c5cb5 100644 --- a/plugin/df.php +++ b/plugin/df.php | |||
@@ -11,15 +11,7 @@ require_once 'inc/collectd.inc.php'; | |||
11 | # df/ | 11 | # df/ |
12 | # df/df-XXXX.rrd | 12 | # df/df-XXXX.rrd |
13 | 13 | ||
14 | $obj = new Type_GenericStacked; | 14 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
15 | $obj->datadir = $CONFIG['datadir']; | ||
16 | $obj->args = array( | ||
17 | 'host' => $host, | ||
18 | 'plugin' => $plugin, | ||
19 | 'pinstance' => $pinstance, | ||
20 | 'type' => $type, | ||
21 | 'tinstance' => $tinstance, | ||
22 | ); | ||
23 | $obj->data_sources = array('free', 'used'); | 15 | $obj->data_sources = array('free', 'used'); |
24 | $obj->ds_names = array( | 16 | $obj->ds_names = array( |
25 | 'free' => 'Free', | 17 | 'free' => 'Free', |
@@ -31,14 +23,12 @@ $obj->colors = array( | |||
31 | ); | 23 | ); |
32 | $obj->width = $width; | 24 | $obj->width = $width; |
33 | $obj->heigth = $heigth; | 25 | $obj->heigth = $heigth; |
34 | $obj->seconds = $seconds; | ||
35 | 26 | ||
36 | $obj->rrd_title = sprintf('Free space (%s)', $tinstance); | 27 | $obj->rrd_title = sprintf('Free space (%s)', $obj->args['tinstance']); |
37 | $obj->rrd_vertical = 'Bytes'; | 28 | $obj->rrd_vertical = 'Bytes'; |
38 | $obj->rrd_format = '%5.1lf%sB'; | 29 | $obj->rrd_format = '%5.1lf%sB'; |
39 | 30 | ||
40 | collectd_flush(ident_from_args($obj->args)); | 31 | collectd_flush($obj->identifiers); |
41 | |||
42 | $obj->rrd_graph(); | 32 | $obj->rrd_graph(); |
43 | 33 | ||
44 | ?> | 34 | ?> |
diff --git a/plugin/disk.php b/plugin/disk.php index 620b188..f1100d6 100644 --- a/plugin/disk.php +++ b/plugin/disk.php | |||
@@ -13,15 +13,7 @@ require_once 'inc/collectd.inc.php'; | |||
13 | # disk-XXXX/disk_ops.rrd | 13 | # disk-XXXX/disk_ops.rrd |
14 | # disk-XXXX/disk_time.rrd | 14 | # disk-XXXX/disk_time.rrd |
15 | 15 | ||
16 | $obj = new Type_GenericIO; | 16 | $obj = new Type_GenericIO($CONFIG['datadir']); |
17 | $obj->datadir = $CONFIG['datadir']; | ||
18 | $obj->args = array( | ||
19 | 'host' => $host, | ||
20 | 'plugin' => $plugin, | ||
21 | 'pinstance' => $pinstance, | ||
22 | 'type' => $type, | ||
23 | 'tinstance' => $tinstance, | ||
24 | ); | ||
25 | $obj->data_sources = array('read', 'write'); | 17 | $obj->data_sources = array('read', 'write'); |
26 | $obj->ds_names = array( | 18 | $obj->ds_names = array( |
27 | 'read' => 'Read ', | 19 | 'read' => 'Read ', |
@@ -33,33 +25,31 @@ $obj->colors = array( | |||
33 | ); | 25 | ); |
34 | $obj->width = $width; | 26 | $obj->width = $width; |
35 | $obj->heigth = $heigth; | 27 | $obj->heigth = $heigth; |
36 | $obj->seconds = $seconds; | 28 | switch($obj->args['type']) { |
37 | switch($type) { | ||
38 | case 'disk_merged': | 29 | case 'disk_merged': |
39 | $obj->rrd_title = sprintf('Disk Merged Operations (%s)', $pinstance); | 30 | $obj->rrd_title = sprintf('Disk Merged Operations (%s)', $obj->args['pinstance']); |
40 | $obj->rrd_vertical = 'Merged operations/s'; | 31 | $obj->rrd_vertical = 'Merged operations/s'; |
41 | $obj->rrd_format = '%5.1lf'; | 32 | $obj->rrd_format = '%5.1lf'; |
42 | break; | 33 | break; |
43 | case 'disk_octets': | 34 | case 'disk_octets': |
44 | $obj->rrd_title = sprintf('Disk Traffic (%s)', $pinstance); | 35 | $obj->rrd_title = sprintf('Disk Traffic (%s)', $obj->args['pinstance']); |
45 | $obj->rrd_vertical = 'Bytes per second'; | 36 | $obj->rrd_vertical = 'Bytes per second'; |
46 | $obj->rrd_format = '%5.1lf%s'; | 37 | $obj->rrd_format = '%5.1lf%s'; |
47 | break; | 38 | break; |
48 | case 'disk_ops': | 39 | case 'disk_ops': |
49 | $obj->rrd_title = sprintf('Disk Operations (%s)', $pinstance); | 40 | $obj->rrd_title = sprintf('Disk Operations (%s)', $obj->args['pinstance']); |
50 | $obj->rrd_vertical = 'Ops per second'; | 41 | $obj->rrd_vertical = 'Ops per second'; |
51 | $obj->rrd_format = '%5.1lf'; | 42 | $obj->rrd_format = '%5.1lf'; |
52 | break; | 43 | break; |
53 | case 'disk_time': | 44 | case 'disk_time': |
54 | $obj->rrd_title = sprintf('Disk time per operation (%s)', $pinstance); | 45 | $obj->rrd_title = sprintf('Disk time per operation (%s)', $obj->args['pinstance']); |
55 | $obj->rrd_vertical = 'Avg. Time/Op'; | 46 | $obj->rrd_vertical = 'Avg. Time/Op'; |
56 | $obj->rrd_format = '%5.1lf%ss'; | 47 | $obj->rrd_format = '%5.1lf%ss'; |
57 | $obj->scale = '0.001'; | 48 | $obj->scale = '0.001'; |
58 | break; | 49 | break; |
59 | } | 50 | } |
60 | 51 | ||
61 | collectd_flush(ident_from_args($obj->args)); | 52 | collectd_flush($obj->identifiers); |
62 | |||
63 | $obj->rrd_graph(); | 53 | $obj->rrd_graph(); |
64 | 54 | ||
65 | ?> | 55 | ?> |
diff --git a/plugin/entropy.php b/plugin/entropy.php index 6ee96aa..8705894 100644 --- a/plugin/entropy.php +++ b/plugin/entropy.php | |||
@@ -9,15 +9,7 @@ require_once 'inc/collectd.inc.php'; | |||
9 | ## LAYOUT | 9 | ## LAYOUT |
10 | # entropy/entropy.rrd | 10 | # entropy/entropy.rrd |
11 | 11 | ||
12 | $obj = new Type_Default; | 12 | $obj = new Type_Default($CONFIG['datadir']); |
13 | $obj->datadir = $CONFIG['datadir']; | ||
14 | $obj->args = array( | ||
15 | 'host' => $host, | ||
16 | 'plugin' => $plugin, | ||
17 | 'pinstance' => $pinstance, | ||
18 | 'type' => $type, | ||
19 | 'tinstance' => $tinstance, | ||
20 | ); | ||
21 | $obj->data_sources = array('entropy'); | 13 | $obj->data_sources = array('entropy'); |
22 | $obj->ds_names = array( | 14 | $obj->ds_names = array( |
23 | 'entropy' => 'Entropy bits', | 15 | 'entropy' => 'Entropy bits', |
@@ -27,13 +19,11 @@ $obj->colors = array( | |||
27 | ); | 19 | ); |
28 | $obj->width = $width; | 20 | $obj->width = $width; |
29 | $obj->heigth = $heigth; | 21 | $obj->heigth = $heigth; |
30 | $obj->seconds = $seconds; | ||
31 | $obj->rrd_title = 'Available entropy'; | 22 | $obj->rrd_title = 'Available entropy'; |
32 | $obj->rrd_vertical = 'Bits'; | 23 | $obj->rrd_vertical = 'Bits'; |
33 | $obj->rrd_format = '%4.0lf'; | 24 | $obj->rrd_format = '%4.0lf'; |
34 | 25 | ||
35 | collectd_flush(ident_from_args($obj->args)); | 26 | collectd_flush($obj->identifiers); |
36 | |||
37 | $obj->rrd_graph(); | 27 | $obj->rrd_graph(); |
38 | 28 | ||
39 | ?> | 29 | ?> |
diff --git a/plugin/interface.php b/plugin/interface.php index 7d8d929..89e4280 100644 --- a/plugin/interface.php +++ b/plugin/interface.php | |||
@@ -12,15 +12,7 @@ require_once 'inc/collectd.inc.php'; | |||
12 | # interface/if_octets-XXXX.rrd | 12 | # interface/if_octets-XXXX.rrd |
13 | # interface/if_packets-XXXX.rrd | 13 | # interface/if_packets-XXXX.rrd |
14 | 14 | ||
15 | $obj = new Type_GenericIO; | 15 | $obj = new Type_GenericIO($CONFIG['datadir']); |
16 | $obj->datadir = $CONFIG['datadir']; | ||
17 | $obj->args = array( | ||
18 | 'host' => $host, | ||
19 | 'plugin' => $plugin, | ||
20 | 'pinstance' => $pinstance, | ||
21 | 'type' => $type, | ||
22 | 'tinstance' => $tinstance, | ||
23 | ); | ||
24 | $obj->data_sources = array('rx', 'tx'); | 16 | $obj->data_sources = array('rx', 'tx'); |
25 | $obj->ds_names = array( | 17 | $obj->ds_names = array( |
26 | 'rx' => 'Receive ', | 18 | 'rx' => 'Receive ', |
@@ -32,25 +24,24 @@ $obj->colors = array( | |||
32 | ); | 24 | ); |
33 | $obj->width = $width; | 25 | $obj->width = $width; |
34 | $obj->heigth = $heigth; | 26 | $obj->heigth = $heigth; |
35 | $obj->seconds = $seconds; | ||
36 | $obj->rrd_format = '%5.1lf%s'; | 27 | $obj->rrd_format = '%5.1lf%s'; |
37 | switch($type) { | 28 | |
29 | switch($obj->args['type']) { | ||
38 | case 'if_errors': | 30 | case 'if_errors': |
39 | $obj->rrd_title = sprintf('Interface Errors (%s)', $tinstance); | 31 | $obj->rrd_title = sprintf('Interface Errors (%s)', $obj->args['tinstance']); |
40 | $obj->rrd_vertical = 'Errors per second'; | 32 | $obj->rrd_vertical = 'Errors per second'; |
41 | break; | 33 | break; |
42 | case 'if_octets': | 34 | case 'if_octets': |
43 | $obj->rrd_title = sprintf('Interface Traffic (%s)', $tinstance); | 35 | $obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args['tinstance']); |
44 | $obj->rrd_vertical = 'Bits per second'; | 36 | $obj->rrd_vertical = 'Bits per second'; |
45 | break; | 37 | break; |
46 | case 'if_packets': | 38 | case 'if_packets': |
47 | $obj->rrd_title = sprintf('Interface Packets (%s)', $tinstance); | 39 | $obj->rrd_title = sprintf('Interface Packets (%s)', $obj->args['tinstance']); |
48 | $obj->rrd_vertical = 'Packets per second'; | 40 | $obj->rrd_vertical = 'Packets per second'; |
49 | break; | 41 | break; |
50 | } | 42 | } |
51 | 43 | ||
52 | collectd_flush(ident_from_args($obj->args)); | 44 | collectd_flush($obj->identifiers); |
53 | |||
54 | $obj->rrd_graph(); | 45 | $obj->rrd_graph(); |
55 | 46 | ||
56 | ?> | 47 | ?> |
diff --git a/plugin/irq.php b/plugin/irq.php index d6b1e72..ba0e7cb 100644 --- a/plugin/irq.php +++ b/plugin/irq.php | |||
@@ -4,38 +4,21 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/GenericStacked.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # irq/ | 10 | # irq/ |
10 | # irq/irq-XX.rrd | 11 | # irq/irq-XX.rrd |
11 | 12 | ||
12 | # grouped | 13 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
13 | require_once 'inc/collectd.inc.php'; | ||
14 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
15 | sort($tinstance); | ||
16 | |||
17 | $obj = new Type_GenericStacked; | ||
18 | $obj->datadir = $CONFIG['datadir']; | ||
19 | $obj->args = array( | ||
20 | 'host' => $host, | ||
21 | 'plugin' => $plugin, | ||
22 | 'pinstance' => $pinstance, | ||
23 | 'type' => $type, | ||
24 | 'tinstance' => $tinstance, | ||
25 | ); | ||
26 | $obj->data_sources = array('value'); | ||
27 | $obj->ds_names = NULL; | ||
28 | $obj->colors = NULL; | ||
29 | $obj->width = $width; | 14 | $obj->width = $width; |
30 | $obj->heigth = $heigth; | 15 | $obj->heigth = $heigth; |
31 | $obj->seconds = $seconds; | ||
32 | 16 | ||
33 | $obj->rrd_title = 'Interrupts'; | 17 | $obj->rrd_title = 'Interrupts'; |
34 | $obj->rrd_vertical = 'IRQs/s'; | 18 | $obj->rrd_vertical = 'IRQs/s'; |
35 | $obj->rrd_format = '%6.1lf'; | 19 | $obj->rrd_format = '%6.1lf'; |
36 | 20 | ||
37 | collectd_flush(ident_from_args($obj->args)); | 21 | collectd_flush($obj->identifiers); |
38 | |||
39 | $obj->rrd_graph(); | 22 | $obj->rrd_graph(); |
40 | 23 | ||
41 | ?> | 24 | ?> |
diff --git a/plugin/load.php b/plugin/load.php index 523f14c..44baf45 100644 --- a/plugin/load.php +++ b/plugin/load.php | |||
@@ -9,15 +9,7 @@ require_once 'inc/collectd.inc.php'; | |||
9 | ## LAYOUT | 9 | ## LAYOUT |
10 | # load/load.rrd | 10 | # load/load.rrd |
11 | 11 | ||
12 | $obj = new Type_Default; | 12 | $obj = new Type_Default($CONFIG['datadir']); |
13 | $obj->datadir = $CONFIG['datadir']; | ||
14 | $obj->args = array( | ||
15 | 'host' => $host, | ||
16 | 'plugin' => $plugin, | ||
17 | 'pinstance' => $pinstance, | ||
18 | 'type' => $type, | ||
19 | 'tinstance' => $tinstance, | ||
20 | ); | ||
21 | $obj->data_sources = array('shortterm', 'midterm', 'longterm'); | 13 | $obj->data_sources = array('shortterm', 'midterm', 'longterm'); |
22 | $obj->ds_names = array( | 14 | $obj->ds_names = array( |
23 | 'shortterm' => ' 1 min', | 15 | 'shortterm' => ' 1 min', |
@@ -31,13 +23,11 @@ $obj->colors = array( | |||
31 | ); | 23 | ); |
32 | $obj->width = $width; | 24 | $obj->width = $width; |
33 | $obj->heigth = $heigth; | 25 | $obj->heigth = $heigth; |
34 | $obj->seconds = $seconds; | ||
35 | $obj->rrd_title = 'System load'; | 26 | $obj->rrd_title = 'System load'; |
36 | $obj->rrd_vertical = 'System load'; | 27 | $obj->rrd_vertical = 'System load'; |
37 | $obj->rrd_format = '%.2lf'; | 28 | $obj->rrd_format = '%.2lf'; |
38 | 29 | ||
39 | collectd_flush(ident_from_args($obj->args)); | 30 | collectd_flush($obj->identifiers); |
40 | |||
41 | $obj->rrd_graph(); | 31 | $obj->rrd_graph(); |
42 | 32 | ||
43 | ?> | 33 | ?> |
diff --git a/plugin/memory.php b/plugin/memory.php index b0f6b73..ade242c 100644 --- a/plugin/memory.php +++ b/plugin/memory.php | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/GenericStacked.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # memory/ | 10 | # memory/ |
@@ -12,20 +13,7 @@ require_once 'type/GenericStacked.class.php'; | |||
12 | # memory/memory-free.rrd | 13 | # memory/memory-free.rrd |
13 | # memory/memory-used.rrd | 14 | # memory/memory-used.rrd |
14 | 15 | ||
15 | # grouped | 16 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
16 | require_once 'inc/collectd.inc.php'; | ||
17 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
18 | |||
19 | $obj = new Type_GenericStacked; | ||
20 | $obj->datadir = $CONFIG['datadir']; | ||
21 | $obj->args = array( | ||
22 | 'host' => $host, | ||
23 | 'plugin' => $plugin, | ||
24 | 'pinstance' => $pinstance, | ||
25 | 'type' => $type, | ||
26 | 'tinstance' => $tinstance, | ||
27 | ); | ||
28 | $obj->data_sources = array('value'); | ||
29 | $obj->order = array('free', 'buffered', 'cached', 'used'); | 17 | $obj->order = array('free', 'buffered', 'cached', 'used'); |
30 | $obj->ds_names = array( | 18 | $obj->ds_names = array( |
31 | 'free' => 'Free ', | 19 | 'free' => 'Free ', |
@@ -41,14 +29,12 @@ $obj->colors = array( | |||
41 | ); | 29 | ); |
42 | $obj->width = $width; | 30 | $obj->width = $width; |
43 | $obj->heigth = $heigth; | 31 | $obj->heigth = $heigth; |
44 | $obj->seconds = $seconds; | ||
45 | 32 | ||
46 | $obj->rrd_title = 'Physical memory utilization'; | 33 | $obj->rrd_title = 'Physical memory utilization'; |
47 | $obj->rrd_vertical = 'Bytes'; | 34 | $obj->rrd_vertical = 'Bytes'; |
48 | $obj->rrd_format = '%5.1lf%s'; | 35 | $obj->rrd_format = '%5.1lf%s'; |
49 | 36 | ||
50 | collectd_flush(ident_from_args($obj->args)); | 37 | collectd_flush($obj->identifiers); |
51 | |||
52 | $obj->rrd_graph(); | 38 | $obj->rrd_graph(); |
53 | 39 | ||
54 | ?> | 40 | ?> |
diff --git a/plugin/processes.php b/plugin/processes.php index 65e1ddd..1487568 100644 --- a/plugin/processes.php +++ b/plugin/processes.php | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/GenericStacked.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # processes/ | 10 | # processes/ |
@@ -14,20 +15,7 @@ require_once 'type/GenericStacked.class.php'; | |||
14 | # processes/ps_state-running.rrd | 15 | # processes/ps_state-running.rrd |
15 | # processes/ps_state-sleeping.rrd | 16 | # processes/ps_state-sleeping.rrd |
16 | 17 | ||
17 | # grouped | 18 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
18 | require_once 'inc/collectd.inc.php'; | ||
19 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
20 | |||
21 | $obj = new Type_GenericStacked; | ||
22 | $obj->datadir = $CONFIG['datadir']; | ||
23 | $obj->args = array( | ||
24 | 'host' => $host, | ||
25 | 'plugin' => $plugin, | ||
26 | 'pinstance' => $pinstance, | ||
27 | 'type' => $type, | ||
28 | 'tinstance' => $tinstance, | ||
29 | ); | ||
30 | $obj->data_sources = array('value'); | ||
31 | $obj->ds_names = array( | 19 | $obj->ds_names = array( |
32 | 'paging' => 'Paging ', | 20 | 'paging' => 'Paging ', |
33 | 'blocked' => 'Blocked ', | 21 | 'blocked' => 'Blocked ', |
@@ -46,14 +34,12 @@ $obj->colors = array( | |||
46 | ); | 34 | ); |
47 | $obj->width = $width; | 35 | $obj->width = $width; |
48 | $obj->heigth = $heigth; | 36 | $obj->heigth = $heigth; |
49 | $obj->seconds = $seconds; | ||
50 | 37 | ||
51 | $obj->rrd_title = 'Processes'; | 38 | $obj->rrd_title = 'Processes'; |
52 | $obj->rrd_vertical = 'Processes'; | 39 | $obj->rrd_vertical = 'Processes'; |
53 | $obj->rrd_format = '%5.1lf%s'; | 40 | $obj->rrd_format = '%5.1lf%s'; |
54 | 41 | ||
55 | collectd_flush(ident_from_args($obj->args)); | 42 | collectd_flush($obj->identifiers); |
56 | |||
57 | $obj->rrd_graph(); | 43 | $obj->rrd_graph(); |
58 | 44 | ||
59 | ?> | 45 | ?> |
diff --git a/plugin/sensors.php b/plugin/sensors.php index 048f9f1..fda5432 100644 --- a/plugin/sensors.php +++ b/plugin/sensors.php | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/Default.class.php'; | 6 | require_once 'type/Default.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # disk-XXXX/ | 10 | # disk-XXXX/ |
@@ -11,49 +12,34 @@ require_once 'type/Default.class.php'; | |||
11 | # disk-XXXX/temerature-XXXX.rrd | 12 | # disk-XXXX/temerature-XXXX.rrd |
12 | # disk-XXXX/voltage-XXXX.rrd | 13 | # disk-XXXX/voltage-XXXX.rrd |
13 | 14 | ||
14 | # grouped | 15 | $obj = new Type_Default($CONFIG['datadir']); |
15 | require_once 'inc/collectd.inc.php'; | ||
16 | $tinstance = collectd_plugindetail($host, $plugin, 'ti', array('t' => $type)); | ||
17 | |||
18 | $obj = new Type_Default; | ||
19 | $obj->datadir = $CONFIG['datadir']; | ||
20 | $obj->args = array( | ||
21 | 'host' => $host, | ||
22 | 'plugin' => $plugin, | ||
23 | 'pinstance' => $pinstance, | ||
24 | 'type' => $type, | ||
25 | 'tinstance' => $tinstance, | ||
26 | ); | ||
27 | $obj->data_sources = array('value'); | ||
28 | $obj->ds_names = array( | 16 | $obj->ds_names = array( |
29 | 'value' => 'Value ', | 17 | 'value' => 'Value ', |
30 | ); | 18 | ); |
31 | $obj->width = $width; | 19 | $obj->width = $width; |
32 | $obj->heigth = $heigth; | 20 | $obj->heigth = $heigth; |
33 | $obj->seconds = $seconds; | 21 | switch($obj->args['type']) { |
34 | switch($type) { | ||
35 | case 'fanspeed': | 22 | case 'fanspeed': |
36 | $obj->colors = '00ff00'; | 23 | $obj->colors = '00ff00'; |
37 | $obj->rrd_title = sprintf('Fanspeed (%s)', $pinstance); | 24 | $obj->rrd_title = sprintf('Fanspeed (%s)', $obj->args['pinstance']); |
38 | $obj->rrd_vertical = 'RPM'; | 25 | $obj->rrd_vertical = 'RPM'; |
39 | $obj->rrd_format = '%5.1lf'; | 26 | $obj->rrd_format = '%5.1lf'; |
40 | break; | 27 | break; |
41 | case 'temperature': | 28 | case 'temperature': |
42 | $obj->colors = '0000ff'; | 29 | $obj->colors = '0000ff'; |
43 | $obj->rrd_title = sprintf('Temperature (%s)', $pinstance); | 30 | $obj->rrd_title = sprintf('Temperature (%s)', $obj->args['pinstance']); |
44 | $obj->rrd_vertical = 'Celius'; | 31 | $obj->rrd_vertical = 'Celius'; |
45 | $obj->rrd_format = '%5.1lf%s'; | 32 | $obj->rrd_format = '%5.1lf%s'; |
46 | break; | 33 | break; |
47 | case 'voltage': | 34 | case 'voltage': |
48 | $obj->colors = 'ff0000'; | 35 | $obj->colors = 'ff0000'; |
49 | $obj->rrd_title = sprintf('Voltage (%s)', $pinstance); | 36 | $obj->rrd_title = sprintf('Voltage (%s)', $obj->args['pinstance']); |
50 | $obj->rrd_vertical = 'Volt'; | 37 | $obj->rrd_vertical = 'Volt'; |
51 | $obj->rrd_format = '%5.1lf'; | 38 | $obj->rrd_format = '%5.1lf'; |
52 | break; | 39 | break; |
53 | } | 40 | } |
54 | 41 | ||
55 | collectd_flush(ident_from_args($obj->args)); | 42 | collectd_flush($obj->identifiers); |
56 | |||
57 | $obj->rrd_graph(); | 43 | $obj->rrd_graph(); |
58 | 44 | ||
59 | ?> | 45 | ?> |
diff --git a/plugin/swap.php b/plugin/swap.php index 638ddc3..e1527cc 100644 --- a/plugin/swap.php +++ b/plugin/swap.php | |||
@@ -4,6 +4,7 @@ | |||
4 | 4 | ||
5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/GenericStacked.class.php'; |
7 | require_once 'inc/collectd.inc.php'; | ||
7 | 8 | ||
8 | ## LAYOUT | 9 | ## LAYOUT |
9 | # swap/ | 10 | # swap/ |
@@ -11,25 +12,12 @@ require_once 'type/GenericStacked.class.php'; | |||
11 | # swap/swap-free.rrd | 12 | # swap/swap-free.rrd |
12 | # swap/swap-used.rrd | 13 | # swap/swap-used.rrd |
13 | 14 | ||
14 | if ($type == 'swap_io') { | 15 | if ($_GET['t'] == 'swap_io') { |
15 | die_img('Error: swap_io not supported yet'); | 16 | die_img('Error: swap_io not supported yet'); |
16 | exit; | 17 | exit; |
17 | } | 18 | } |
18 | 19 | ||
19 | # grouped | 20 | $obj = new Type_GenericStacked($CONFIG['datadir']); |
20 | require_once 'inc/collectd.inc.php'; | ||
21 | $tinstance = collectd_plugindetail($host, $plugin, 'ti', array('t' => $type)); | ||
22 | |||
23 | $obj = new Type_GenericStacked; | ||
24 | $obj->datadir = $CONFIG['datadir']; | ||
25 | $obj->args = array( | ||
26 | 'host' => $host, | ||
27 | 'plugin' => $plugin, | ||
28 | 'pinstance' => $pinstance, | ||
29 | 'type' => $type, | ||
30 | 'tinstance' => $tinstance, | ||
31 | ); | ||
32 | $obj->data_sources = array('value'); | ||
33 | $obj->order = array('free', 'cached', 'used'); | 21 | $obj->order = array('free', 'cached', 'used'); |
34 | $obj->ds_names = array( | 22 | $obj->ds_names = array( |
35 | 'free' => 'Free ', | 23 | 'free' => 'Free ', |
@@ -43,14 +31,12 @@ $obj->colors = array( | |||
43 | ); | 31 | ); |
44 | $obj->width = $width; | 32 | $obj->width = $width; |
45 | $obj->heigth = $heigth; | 33 | $obj->heigth = $heigth; |
46 | $obj->seconds = $seconds; | ||
47 | 34 | ||
48 | $obj->rrd_title = 'Swap utilization'; | 35 | $obj->rrd_title = 'Swap utilization'; |
49 | $obj->rrd_vertical = 'Bytes'; | 36 | $obj->rrd_vertical = 'Bytes'; |
50 | $obj->rrd_format = '%5.1lf%s'; | 37 | $obj->rrd_format = '%5.1lf%s'; |
51 | 38 | ||
52 | collectd_flush(ident_from_args($obj->args)); | 39 | collectd_flush($obj->identifiers); |
53 | |||
54 | $obj->rrd_graph(); | 40 | $obj->rrd_graph(); |
55 | 41 | ||
56 | ?> | 42 | ?> |
diff --git a/plugin/users.php b/plugin/users.php index 5ebee43..d94a8c1 100644 --- a/plugin/users.php +++ b/plugin/users.php | |||
@@ -9,15 +9,7 @@ require_once 'inc/collectd.inc.php'; | |||
9 | ## LAYOUT | 9 | ## LAYOUT |
10 | # users/users.rrd | 10 | # users/users.rrd |
11 | 11 | ||
12 | $obj = new Type_Default; | 12 | $obj = new Type_Default($CONFIG['datadir']); |
13 | $obj->datadir = $CONFIG['datadir']; | ||
14 | $obj->args = array( | ||
15 | 'host' => $host, | ||
16 | 'plugin' => $plugin, | ||
17 | 'pinstance' => $pinstance, | ||
18 | 'type' => $type, | ||
19 | 'tinstance' => $tinstance, | ||
20 | ); | ||
21 | $obj->data_sources = array('users'); | 13 | $obj->data_sources = array('users'); |
22 | $obj->ds_names = array( | 14 | $obj->ds_names = array( |
23 | 'users' => 'Users', | 15 | 'users' => 'Users', |
@@ -27,13 +19,11 @@ $obj->colors = array( | |||
27 | ); | 19 | ); |
28 | $obj->width = $width; | 20 | $obj->width = $width; |
29 | $obj->heigth = $heigth; | 21 | $obj->heigth = $heigth; |
30 | $obj->seconds = $seconds; | ||
31 | $obj->rrd_title = 'Users'; | 22 | $obj->rrd_title = 'Users'; |
32 | $obj->rrd_vertical = 'Users'; | 23 | $obj->rrd_vertical = 'Users'; |
33 | $obj->rrd_format = '%.1lf'; | 24 | $obj->rrd_format = '%.1lf'; |
34 | 25 | ||
35 | collectd_flush(ident_from_args($obj->args)); | 26 | collectd_flush($obj->identifiers); |
36 | |||
37 | $obj->rrd_graph(); | 27 | $obj->rrd_graph(); |
38 | 28 | ||
39 | ?> | 29 | ?> |
diff --git a/type/Default.class.php b/type/Default.class.php index 6b1ab5c..0c992e2 100644 --- a/type/Default.class.php +++ b/type/Default.class.php | |||
@@ -5,7 +5,8 @@ | |||
5 | class Type_Default { | 5 | class Type_Default { |
6 | var $datadir; | 6 | var $datadir; |
7 | var $args; | 7 | var $args; |
8 | var $data_sources; | 8 | var $seconds; |
9 | var $data_sources = array('value'); | ||
9 | var $order; | 10 | var $order; |
10 | var $ds_names; | 11 | var $ds_names; |
11 | var $colors; | 12 | var $colors; |
@@ -16,6 +17,29 @@ class Type_Default { | |||
16 | var $width; | 17 | var $width; |
17 | var $heigth; | 18 | var $heigth; |
18 | 19 | ||
20 | var $files; | ||
21 | var $tinstances; | ||
22 | var $identifiers; | ||
23 | |||
24 | function __construct($datadir) { | ||
25 | $this->datadir = $datadir; | ||
26 | $this->parse_get(); | ||
27 | $this->rrd_files(); | ||
28 | $this->identifiers = $this->file2identifier($this->files); | ||
29 | } | ||
30 | |||
31 | # parse $_GET values | ||
32 | function parse_get() { | ||
33 | $this->args = array( | ||
34 | 'host' => $_GET['h'], | ||
35 | 'plugin' => $_GET['p'], | ||
36 | 'pinstance' => $_GET['pi'], | ||
37 | 'type' => $_GET['t'], | ||
38 | 'tinstance' => $_GET['ti'], | ||
39 | ); | ||
40 | $this->seconds = $_GET['s']; | ||
41 | } | ||
42 | |||
19 | function validate_color($color) { | 43 | function validate_color($color) { |
20 | if (!preg_match('/^[0-9a-f]{6}$/', $color)) | 44 | if (!preg_match('/^[0-9a-f]{6}$/', $color)) |
21 | return '000000'; | 45 | return '000000'; |
@@ -46,26 +70,41 @@ class Type_Default { | |||
46 | return $c[r].$c[g].$c[b]; | 70 | return $c[r].$c[g].$c[b]; |
47 | } | 71 | } |
48 | 72 | ||
49 | function identifier($host, $plugin, $pinst, $type, $tinst) { | 73 | function rrd_files() { |
50 | $identifier = sprintf('%s/%s%s%s/%s%s%s', $host, | 74 | $files = $this->get_filenames(); |
51 | $plugin, strlen($pinst) ? '-' : '', $pinst, | ||
52 | $type, strlen($tinst) ? '-' : '', $tinst); | ||
53 | 75 | ||
54 | if (is_file($this->datadir.'/'.$identifier.'.rrd')) | 76 | foreach($files as $filename) { |
55 | return $identifier; | 77 | preg_match("#^$this->datadir/{$this->args['host']}/[\w\d]+-?([\w\d-]+)?/[\w\d]+-?([\w\d-]+)?\.rrd#", $filename, $matches); |
56 | else | 78 | |
57 | return FALSE; | 79 | $this->tinstances[] = $matches[2]; |
80 | $this->files[$matches[2]] = $filename; | ||
81 | } | ||
82 | |||
83 | sort($this->tinstances); | ||
84 | ksort($this->files); | ||
58 | } | 85 | } |
59 | 86 | ||
60 | function get_filename($tinstance=NULL) { | 87 | function get_filenames() { |
61 | if (!is_array($this->args['tinstance']) && $tinstance == NULL) | 88 | $identifier = sprintf('%s/%s%s%s/%s%s%s', $this->args['host'], |
62 | $tinstance = $this->args['tinstance']; | 89 | $this->args['plugin'], strlen($this->args['pinstance']) ? '-' : '', $this->args['pinstance'], |
90 | $this->args['type'], strlen($this->args['tinstance']) ? '-' : '', $this->args['tinstance']); | ||
91 | |||
92 | $wildcard = strlen($this->args['tinstance']) ? '' : '*'; | ||
63 | 93 | ||
64 | $identifier = $this->identifier($this->args['host'], | 94 | $files = glob($this->datadir .'/'. $identifier . $wildcard . '.rrd'); |
65 | $this->args['plugin'], $this->args['pinstance'], | ||
66 | $this->args['type'], $tinstance); | ||
67 | 95 | ||
68 | return $this->datadir.'/'.$identifier.'.rrd'; | 96 | return $files; |
97 | } | ||
98 | |||
99 | function file2identifier($files) { | ||
100 | foreach($files as $key => $file) { | ||
101 | if (is_file($file)) { | ||
102 | $files[$key] = preg_replace("#^$this->datadir/#", '', $files[$key]); | ||
103 | $files[$key] = preg_replace('#\.rrd$#', '', $files[$key]); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | return $files; | ||
69 | } | 108 | } |
70 | 109 | ||
71 | function rrd_graph($debug=false) { | 110 | function rrd_graph($debug=false) { |
@@ -96,48 +135,57 @@ class Type_Default { | |||
96 | return $rrdgraph; | 135 | return $rrdgraph; |
97 | } | 136 | } |
98 | 137 | ||
99 | function rrd_gen_graph() { | 138 | function rrd_get_sources() { |
100 | $filename = $this->get_filename(); | 139 | # is the source spread over multiple files? |
140 | if (is_array($this->files) && count($this->files)>1) { | ||
141 | # and must it be ordered? | ||
142 | if (is_array($this->order)) { | ||
143 | $this->tinstances = array_intersect($this->order, $this->tinstances); | ||
144 | } | ||
145 | # use tinstances as sources | ||
146 | $sources = $this->tinstances; | ||
147 | } | ||
148 | # or one file with multiple data_sources | ||
149 | else { | ||
150 | # use data_sources as sources | ||
151 | $sources = $this->data_sources; | ||
152 | } | ||
153 | return $sources; | ||
154 | } | ||
101 | 155 | ||
156 | function rrd_gen_graph() { | ||
102 | $rrdgraph = $this->rrd_options(); | 157 | $rrdgraph = $this->rrd_options(); |
103 | 158 | ||
104 | if (is_array($this->args['tinstance'])) | 159 | $sources = $this->rrd_get_sources(); |
105 | $array = is_array($this->order) ? $this->order : $this->args['tinstance']; | ||
106 | else | ||
107 | $array = $this->data_sources; | ||
108 | 160 | ||
109 | $i=0; | 161 | $i=0; |
110 | foreach ($array as $value) { | 162 | foreach ($this->tinstances as $tinstance) { |
111 | if (is_array($this->args['tinstance'])) { | 163 | foreach ($this->data_sources as $ds) { |
112 | $filename = $this->get_filename($value); | 164 | $rrdgraph[] = sprintf('DEF:min_%s=%s:%s:MIN', $sources[$i], $this->files[$tinstance], $ds); |
113 | $ds = $this->data_sources[0]; | 165 | $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', $sources[$i], $this->files[$tinstance], $ds); |
114 | } else { | 166 | $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', $sources[$i], $this->files[$tinstance], $ds); |
115 | $filename = $this->get_filename(); | 167 | $i++; |
116 | $ds = $value; | ||
117 | } | 168 | } |
118 | $rrdgraph[] = sprintf('DEF:min%s=%s:%s:MIN', $i, $filename, $ds); | ||
119 | $rrdgraph[] = sprintf('DEF:avg%s=%s:%s:AVERAGE', $i, $filename, $ds); | ||
120 | $rrdgraph[] = sprintf('DEF:max%s=%s:%s:MAX', $i, $filename, $ds); | ||
121 | $i++; | ||
122 | } | 169 | } |
123 | 170 | ||
124 | if (!is_array($this->args['tinstance'])) { | 171 | if(count($this->files)<=1) { |
125 | $rrdgraph[] = sprintf('AREA:max0#%s', $this->get_faded_color($this->colors[$this->data_sources[0]])); | 172 | foreach ($sources as $source) { |
126 | $rrdgraph[] = sprintf('AREA:min0#%s', 'ffffff'); | 173 | $rrdgraph[] = sprintf('AREA:max_%s#%s', $source, $this->get_faded_color($this->colors[$source])); |
174 | $rrdgraph[] = sprintf('AREA:min_%s#%s', $source, 'ffffff'); | ||
175 | break; # only 1 area to draw | ||
176 | } | ||
127 | } | 177 | } |
128 | 178 | ||
129 | $i=0; | 179 | foreach ($sources as $source) { |
130 | foreach ($array as $value) { | 180 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
131 | $dsname = $this->ds_names[$value] != '' ? $this->ds_names[$value] : $value; | 181 | $color = is_array($this->colors) ? $this->colors[$source]: $this->colors; |
132 | $color = is_array($this->colors) ? $this->colors[$value]: $this->colors; | 182 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $source, $this->validate_color($color), $dsname); |
133 | $rrdgraph[] = sprintf('LINE1:avg%d#%s:\'%s\'', $i, $this->validate_color($color), $dsname); | 183 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $source, $this->rrd_format); |
134 | $rrdgraph[] = sprintf('GPRINT:min%d:MIN:\'%s Min,\'', $i, $this->rrd_format); | 184 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $source, $this->rrd_format); |
135 | $rrdgraph[] = sprintf('GPRINT:avg%d:AVERAGE:\'%s Avg,\'', $i, $this->rrd_format); | 185 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $source, $this->rrd_format); |
136 | $rrdgraph[] = sprintf('GPRINT:max%d:MAX:\'%s Max,\'', $i, $this->rrd_format); | 186 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', $source, $this->rrd_format); |
137 | $rrdgraph[] = sprintf('GPRINT:avg%d:LAST:\'%s Last\\l\'', $i, $this->rrd_format); | ||
138 | $i++; | ||
139 | } | 187 | } |
140 | 188 | ||
141 | return $rrdgraph; | 189 | return $rrdgraph; |
142 | } | 190 | } |
143 | } | 191 | } |
diff --git a/type/GenericIO.class.php b/type/GenericIO.class.php index e91cb16..ee04316 100644 --- a/type/GenericIO.class.php +++ b/type/GenericIO.class.php | |||
@@ -5,45 +5,54 @@ require_once 'Default.class.php'; | |||
5 | class Type_GenericIO extends Type_Default { | 5 | class Type_GenericIO extends Type_Default { |
6 | 6 | ||
7 | function rrd_gen_graph() { | 7 | function rrd_gen_graph() { |
8 | $filename = $this->get_filename(); | ||
9 | |||
10 | $rrdgraph = $this->rrd_options(); | 8 | $rrdgraph = $this->rrd_options(); |
11 | 9 | ||
10 | $sources = $this->rrd_get_sources(); | ||
11 | |||
12 | if ($this->scale) | 12 | if ($this->scale) |
13 | $raw = '_raw'; | 13 | $raw = '_raw'; |
14 | foreach($this->data_sources as $ds) { | 14 | $i=0; |
15 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', $ds, $raw, $filename, $ds); | 15 | foreach ($this->tinstances as $tinstance) { |
16 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', $ds, $raw, $filename, $ds); | 16 | foreach ($this->data_sources as $ds) { |
17 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', $ds, $raw, $filename, $ds); | 17 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', $sources[$i], $raw, $this->files[$tinstance], $ds); |
18 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', $sources[$i], $raw, $this->files[$tinstance], $ds); | ||
19 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', $sources[$i], $raw, $this->files[$tinstance], $ds); | ||
20 | $i++; | ||
21 | } | ||
18 | } | 22 | } |
19 | if ($this->scale) { | 23 | if ($this->scale) { |
20 | foreach($this->data_sources as $ds) { | 24 | $i=0; |
21 | $rrdgraph[] = sprintf('CDEF:min_%s=min_%s_raw,%s,*', $ds, $ds, $this->scale); | 25 | foreach ($this->tinstances as $tinstance) { |
22 | $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%s_raw,%s,*', $ds, $ds, $this->scale); | 26 | foreach ($this->data_sources as $ds) { |
23 | $rrdgraph[] = sprintf('CDEF:max_%s=max_%s_raw,%s,*', $ds, $ds, $this->scale); | 27 | $rrdgraph[] = sprintf('CDEF:min_%s=min_%1$s_raw,%s,*', $sources[$i], $this->scale); |
28 | $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%1$s_raw,%s,*', $sources[$i], $this->scale); | ||
29 | $rrdgraph[] = sprintf('CDEF:max_%s=max_%1$s_raw,%s,*', $sources[$i], $this->scale); | ||
30 | $i++; | ||
31 | } | ||
24 | } | 32 | } |
25 | } | 33 | } |
26 | 34 | ||
27 | $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF', | 35 | $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF', |
28 | $this->data_sources[0], $this->data_sources[1]); | 36 | $sources[0], $sources[1]); |
29 | 37 | ||
30 | foreach($this->data_sources as $ds) { | 38 | foreach($sources as $source) { |
31 | $rrdgraph[] = sprintf('AREA:avg_%s#%s', $ds, $this->get_faded_color($this->colors[$ds])); | 39 | $rrdgraph[] = sprintf('AREA:avg_%s#%s', $source, $this->get_faded_color($this->colors[$source])); |
32 | } | 40 | } |
33 | 41 | ||
34 | $rrdgraph[] = sprintf('AREA:overlap#%s', | 42 | $rrdgraph[] = sprintf('AREA:overlap#%s', |
35 | $this->get_faded_color( | 43 | $this->get_faded_color( |
36 | $this->get_faded_color($this->colors[$this->data_sources[0]]), | 44 | $this->get_faded_color($this->colors[$sources[0]]), |
37 | $this->get_faded_color($this->colors[$this->data_sources[1]]) | 45 | $this->get_faded_color($this->colors[$sources[1]]) |
38 | ) | 46 | ) |
39 | ); | 47 | ); |
40 | 48 | ||
41 | foreach($this->data_sources as $ds) { | 49 | foreach($sources as $source) { |
42 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $ds, $this->colors[$ds], $this->ds_names[$ds]); | 50 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
43 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $ds, $this->rrd_format); | 51 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $source, $this->colors[$source], $dsname); |
44 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $ds, $this->rrd_format); | 52 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $source, $this->rrd_format); |
45 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $ds, $this->rrd_format); | 53 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $source, $this->rrd_format); |
46 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\l\'', $ds, $this->rrd_format); | 54 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $source, $this->rrd_format); |
55 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\l\'', $source, $this->rrd_format); | ||
47 | } | 56 | } |
48 | 57 | ||
49 | return $rrdgraph; | 58 | return $rrdgraph; |
diff --git a/type/GenericStacked.class.php b/type/GenericStacked.class.php index f024336..7595385 100644 --- a/type/GenericStacked.class.php +++ b/type/GenericStacked.class.php | |||
@@ -3,56 +3,41 @@ | |||
3 | require_once 'Default.class.php'; | 3 | require_once 'Default.class.php'; |
4 | 4 | ||
5 | class Type_GenericStacked extends Type_Default { | 5 | class Type_GenericStacked extends Type_Default { |
6 | 6 | ||
7 | function rrd_gen_graph() { | 7 | function rrd_gen_graph() { |
8 | $rrdgraph = $this->rrd_options(); | 8 | $rrdgraph = $this->rrd_options(); |
9 | 9 | ||
10 | if (is_array($this->args['tinstance'])) | 10 | $sources = $this->rrd_get_sources(); |
11 | if (is_array($this->order)) | ||
12 | $array = array_intersect($this->order, $this->args['tinstance']); | ||
13 | else | ||
14 | $array = $this->args['tinstance']; | ||
15 | else | ||
16 | $array = $this->data_sources; | ||
17 | 11 | ||
18 | $i=0; | 12 | $i=0; |
19 | foreach ($array as $value) { | 13 | foreach ($this->tinstances as $tinstance) { |
20 | if (is_array($this->args['tinstance'])) { | 14 | foreach ($this->data_sources as $ds) { |
21 | $filename = $this->get_filename($value); | 15 | $rrdgraph[] = sprintf('DEF:min_%s=%s:%s:MIN', $sources[$i], $this->files[$tinstance], $ds); |
22 | $ds = $this->data_sources[0]; | 16 | $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', $sources[$i], $this->files[$tinstance], $ds); |
23 | } else { | 17 | $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', $sources[$i], $this->files[$tinstance], $ds); |
24 | $filename = $this->get_filename(); | 18 | $i++; |
25 | $ds = $value; | ||
26 | } | 19 | } |
27 | $rrdgraph[] = sprintf('DEF:min%s=%s:%s:MIN', $i, $filename, $ds); | ||
28 | $rrdgraph[] = sprintf('DEF:avg%s=%s:%s:AVERAGE', $i, $filename, $ds); | ||
29 | $rrdgraph[] = sprintf('DEF:max%s=%s:%s:MAX', $i, $filename, $ds); | ||
30 | $i++; | ||
31 | } | 20 | } |
32 | 21 | ||
33 | for ($i=count($array)-1 ; $i>=0 ; $i--) { | 22 | for ($i=count($sources)-1 ; $i>=0 ; $i--) { |
34 | if ($i == (count($array)-1)) | 23 | if ($i == (count($sources)-1)) |
35 | $rrdgraph[] = sprintf('CDEF:cdef%d=avg%d', $i, $i); | 24 | $rrdgraph[] = sprintf('CDEF:area_%s=avg_%1$s', $sources[$i]); |
36 | else | 25 | else |
37 | $rrdgraph[] = sprintf('CDEF:cdef%d=cdef%d,avg%d,+', $i, $i+1, $i); | 26 | $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,avg_%1$s,+', $sources[$i], $sources[$i+1]); |
38 | } | 27 | } |
39 | 28 | ||
40 | $i=0; | 29 | foreach ($sources as $source) { |
41 | foreach ($array as $value) { | 30 | $color = $this->get_faded_color($this->colors[$source]); |
42 | $color = $this->get_faded_color($this->colors[$value]); | 31 | $rrdgraph[] = sprintf('AREA:area_%s#%s', $source, $color); |
43 | $rrdgraph[] = sprintf('AREA:cdef%d#%s', $i, $color); | ||
44 | $i++; | ||
45 | } | 32 | } |
46 | 33 | ||
47 | $i=0; | 34 | foreach ($sources as $source) { |
48 | foreach ($array as $value) { | 35 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; |
49 | $dsname = $this->ds_names[$value] != '' ? $this->ds_names[$value] : $value; | 36 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', $source, $this->validate_color($this->colors[$source]), $dsname); |
50 | $rrdgraph[] = sprintf('LINE1:cdef%d#%s:\'%s\'', $i, $this->validate_color($this->colors[$value]), $dsname); | 37 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $source, $this->rrd_format); |
51 | $rrdgraph[] = sprintf('GPRINT:min%d:MIN:\'%s Min,\'', $i, $this->rrd_format); | 38 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $source, $this->rrd_format); |
52 | $rrdgraph[] = sprintf('GPRINT:avg%d:AVERAGE:\'%s Avg,\'', $i, $this->rrd_format); | 39 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $source, $this->rrd_format); |
53 | $rrdgraph[] = sprintf('GPRINT:max%d:MAX:\'%s Max,\'', $i, $this->rrd_format); | 40 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\\l\'', $source, $this->rrd_format); |
54 | $rrdgraph[] = sprintf('GPRINT:avg%d:LAST:\'%s Last\\l\'', $i, $this->rrd_format); | ||
55 | $i++; | ||
56 | } | 41 | } |
57 | 42 | ||
58 | return $rrdgraph; | 43 | return $rrdgraph; |