diff options
author | Pim van den Berg | 2009-09-20 13:36:25 +0200 |
---|---|---|
committer | Pim van den Berg | 2009-09-20 13:45:26 +0200 |
commit | cd94ef34134d8f06af83ec97119018b4e80346a0 (patch) | |
tree | b01a57617cb5528554b1909583bdf110d8acb631 | |
download | apt-panopticon_cgp-cd94ef34134d8f06af83ec97119018b4e80346a0.zip apt-panopticon_cgp-cd94ef34134d8f06af83ec97119018b4e80346a0.tar.gz apt-panopticon_cgp-cd94ef34134d8f06af83ec97119018b4e80346a0.tar.bz2 apt-panopticon_cgp-cd94ef34134d8f06af83ec97119018b4e80346a0.tar.xz |
initial import of cgp
Collectd Graph Panel is a frontend for Collectd written in PHP.
The goal of CGP is to provide an easy-to-use frontend for Collectd,
starting with page that shows an overview of all the hosts you are
managing with Collectd.
In this initial import there is support for the plugins that are default
enabled in Collectd. The supported plugins are located in the plugin
directory.
-rw-r--r-- | .htaccess | 2 | ||||
-rw-r--r-- | conf/.gitignore | 1 | ||||
-rw-r--r-- | conf/common.inc.php | 8 | ||||
-rw-r--r-- | conf/config.php | 19 | ||||
-rw-r--r-- | detail.php | 52 | ||||
-rw-r--r-- | graph.php | 39 | ||||
-rw-r--r-- | host.php | 43 | ||||
-rw-r--r-- | inc/collectd.inc.php | 176 | ||||
-rw-r--r-- | inc/html.inc.php | 45 | ||||
-rw-r--r-- | inc/rrdtool.class.php | 25 | ||||
-rw-r--r-- | index.php | 30 | ||||
-rw-r--r-- | layout/style.css | 23 | ||||
-rw-r--r-- | plugin/cpu.php | 65 | ||||
-rw-r--r-- | plugin/df.php | 42 | ||||
-rw-r--r-- | plugin/disk.php | 63 | ||||
-rw-r--r-- | plugin/entropy.php | 37 | ||||
-rw-r--r-- | plugin/interface.php | 54 | ||||
-rw-r--r-- | plugin/irq.php | 40 | ||||
-rw-r--r-- | plugin/load.php | 41 | ||||
-rw-r--r-- | plugin/memory.php | 53 | ||||
-rw-r--r-- | plugin/processes.php | 58 | ||||
-rw-r--r-- | plugin/sensors.php | 58 | ||||
-rw-r--r-- | plugin/swap.php | 50 | ||||
-rw-r--r-- | plugin/users.php | 37 | ||||
-rw-r--r-- | type/Default.class.php | 127 | ||||
-rw-r--r-- | type/GenericIO.class.php | 59 | ||||
-rw-r--r-- | type/GenericStacked.class.php | 65 |
27 files changed, 1312 insertions, 0 deletions
diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..9e0a727 --- /dev/null +++ b/.htaccess | |||
@@ -0,0 +1,2 @@ | |||
1 | RewriteEngine On | ||
2 | RewriteRule ^.git(ignore|/) - [F,L] | ||
diff --git a/conf/.gitignore b/conf/.gitignore new file mode 100644 index 0000000..529bf01 --- /dev/null +++ b/conf/.gitignore | |||
@@ -0,0 +1 @@ | |||
config.local.php | |||
diff --git a/conf/common.inc.php b/conf/common.inc.php new file mode 100644 index 0000000..c4884d6 --- /dev/null +++ b/conf/common.inc.php | |||
@@ -0,0 +1,8 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'config.php'; | ||
4 | |||
5 | $CONFIG['webdir'] = preg_replace('/\/[a-z\.]+$/', '', $_SERVER['SCRIPT_FILENAME']); | ||
6 | $CONFIG['weburl'] = preg_replace('/\/[a-z\.]+$/', '', $_SERVER['SCRIPT_NAME']); | ||
7 | |||
8 | ?> | ||
diff --git a/conf/config.php b/conf/config.php new file mode 100644 index 0000000..4fb7aec --- /dev/null +++ b/conf/config.php | |||
@@ -0,0 +1,19 @@ | |||
1 | <?php | ||
2 | |||
3 | $CONFIG['datadir'] = '/var/lib/collectd/rrd'; | ||
4 | |||
5 | #$CONFIG['cat']['nethuis'] = array('pepper'); | ||
6 | $CONFIG['overview'] = array('load', 'cpu', 'memory', 'swap'); | ||
7 | |||
8 | $CONFIG['groupby'] = array( | ||
9 | 'cpu' => 'type', | ||
10 | 'irq' => 'type', | ||
11 | 'memory' => 'type', | ||
12 | 'processes' => 'type', | ||
13 | 'swap' => 'type', | ||
14 | 'sensors' => 'type', | ||
15 | ); | ||
16 | |||
17 | include 'config.local.php'; | ||
18 | |||
19 | ?> | ||
diff --git a/detail.php b/detail.php new file mode 100644 index 0000000..e12334d --- /dev/null +++ b/detail.php | |||
@@ -0,0 +1,52 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'inc/html.inc.php'; | ||
4 | require_once 'inc/collectd.inc.php'; | ||
5 | |||
6 | $host = $_GET['h']; | ||
7 | $plugin = $_GET['p']; | ||
8 | $pinstance = $_GET['pi']; | ||
9 | $type = $_GET['t']; | ||
10 | $tinstance = $_GET['ti']; | ||
11 | $width = $_GET['x']; | ||
12 | $heigth = $_GET['y']; | ||
13 | $seconds = $_GET['s']; | ||
14 | |||
15 | html_start(); | ||
16 | |||
17 | printf('<h1><a href="%s">«</a> %s</h1>'."\n", | ||
18 | $CONFIG['weburl'].'/host.php?h='.htmlentities($host), $host | ||
19 | ); | ||
20 | |||
21 | $term = array( | ||
22 | '2hour' => 3600*2, | ||
23 | '6hour' => 3600*6, | ||
24 | 'day' => 86400, | ||
25 | 'week' => 86400*7, | ||
26 | 'month' => 86400*31, | ||
27 | 'quarter'=> 86400*31*3, | ||
28 | 'year' => 86400*365, | ||
29 | ); | ||
30 | |||
31 | $args = $_GET; | ||
32 | foreach($term as $key => $s) { | ||
33 | $args['s'] = $s; | ||
34 | printf('<a href="%s/%s">%s</a>'."\n", | ||
35 | $CONFIG['weburl'], build_url('detail.php', $args), $key); | ||
36 | } | ||
37 | |||
38 | print "<br>\n"; | ||
39 | |||
40 | $plugins = collectd_plugins($host); | ||
41 | |||
42 | if(!$plugins) { | ||
43 | echo "Unknown host\n"; | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | # show graph | ||
48 | printf('<img src="%s/%s">'."\n", $CONFIG['weburl'], build_url('graph.php', $_GET)); | ||
49 | |||
50 | html_end(); | ||
51 | |||
52 | ?> | ||
diff --git a/graph.php b/graph.php new file mode 100644 index 0000000..4747552 --- /dev/null +++ b/graph.php | |||
@@ -0,0 +1,39 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'conf/common.inc.php'; | ||
4 | |||
5 | $host = $_GET['h']; | ||
6 | $plugin = $_GET['p']; | ||
7 | $pinstance = $_GET['pi']; | ||
8 | $type = $_GET['t']; | ||
9 | $tinstance = $_GET['ti']; | ||
10 | $width = $_GET['x']; | ||
11 | $heigth = $_GET['y']; | ||
12 | $seconds = $_GET['s']; | ||
13 | |||
14 | if (!preg_match('/^[a-z]+$/', $plugin)) { | ||
15 | die_img('Error: plugin contains unknown characters.'); | ||
16 | exit; | ||
17 | } | ||
18 | |||
19 | if (!file_exists($CONFIG['webdir']."/plugin/$plugin.php")) { | ||
20 | die_img(sprintf('Error: plugin not available (%s).', $plugin)); | ||
21 | exit; | ||
22 | } | ||
23 | |||
24 | include $CONFIG['webdir']."/plugin/$plugin.php"; | ||
25 | |||
26 | |||
27 | function die_img($msg) { | ||
28 | header("Content-Type: image/png"); | ||
29 | $image = ImageCreatetruecolor(300, 30); | ||
30 | $black = ImageColorAllocate($image, 0, 0, 0); | ||
31 | $white = ImageColorAllocate($image, 255, 255, 255); | ||
32 | imagefill($image, 0, 0, $white); | ||
33 | imagerectangle($image, 0, 0, 299, 29, $black); | ||
34 | imagestring($image, 2, 10, 9, $msg, $black); | ||
35 | imagepng($image); | ||
36 | imagedestroy($image); | ||
37 | } | ||
38 | |||
39 | ?> | ||
diff --git a/host.php b/host.php new file mode 100644 index 0000000..22112e6 --- /dev/null +++ b/host.php | |||
@@ -0,0 +1,43 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'inc/html.inc.php'; | ||
4 | require_once 'inc/collectd.inc.php'; | ||
5 | |||
6 | $host = $_GET['h']; | ||
7 | $splugin = $_GET['p']; | ||
8 | |||
9 | html_start(); | ||
10 | |||
11 | printf('<h1><a href="%s">«</a> %s</h1>'."\n", $CONFIG['weburl'], $host); | ||
12 | |||
13 | $plugins = collectd_plugins($host); | ||
14 | |||
15 | if(!$plugins) { | ||
16 | echo "Unknown host\n"; | ||
17 | return false; | ||
18 | } | ||
19 | |||
20 | # first the ones defined in overview | ||
21 | foreach($CONFIG['overview'] as $plugin) { | ||
22 | if (in_array($plugin, $plugins)) { | ||
23 | printf("<h2>[-] %s</h2>\n", $plugin); | ||
24 | graphs_from_plugin($host, $plugin); | ||
25 | } | ||
26 | } | ||
27 | |||
28 | # other plugins | ||
29 | foreach($plugins as $plugin) { | ||
30 | if (!in_array($plugin, $CONFIG['overview'])) { | ||
31 | $url = sprintf('<a href="%s/host.php?h=%s&p=%s">%s</a>'."\n", $CONFIG['weburl'], $host, $plugin, $plugin); | ||
32 | if ($splugin == $plugin) { | ||
33 | printf("<h2>[-] %s</h2>\n", $url); | ||
34 | graphs_from_plugin($host, $plugin); | ||
35 | } else { | ||
36 | printf("<h2>[+] %s</h2>\n", $url); | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | html_end(); | ||
42 | |||
43 | ?> | ||
diff --git a/inc/collectd.inc.php b/inc/collectd.inc.php new file mode 100644 index 0000000..2724c05 --- /dev/null +++ b/inc/collectd.inc.php | |||
@@ -0,0 +1,176 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'conf/common.inc.php'; | ||
4 | |||
5 | # returns an array of all collectd hosts | ||
6 | function collectd_hosts() { | ||
7 | global $CONFIG; | ||
8 | |||
9 | if (!is_dir($CONFIG['datadir'])) | ||
10 | return false; | ||
11 | |||
12 | $dir = scandir($CONFIG['datadir']); | ||
13 | foreach($dir as $k => $v) { | ||
14 | if(!is_dir($CONFIG['datadir'].'/'.$v) || $v == '.' || $v == '..') | ||
15 | unset($dir[$k]); | ||
16 | } | ||
17 | return($dir); | ||
18 | } | ||
19 | |||
20 | # returns an array of plugins/pinstances/types/tinstances | ||
21 | function collectd_plugindata($host) { | ||
22 | global $CONFIG; | ||
23 | |||
24 | if (!is_dir($CONFIG['datadir'].'/'.$host)) | ||
25 | return false; | ||
26 | |||
27 | chdir($CONFIG['datadir'].'/'.$host); | ||
28 | $files = glob("*/*.rrd"); | ||
29 | if (!$files) | ||
30 | return false; | ||
31 | |||
32 | $data; | ||
33 | $i = 0; | ||
34 | foreach($files as $item) { | ||
35 | unset($part); | ||
36 | |||
37 | # split item by plugin/type | ||
38 | $part = explode('/', $item); | ||
39 | $part[1] = preg_replace('/\.rrd/', '', $part[1]); | ||
40 | |||
41 | # plugin | ||
42 | $data[$i]['p'] = preg_replace('/-.+/', '', $part[0]); | ||
43 | |||
44 | # plugin instance | ||
45 | if(preg_match('/-/', $part[0])) | ||
46 | $data[$i]['pi'] = preg_replace('/^[a-z_]+\-/', '', $part[0]); | ||
47 | |||
48 | # type | ||
49 | $data[$i]['t'] = preg_replace('/-.+/', '', $part[1]); | ||
50 | |||
51 | # type instance | ||
52 | if(preg_match('/-/', $part[1])) | ||
53 | $data[$i]['ti'] = preg_replace('/^[a-z_]+\-/', '', $part[1]); | ||
54 | |||
55 | $i++; | ||
56 | } | ||
57 | return($data); | ||
58 | } | ||
59 | |||
60 | # returns an array of all plugins of a host | ||
61 | function collectd_plugins($host) { | ||
62 | $plugindata = collectd_plugindata($host); | ||
63 | |||
64 | $plugins = array(); | ||
65 | foreach ($plugindata as $item) { | ||
66 | if (!in_array($item['p'], $plugins)) | ||
67 | $plugins[] = $item['p']; | ||
68 | } | ||
69 | |||
70 | return $plugins; | ||
71 | } | ||
72 | |||
73 | # returns an array of all pi/t/ti of an plugin | ||
74 | function collectd_plugindetail($host, $plugin, $detail, $where=NULL) { | ||
75 | $details = array('pi', 't', 'ti'); | ||
76 | if (!in_array($detail, $details)) | ||
77 | return false; | ||
78 | |||
79 | $plugindata = collectd_plugindata($host); | ||
80 | |||
81 | $return = array(); | ||
82 | foreach ($plugindata as $item) { | ||
83 | if ($item['p'] == $plugin && !in_array($item[$detail], $return) && isset($item[$detail])) { | ||
84 | if ($where) { | ||
85 | $add = true; | ||
86 | # add detail to returnvalue if all where is true | ||
87 | foreach($where as $key => $value) { | ||
88 | if ($item[$key] != $value) | ||
89 | $add = false; | ||
90 | } | ||
91 | if ($add) | ||
92 | $return[] = $item[$detail]; | ||
93 | } else { | ||
94 | $return[] = $item[$detail]; | ||
95 | } | ||
96 | } | ||
97 | } | ||
98 | |||
99 | if (empty($return)) | ||
100 | return false; | ||
101 | |||
102 | return $return; | ||
103 | } | ||
104 | |||
105 | # generate graph url's for a plugin of a host | ||
106 | function graphs_from_plugin($host, $plugin) { | ||
107 | global $CONFIG; | ||
108 | |||
109 | $pis = collectd_plugindetail($host, $plugin, 'pi'); | ||
110 | $ts = collectd_plugindetail($host, $plugin, 't'); | ||
111 | $tis = collectd_plugindetail($host, $plugin, 'ti'); | ||
112 | if (!$pis) $pis = array('NULL'); | ||
113 | if (!$tis) $tis = array('NULL'); | ||
114 | |||
115 | foreach($pis as $pi) { | ||
116 | if ($CONFIG['groupby'][$plugin] == 'type') { | ||
117 | foreach ($ts as $t) { | ||
118 | $items = array( | ||
119 | 'h' => $host, | ||
120 | 'p' => $plugin, | ||
121 | 'pi' => $pi, | ||
122 | 't' => $t | ||
123 | ); | ||
124 | printf('<a href="%s/%s"><img src="%s/%s"></a>'."\n", | ||
125 | $CONFIG['weburl'], | ||
126 | build_url('detail.php', $items).'&x=800&y=350', | ||
127 | $CONFIG['weburl'], | ||
128 | build_url('graph.php', $items) | ||
129 | ); | ||
130 | } | ||
131 | } else { | ||
132 | foreach ($tis as $ti) { | ||
133 | foreach ($ts as $t) { | ||
134 | $items = array( | ||
135 | 'h' => $host, | ||
136 | 'p' => $plugin, | ||
137 | 'pi' => $pi, | ||
138 | 't' => $t, | ||
139 | 'ti' => $ti | ||
140 | ); | ||
141 | printf('<a href="%s/%s"><img src="%s/%s"></a>'."\n", | ||
142 | $CONFIG['weburl'], | ||
143 | build_url('detail.php', $items).'&x=800&y=350', | ||
144 | $CONFIG['weburl'], | ||
145 | build_url('graph.php', $items) | ||
146 | ); | ||
147 | } | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | # generate an url with GET values from $items | ||
154 | function build_url($base, $items, $s=86400) { | ||
155 | if (!is_array($items)) | ||
156 | return false; | ||
157 | |||
158 | if (!is_numeric($s)) | ||
159 | return false; | ||
160 | |||
161 | $i=0; | ||
162 | foreach ($items as $key => $value) { | ||
163 | # don't include empty values | ||
164 | if ($value == 'NULL') | ||
165 | continue; | ||
166 | |||
167 | $base .= sprintf('%s%s=%s', $i==0 ? '?' : '&', $key, $value); | ||
168 | $i++; | ||
169 | } | ||
170 | if (!isset($items['s'])) | ||
171 | $base .= '&s='.$s; | ||
172 | |||
173 | return $base; | ||
174 | } | ||
175 | |||
176 | ?> | ||
diff --git a/inc/html.inc.php b/inc/html.inc.php new file mode 100644 index 0000000..d1d2a65 --- /dev/null +++ b/inc/html.inc.php | |||
@@ -0,0 +1,45 @@ | |||
1 | <?php | ||
2 | |||
3 | function html_start() { | ||
4 | echo <<<EOT | ||
5 | <!DOCTYPE HTML> | ||
6 | <html> | ||
7 | <head> | ||
8 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | ||
9 | <title>Collectd Graph Panel</title> | ||
10 | <link rel="stylesheet" href="layout/style.css" type="text/css"> | ||
11 | </head> | ||
12 | <body> | ||
13 | |||
14 | EOT; | ||
15 | } | ||
16 | |||
17 | function html_end() { | ||
18 | echo <<<EOT | ||
19 | </body> | ||
20 | </html> | ||
21 | EOT; | ||
22 | } | ||
23 | |||
24 | require_once 'conf/common.inc.php'; | ||
25 | require_once 'inc/rrdtool.class.php'; | ||
26 | function host_summary($hosts) { | ||
27 | global $CONFIG; | ||
28 | |||
29 | $rrd = new RRDTool; | ||
30 | |||
31 | echo "<table class=\"summary\">\n"; | ||
32 | |||
33 | foreach($hosts as $host) { | ||
34 | $rrd_info = $rrd->rrd_info($CONFIG['datadir'].'/'.$host.'/load/load.rrd'); | ||
35 | if (!$rrd_info) | ||
36 | continue; | ||
37 | printf('<tr><th><a href="%s/host.php?h=%s">%s</a></th><td>%.2f</td><td>%.2f</td><td>%.2f</td></tr>'."\n", | ||
38 | $CONFIG['weburl'],$host, $host, | ||
39 | $rrd_info["ds[shortterm].last_ds"], $rrd_info["ds[midterm].last_ds"], $rrd_info["ds[longterm].last_ds"]); | ||
40 | } | ||
41 | |||
42 | echo "</table>\n"; | ||
43 | } | ||
44 | |||
45 | ?> | ||
diff --git a/inc/rrdtool.class.php b/inc/rrdtool.class.php new file mode 100644 index 0000000..e1a7b4b --- /dev/null +++ b/inc/rrdtool.class.php | |||
@@ -0,0 +1,25 @@ | |||
1 | <?php | ||
2 | |||
3 | class RRDTool { | ||
4 | var $width = 175; | ||
5 | var $height = 125; | ||
6 | |||
7 | function rrd_info($rrdfile) { | ||
8 | if (file_exists($rrdfile)) { | ||
9 | $raw_info = shell_exec('/usr/bin/rrdtool info '.$rrdfile); | ||
10 | $raw_array = explode("\n", $raw_info); | ||
11 | foreach ($raw_array as $key => $info) { | ||
12 | if ($info != "") { | ||
13 | $item_info = explode(" = ", $info); | ||
14 | $item_info[1] = preg_replace('/"/', '', $item_info[1]); | ||
15 | $info_array[$item_info[0]] = $item_info[1]; | ||
16 | } | ||
17 | } | ||
18 | return($info_array); | ||
19 | } else { | ||
20 | return false; | ||
21 | } | ||
22 | } | ||
23 | } | ||
24 | |||
25 | ?> | ||
diff --git a/index.php b/index.php new file mode 100644 index 0000000..f937bcc --- /dev/null +++ b/index.php | |||
@@ -0,0 +1,30 @@ | |||
1 | <?php | ||
2 | |||
3 | include_once 'conf/common.inc.php'; | ||
4 | include_once 'inc/collectd.inc.php'; | ||
5 | require_once 'inc/html.inc.php'; | ||
6 | |||
7 | html_start(); | ||
8 | |||
9 | $h = array(); | ||
10 | |||
11 | # show all categorized hosts | ||
12 | foreach($CONFIG['cat'] as $cat => $hosts) { | ||
13 | printf("<h1>%s</h1>\n", $cat); | ||
14 | host_summary($hosts); | ||
15 | $h = array_merge($h, $hosts); | ||
16 | } | ||
17 | |||
18 | # search for uncategorized hosts | ||
19 | $chosts = collectd_hosts(); | ||
20 | $uhosts = array_diff($chosts, $h); | ||
21 | |||
22 | # show all uncategorized hosts | ||
23 | if ($uhosts) { | ||
24 | echo "<h1>uncategorized</h1>\n"; | ||
25 | host_summary($uhosts); | ||
26 | } | ||
27 | |||
28 | html_end(); | ||
29 | |||
30 | ?> | ||
diff --git a/layout/style.css b/layout/style.css new file mode 100644 index 0000000..813f98d --- /dev/null +++ b/layout/style.css | |||
@@ -0,0 +1,23 @@ | |||
1 | h1 { | ||
2 | font-size: 1.5em; | ||
3 | margin: 0.5em 0; | ||
4 | } | ||
5 | |||
6 | h2 { | ||
7 | font-size: 1em; | ||
8 | } | ||
9 | |||
10 | table.summary th { | ||
11 | width: 150px; | ||
12 | font-weight: normal; | ||
13 | text-align: left; | ||
14 | } | ||
15 | |||
16 | table.summary td { | ||
17 | width: 50px; | ||
18 | text-align: right; | ||
19 | } | ||
20 | |||
21 | img { | ||
22 | border: 0; | ||
23 | } | ||
diff --git a/plugin/cpu.php b/plugin/cpu.php new file mode 100644 index 0000000..10fbf56 --- /dev/null +++ b/plugin/cpu.php | |||
@@ -0,0 +1,65 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd CPU plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # cpu-X/ | ||
10 | # cpu-X/cpu-idle.rrd | ||
11 | # cpu-X/cpu-interrupt.rrd | ||
12 | # cpu-X/cpu-nice.rrd | ||
13 | # cpu-X/cpu-softirq.rrd | ||
14 | # cpu-X/cpu-steal.rrd | ||
15 | # cpu-X/cpu-system.rrd | ||
16 | # cpu-X/cpu-user.rrd | ||
17 | # cpu-X/cpu-wait.rrd | ||
18 | |||
19 | # grouped | ||
20 | require_once $CONFIG['webdir'].'/inc/collectd.inc.php'; | ||
21 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
22 | |||
23 | $obj = new Type_GenericStacked; | ||
24 | $obj->datadir = $CONFIG['datadir']; | ||
25 | $obj->path_format = '{host}/{plugin}-{pinstance}/{type}-{tinstance}.rrd'; | ||
26 | $obj->args = array( | ||
27 | 'host' => $host, | ||
28 | 'plugin' => $plugin, | ||
29 | 'pinstance' => $pinstance, | ||
30 | 'type' => $type, | ||
31 | 'tinstance' => $tinstance, | ||
32 | ); | ||
33 | $obj->data_sources = array('value'); | ||
34 | $obj->order = array('idle', 'nice', 'user', 'wait', 'system', 'softirq', 'interrupt', 'steal'); | ||
35 | $obj->ds_names = array( | ||
36 | 'idle' => 'Idle ', | ||
37 | 'nice' => 'Nice ', | ||
38 | 'user' => 'User ', | ||
39 | 'wait' => 'Wait-IO', | ||
40 | 'system' => 'System ', | ||
41 | 'softirq' => 'SoftIRQ', | ||
42 | 'interrupt' => 'IRQ ', | ||
43 | 'steal' => 'Steal ', | ||
44 | ); | ||
45 | $obj->colors = array( | ||
46 | 'idle' => 'e8e8e8', | ||
47 | 'nice' => '00e000', | ||
48 | 'user' => '0000ff', | ||
49 | 'wait' => 'ffb000', | ||
50 | 'system' => 'ff0000', | ||
51 | 'softirq' => 'ff00ff', | ||
52 | 'interrupt' => 'a000a0', | ||
53 | 'steal' => '000000', | ||
54 | ); | ||
55 | $obj->width = $width; | ||
56 | $obj->heigth = $heigth; | ||
57 | $obj->seconds = $seconds; | ||
58 | |||
59 | $obj->rrd_title = "CPU-$pinstance usage on $host"; | ||
60 | $obj->rrd_vertical = 'Jiffies'; | ||
61 | $obj->rrd_format = '%5.2lf'; | ||
62 | |||
63 | $obj->rrd_graph(); | ||
64 | |||
65 | ?> | ||
diff --git a/plugin/df.php b/plugin/df.php new file mode 100644 index 0000000..6398249 --- /dev/null +++ b/plugin/df.php | |||
@@ -0,0 +1,42 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Df plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | # LAYOUT | ||
9 | # | ||
10 | # df/ | ||
11 | # df/df-XXXX.rrd | ||
12 | |||
13 | $obj = new Type_GenericStacked; | ||
14 | $obj->datadir = $CONFIG['datadir']; | ||
15 | $obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
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'); | ||
24 | $obj->ds_names = array( | ||
25 | 'free' => 'Free', | ||
26 | 'used' => 'Used', | ||
27 | ); | ||
28 | $obj->colors = array( | ||
29 | 'free' => '00ff00', | ||
30 | 'used' => 'ff0000', | ||
31 | ); | ||
32 | $obj->width = $width; | ||
33 | $obj->heigth = $heigth; | ||
34 | $obj->seconds = $seconds; | ||
35 | |||
36 | $obj->rrd_title = "Free space ($tinstance) on $host"; | ||
37 | $obj->rrd_vertical = 'Bytes'; | ||
38 | $obj->rrd_format = '%5.1lf%sB'; | ||
39 | |||
40 | $obj->rrd_graph(); | ||
41 | |||
42 | ?> | ||
diff --git a/plugin/disk.php b/plugin/disk.php new file mode 100644 index 0000000..298c179 --- /dev/null +++ b/plugin/disk.php | |||
@@ -0,0 +1,63 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Disk plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericIO.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # disk-XXXX/ | ||
10 | # disk-XXXX/disk_merged.rrd | ||
11 | # disk-XXXX/disk_octets.rrd | ||
12 | # disk-XXXX/disk_ops.rrd | ||
13 | # disk-XXXX/disk_time.rrd | ||
14 | |||
15 | $obj = new Type_GenericIO; | ||
16 | $obj->datadir = $CONFIG['datadir']; | ||
17 | $obj->path_format = '{host}/{plugin}-{pinstance}/{type}.rrd'; | ||
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'); | ||
26 | $obj->ds_names = array( | ||
27 | 'read' => 'Read ', | ||
28 | 'write' => 'Written', | ||
29 | ); | ||
30 | $obj->colors = array( | ||
31 | 'read' => '0000ff', | ||
32 | 'write' => '00b000', | ||
33 | ); | ||
34 | $obj->width = $width; | ||
35 | $obj->heigth = $heigth; | ||
36 | $obj->seconds = $seconds; | ||
37 | switch($type) { | ||
38 | case 'disk_merged': | ||
39 | $obj->rrd_title = "Disk Merged Operations ($pinstance) on $host"; | ||
40 | $obj->rrd_vertical = 'Merged operations/s'; | ||
41 | $obj->rrd_format = '%5.1lf'; | ||
42 | break; | ||
43 | case 'disk_octets': | ||
44 | $obj->rrd_title = "Disk Traffic ($pinstance) on $host"; | ||
45 | $obj->rrd_vertical = 'Bytes per second'; | ||
46 | $obj->rrd_format = '%5.1lf%s'; | ||
47 | break; | ||
48 | case 'disk_ops': | ||
49 | $obj->rrd_title = "Disk Operations ($pinstance) on $host"; | ||
50 | $obj->rrd_vertical = 'Ops per second'; | ||
51 | $obj->rrd_format = '%5.1lf'; | ||
52 | break; | ||
53 | case 'disk_time': | ||
54 | $obj->rrd_title = "Disk time per operation ($pinstance) on $host"; | ||
55 | $obj->rrd_vertical = 'Avg. Time/Op'; | ||
56 | $obj->rrd_format = '%5.1lf%ss'; | ||
57 | $obj->scale = '0.001'; | ||
58 | break; | ||
59 | } | ||
60 | |||
61 | $obj->rrd_graph(); | ||
62 | |||
63 | ?> | ||
diff --git a/plugin/entropy.php b/plugin/entropy.php new file mode 100644 index 0000000..55159dc --- /dev/null +++ b/plugin/entropy.php | |||
@@ -0,0 +1,37 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Entropy plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/Default.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # entropy/entropy.rrd | ||
10 | |||
11 | $obj = new Type_Default; | ||
12 | $obj->datadir = $CONFIG['datadir']; | ||
13 | $obj->path_format = '{host}/{plugin}/{type}.rrd'; | ||
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'); | ||
22 | $obj->ds_names = array( | ||
23 | 'entropy' => 'Entropy bits', | ||
24 | ); | ||
25 | $obj->colors = array( | ||
26 | 'entropy' => '0000f0', | ||
27 | ); | ||
28 | $obj->width = $width; | ||
29 | $obj->heigth = $heigth; | ||
30 | $obj->seconds = $seconds; | ||
31 | $obj->rrd_title = "Available entropy on $host"; | ||
32 | $obj->rrd_vertical = 'Bits'; | ||
33 | $obj->rrd_format = '%4.0lf'; | ||
34 | |||
35 | $obj->rrd_graph(); | ||
36 | |||
37 | ?> | ||
diff --git a/plugin/interface.php b/plugin/interface.php new file mode 100644 index 0000000..2f345f9 --- /dev/null +++ b/plugin/interface.php | |||
@@ -0,0 +1,54 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Interface plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericIO.class.php'; | ||
7 | |||
8 | # LAYOUT | ||
9 | # interface/ | ||
10 | # interface/if_errors-XXXX.rrd | ||
11 | # interface/if_octets-XXXX.rrd | ||
12 | # interface/if_packets-XXXX.rrd | ||
13 | |||
14 | $obj = new Type_GenericIO; | ||
15 | $obj->datadir = $CONFIG['datadir']; | ||
16 | $obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
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'); | ||
25 | $obj->ds_names = array( | ||
26 | 'rx' => 'Receive ', | ||
27 | 'tx' => 'Transmit', | ||
28 | ); | ||
29 | $obj->colors = array( | ||
30 | 'rx' => '0000ff', | ||
31 | 'tx' => '00b000', | ||
32 | ); | ||
33 | $obj->width = $width; | ||
34 | $obj->heigth = $heigth; | ||
35 | $obj->seconds = $seconds; | ||
36 | $obj->rrd_format = '%5.1lf%s'; | ||
37 | switch($type) { | ||
38 | case 'if_errors': | ||
39 | $obj->rrd_title = "Interface Errors ($tinstance) on $host"; | ||
40 | $obj->rrd_vertical = 'Errors per second'; | ||
41 | break; | ||
42 | case 'if_octets': | ||
43 | $obj->rrd_title = "Interface Traffic ($tinstance) on $host"; | ||
44 | $obj->rrd_vertical = 'Bits per second'; | ||
45 | break; | ||
46 | case 'if_packets': | ||
47 | $obj->rrd_title = "Interface Packets ($tinstance) on $host"; | ||
48 | $obj->rrd_vertical = 'Packets per second'; | ||
49 | break; | ||
50 | } | ||
51 | |||
52 | $obj->rrd_graph(); | ||
53 | |||
54 | ?> | ||
diff --git a/plugin/irq.php b/plugin/irq.php new file mode 100644 index 0000000..2759c0e --- /dev/null +++ b/plugin/irq.php | |||
@@ -0,0 +1,40 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd IRQ plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # irq/ | ||
10 | # irq/irq-XX.rrd | ||
11 | |||
12 | # grouped | ||
13 | require_once $CONFIG['webdir'].'/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->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
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 = NULL; | ||
29 | $obj->colors = NULL; | ||
30 | $obj->width = $width; | ||
31 | $obj->heigth = $heigth; | ||
32 | $obj->seconds = $seconds; | ||
33 | |||
34 | $obj->rrd_title = "Interrupts on $host"; | ||
35 | $obj->rrd_vertical = 'IRQs/s'; | ||
36 | $obj->rrd_format = '%6.1lf'; | ||
37 | |||
38 | $obj->rrd_graph(); | ||
39 | |||
40 | ?> | ||
diff --git a/plugin/load.php b/plugin/load.php new file mode 100644 index 0000000..d7db740 --- /dev/null +++ b/plugin/load.php | |||
@@ -0,0 +1,41 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Load plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/Default.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # load/load.rrd | ||
10 | |||
11 | $obj = new Type_Default; | ||
12 | $obj->datadir = $CONFIG['datadir']; | ||
13 | $obj->path_format = '{host}/{plugin}/{type}.rrd'; | ||
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'); | ||
22 | $obj->ds_names = array( | ||
23 | 'shortterm' => ' 1 min', | ||
24 | 'midterm' => ' 5 min', | ||
25 | 'longterm' => '15 min', | ||
26 | ); | ||
27 | $obj->colors = array( | ||
28 | 'shortterm' => '00ff00', | ||
29 | 'midterm' => '0000ff', | ||
30 | 'longterm' => 'ff0000', | ||
31 | ); | ||
32 | $obj->width = $width; | ||
33 | $obj->heigth = $heigth; | ||
34 | $obj->seconds = $seconds; | ||
35 | $obj->rrd_title = "System load on $host"; | ||
36 | $obj->rrd_vertical = 'System load'; | ||
37 | $obj->rrd_format = '%.2lf'; | ||
38 | |||
39 | $obj->rrd_graph(); | ||
40 | |||
41 | ?> | ||
diff --git a/plugin/memory.php b/plugin/memory.php new file mode 100644 index 0000000..7944238 --- /dev/null +++ b/plugin/memory.php | |||
@@ -0,0 +1,53 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Memory plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # memory/ | ||
10 | # memory/memory-buffered.rrd | ||
11 | # memory/memory-cached.rrd | ||
12 | # memory/memory-free.rrd | ||
13 | # memory/memory-used.rrd | ||
14 | |||
15 | # grouped | ||
16 | require_once $CONFIG['webdir'].'/inc/collectd.inc.php'; | ||
17 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
18 | |||
19 | $obj = new Type_GenericStacked; | ||
20 | $obj->datadir = $CONFIG['datadir']; | ||
21 | $obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
22 | $obj->args = array( | ||
23 | 'host' => $host, | ||
24 | 'plugin' => $plugin, | ||
25 | 'pinstance' => $pinstance, | ||
26 | 'type' => $type, | ||
27 | 'tinstance' => $tinstance, | ||
28 | ); | ||
29 | $obj->data_sources = array('value'); | ||
30 | $obj->order = array('free', 'buffered', 'cached', 'used'); | ||
31 | $obj->ds_names = array( | ||
32 | 'free' => 'Free ', | ||
33 | 'cached' => 'Cached ', | ||
34 | 'buffered' => 'Buffered', | ||
35 | 'used' => 'Used ', | ||
36 | ); | ||
37 | $obj->colors = array( | ||
38 | 'free' => '00e000', | ||
39 | 'cached' => '0000ff', | ||
40 | 'buffered' => 'ffb000', | ||
41 | 'used' => 'ff0000', | ||
42 | ); | ||
43 | $obj->width = $width; | ||
44 | $obj->heigth = $heigth; | ||
45 | $obj->seconds = $seconds; | ||
46 | |||
47 | $obj->rrd_title = "Physical memory utilization on $host"; | ||
48 | $obj->rrd_vertical = 'Bytes'; | ||
49 | $obj->rrd_format = '%5.1lf%s'; | ||
50 | |||
51 | $obj->rrd_graph(); | ||
52 | |||
53 | ?> | ||
diff --git a/plugin/processes.php b/plugin/processes.php new file mode 100644 index 0000000..445e1e4 --- /dev/null +++ b/plugin/processes.php | |||
@@ -0,0 +1,58 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd CPU plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # processes/ | ||
10 | # processes/ps_state-paging.rrd | ||
11 | # processes/ps_state-blocked.rrd | ||
12 | # processes/ps_state-zombies.rrd | ||
13 | # processes/ps_state-stopped.rrd | ||
14 | # processes/ps_state-running.rrd | ||
15 | # processes/ps_state-sleeping.rrd | ||
16 | |||
17 | # grouped | ||
18 | require_once $CONFIG['webdir'].'/inc/collectd.inc.php'; | ||
19 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
20 | |||
21 | $obj = new Type_GenericStacked; | ||
22 | $obj->datadir = $CONFIG['datadir']; | ||
23 | $obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
24 | $obj->args = array( | ||
25 | 'host' => $host, | ||
26 | 'plugin' => $plugin, | ||
27 | 'pinstance' => $pinstance, | ||
28 | 'type' => $type, | ||
29 | 'tinstance' => $tinstance, | ||
30 | ); | ||
31 | $obj->data_sources = array('value'); | ||
32 | $obj->ds_names = array( | ||
33 | 'paging' => 'Paging ', | ||
34 | 'blocked' => 'Blocked ', | ||
35 | 'zombies' => 'Zombies ', | ||
36 | 'stopped' => 'Stopped ', | ||
37 | 'running' => 'Running ', | ||
38 | 'sleeping' => 'Sleeping', | ||
39 | ); | ||
40 | $obj->colors = array( | ||
41 | 'paging' => 'ffb000', | ||
42 | 'blocked' => 'ff00ff', | ||
43 | 'zombies' => 'ff0000', | ||
44 | 'stopped' => 'a000a0', | ||
45 | 'running' => '00e000', | ||
46 | 'sleeping' => '0000ff', | ||
47 | ); | ||
48 | $obj->width = $width; | ||
49 | $obj->heigth = $heigth; | ||
50 | $obj->seconds = $seconds; | ||
51 | |||
52 | $obj->rrd_title = "Processes on $host"; | ||
53 | $obj->rrd_vertical = 'Processes'; | ||
54 | $obj->rrd_format = '%5.1lf%s'; | ||
55 | |||
56 | $obj->rrd_graph(); | ||
57 | |||
58 | ?> | ||
diff --git a/plugin/sensors.php b/plugin/sensors.php new file mode 100644 index 0000000..ad43378 --- /dev/null +++ b/plugin/sensors.php | |||
@@ -0,0 +1,58 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Sensors plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/Default.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # disk-XXXX/ | ||
10 | # disk-XXXX/fanspeed-XXXX.rrd | ||
11 | # disk-XXXX/temerature-XXXX.rrd | ||
12 | # disk-XXXX/voltage-XXXX.rrd | ||
13 | |||
14 | # grouped | ||
15 | require_once $CONFIG['webdir'].'/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->path_format = '{host}/{plugin}-{pinstance}/{type}-{tinstance}.rrd'; | ||
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->ds_names = array( | ||
30 | 'value' => 'Value ', | ||
31 | ); | ||
32 | $obj->width = $width; | ||
33 | $obj->heigth = $heigth; | ||
34 | $obj->seconds = $seconds; | ||
35 | switch($type) { | ||
36 | case 'fanspeed': | ||
37 | $obj->colors = '00ff00'; | ||
38 | $obj->rrd_title = "Fanspeed ($pinstance) on $host"; | ||
39 | $obj->rrd_vertical = 'RPM'; | ||
40 | $obj->rrd_format = '%5.1lf'; | ||
41 | break; | ||
42 | case 'temperature': | ||
43 | $obj->colors = '0000ff'; | ||
44 | $obj->rrd_title = "Temperature ($pinstance) on $host"; | ||
45 | $obj->rrd_vertical = 'Celius'; | ||
46 | $obj->rrd_format = '%5.1lf%s'; | ||
47 | break; | ||
48 | case 'voltage': | ||
49 | $obj->colors = 'ff0000'; | ||
50 | $obj->rrd_title = "Voltage ($pinstance) on $host"; | ||
51 | $obj->rrd_vertical = 'Volt'; | ||
52 | $obj->rrd_format = '%5.1lf'; | ||
53 | break; | ||
54 | } | ||
55 | |||
56 | $obj->rrd_graph(); | ||
57 | |||
58 | ?> | ||
diff --git a/plugin/swap.php b/plugin/swap.php new file mode 100644 index 0000000..dfd9ba1 --- /dev/null +++ b/plugin/swap.php | |||
@@ -0,0 +1,50 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Swap plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/GenericStacked.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # swap/ | ||
10 | # swap/swap-cached.rrd | ||
11 | # swap/swap-free.rrd | ||
12 | # swap/swap-used.rrd | ||
13 | |||
14 | # grouped | ||
15 | require_once $CONFIG['webdir'].'/inc/collectd.inc.php'; | ||
16 | $tinstance = collectd_plugindetail($host, $plugin, 'ti'); | ||
17 | |||
18 | $obj = new Type_GenericStacked; | ||
19 | $obj->datadir = $CONFIG['datadir']; | ||
20 | $obj->path_format = '{host}/{plugin}/{type}-{tinstance}.rrd'; | ||
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', 'cached', 'used'); | ||
30 | $obj->ds_names = array( | ||
31 | 'free' => 'Free ', | ||
32 | 'cached' => 'Cached ', | ||
33 | 'used' => 'Used ', | ||
34 | ); | ||
35 | $obj->colors = array( | ||
36 | 'free' => '00e000', | ||
37 | 'cached' => '0000ff', | ||
38 | 'used' => 'ff0000', | ||
39 | ); | ||
40 | $obj->width = $width; | ||
41 | $obj->heigth = $heigth; | ||
42 | $obj->seconds = $seconds; | ||
43 | |||
44 | $obj->rrd_title = "Swap utilization on $host"; | ||
45 | $obj->rrd_vertical = 'Bytes'; | ||
46 | $obj->rrd_format = '%5.1lf%s'; | ||
47 | |||
48 | $obj->rrd_graph(); | ||
49 | |||
50 | ?> | ||
diff --git a/plugin/users.php b/plugin/users.php new file mode 100644 index 0000000..dfcaee3 --- /dev/null +++ b/plugin/users.php | |||
@@ -0,0 +1,37 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Users plugin | ||
4 | |||
5 | require_once $CONFIG['webdir'].'/conf/config.php'; | ||
6 | require_once $CONFIG['webdir'].'/type/Default.class.php'; | ||
7 | |||
8 | ## LAYOUT | ||
9 | # users/users.rrd | ||
10 | |||
11 | $obj = new Type_Default; | ||
12 | $obj->datadir = $CONFIG['datadir']; | ||
13 | $obj->path_format = '{host}/{plugin}/{type}.rrd'; | ||
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'); | ||
22 | $obj->ds_names = array( | ||
23 | 'users' => 'Users', | ||
24 | ); | ||
25 | $obj->colors = array( | ||
26 | 'users' => '0000f0', | ||
27 | ); | ||
28 | $obj->width = $width; | ||
29 | $obj->heigth = $heigth; | ||
30 | $obj->seconds = $seconds; | ||
31 | $obj->rrd_title = "Users on $host"; | ||
32 | $obj->rrd_vertical = 'Users'; | ||
33 | $obj->rrd_format = '%.1lf'; | ||
34 | |||
35 | $obj->rrd_graph(); | ||
36 | |||
37 | ?> | ||
diff --git a/type/Default.class.php b/type/Default.class.php new file mode 100644 index 0000000..8a5dd72 --- /dev/null +++ b/type/Default.class.php | |||
@@ -0,0 +1,127 @@ | |||
1 | <?php | ||
2 | |||
3 | # Collectd Default type | ||
4 | |||
5 | class Type_Default { | ||
6 | var $datadir; | ||
7 | var $args; | ||
8 | var $data_sources; | ||
9 | var $order; | ||
10 | var $ds_names; | ||
11 | var $colors; | ||
12 | var $rrd_title; | ||
13 | var $rrd_vertical; | ||
14 | var $rrd_format; | ||
15 | var $scale; | ||
16 | var $width; | ||
17 | var $heigth; | ||
18 | |||
19 | function validate_color($color) { | ||
20 | if (!preg_match('/^[0-9a-f]{6}$/', $color)) | ||
21 | return '000000'; | ||
22 | else | ||
23 | return $color; | ||
24 | } | ||
25 | |||
26 | function get_faded_color($fgc, $bgc='ffffff', $percent=0.25) { | ||
27 | $fgc = $this->validate_color($fgc); | ||
28 | if (!is_numeric($percent)) | ||
29 | $percent=0.25; | ||
30 | |||
31 | $rgb = array('r', 'g', 'b'); | ||
32 | |||
33 | $fg[r] = hexdec(substr($fgc,0,2)); | ||
34 | $fg[g] = hexdec(substr($fgc,2,2)); | ||
35 | $fg[b] = hexdec(substr($fgc,4,2)); | ||
36 | $bg[r] = hexdec(substr($bgc,0,2)); | ||
37 | $bg[g] = hexdec(substr($bgc,2,2)); | ||
38 | $bg[b] = hexdec(substr($bgc,4,2)); | ||
39 | |||
40 | foreach ($rgb as $pri) { | ||
41 | $c[$pri] = dechex(round($percent * $fg[$pri]) + ((1.0 - $percent) * $bg[$pri])); | ||
42 | if ($c[$pri] == '0') | ||
43 | $c[$pri] = '00'; | ||
44 | } | ||
45 | |||
46 | return $c[r].$c[g].$c[b]; | ||
47 | } | ||
48 | |||
49 | function get_filename($tinstance=NULL) { | ||
50 | if (!is_array($this->args['tinstance']) && $tinstance == NULL) | ||
51 | $tinstance = $this->args['tinstance']; | ||
52 | |||
53 | $search = array('{host}', '{plugin}', '{pinstance}', '{type}', '{tinstance}'); | ||
54 | $replace = array($this->args['host'], $this->args['plugin'], $this->args['pinstance'], $this->args['type'], $tinstance); | ||
55 | $f = $this->datadir . '/' . str_replace($search, $replace, $this->path_format); | ||
56 | return $f; | ||
57 | } | ||
58 | |||
59 | function rrd_graph($debug=false) { | ||
60 | $graphdata = $this->rrd_gen_graph(); | ||
61 | |||
62 | if(!$debug) { | ||
63 | # caching | ||
64 | header("Expires: " . date(DATE_RFC822,strtotime("90 seconds"))); | ||
65 | header("content-type: image/png"); | ||
66 | $graphdata = implode(' ', $graphdata); | ||
67 | echo `$graphdata`; | ||
68 | } else { | ||
69 | print '<pre>'; | ||
70 | print_r($graphdata); | ||
71 | print '</pre>'; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | function rrd_gen_graph() { | ||
76 | $filename = $this->get_filename(); | ||
77 | |||
78 | $rrdgraph[] = '/usr/bin/rrdtool graph - -a PNG'; | ||
79 | $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); | ||
80 | $rrdgraph[] = sprintf('-h %d', is_numeric($this->heigth) ? $this->heigth : 175); | ||
81 | $rrdgraph[] = '-l 0'; | ||
82 | $rrdgraph[] = sprintf('-t "%s"', $this->rrd_title); | ||
83 | $rrdgraph[] = sprintf('-v "%s"', $this->rrd_vertical); | ||
84 | $rrdgraph[] = sprintf('-s -%d', is_numeric($this->seconds) ? $this->seconds : 86400); | ||
85 | |||
86 | if (is_array($this->args['tinstance'])) | ||
87 | $array = is_array($this->order) ? $this->order : $this->args['tinstance']; | ||
88 | else | ||
89 | $array = $this->data_sources; | ||
90 | |||
91 | $i=0; | ||
92 | foreach ($array as $value) { | ||
93 | if (is_array($this->args['tinstance'])) { | ||
94 | $filename = $this->get_filename($value); | ||
95 | $ds = $this->data_sources[0]; | ||
96 | } else { | ||
97 | $filename = $this->get_filename(); | ||
98 | $ds = $value; | ||
99 | } | ||
100 | $rrdgraph[] = sprintf('DEF:min%s=%s:%s:MIN', $i, $filename, $ds); | ||
101 | $rrdgraph[] = sprintf('DEF:avg%s=%s:%s:AVERAGE', $i, $filename, $ds); | ||
102 | $rrdgraph[] = sprintf('DEF:max%s=%s:%s:MAX', $i, $filename, $ds); | ||
103 | $i++; | ||
104 | } | ||
105 | |||
106 | if (!is_array($this->args['tinstance'])) { | ||
107 | $rrdgraph[] = sprintf('AREA:max0#%s', $this->get_faded_color($this->colors[$this->data_sources[0]])); | ||
108 | $rrdgraph[] = sprintf('AREA:min0#%s', 'ffffff'); | ||
109 | } | ||
110 | |||
111 | $i=0; | ||
112 | foreach ($array as $value) { | ||
113 | $dsname = $this->ds_names[$value] != '' ? $this->ds_names[$value] : $value; | ||
114 | $color = is_array($this->colors) ? $this->colors[$value]: $this->colors; | ||
115 | $rrdgraph[] = sprintf('LINE1:avg%d#%s:\'%s\'', $i, $this->validate_color($color), $dsname); | ||
116 | $rrdgraph[] = sprintf('GPRINT:min%d:MIN:\'%s Min,\'', $i, $this->rrd_format); | ||
117 | $rrdgraph[] = sprintf('GPRINT:avg%d:AVERAGE:\'%s Avg,\'', $i, $this->rrd_format); | ||
118 | $rrdgraph[] = sprintf('GPRINT:max%d:MAX:\'%s Max,\'', $i, $this->rrd_format); | ||
119 | $rrdgraph[] = sprintf('GPRINT:avg%d:LAST:\'%s Last\\l\'', $i, $this->rrd_format); | ||
120 | $i++; | ||
121 | } | ||
122 | |||
123 | return $rrdgraph; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | ?> | ||
diff --git a/type/GenericIO.class.php b/type/GenericIO.class.php new file mode 100644 index 0000000..573abde --- /dev/null +++ b/type/GenericIO.class.php | |||
@@ -0,0 +1,59 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'Default.class.php'; | ||
4 | |||
5 | class Type_GenericIO extends Type_Default { | ||
6 | |||
7 | function rrd_gen_graph() { | ||
8 | $filename = $this->get_filename(); | ||
9 | |||
10 | $rrdgraph[] = '/usr/bin/rrdtool graph - -a PNG'; | ||
11 | $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); | ||
12 | $rrdgraph[] = sprintf('-h %d', is_numeric($this->heigth) ? $this->heigth : 175); | ||
13 | $rrdgraph[] = '-l 0'; | ||
14 | $rrdgraph[] = sprintf('-t "%s"', $this->rrd_title); | ||
15 | $rrdgraph[] = sprintf('-v "%s"', $this->rrd_vertical); | ||
16 | $rrdgraph[] = sprintf('-s -%d', is_numeric($this->seconds) ? $this->seconds : 86400); | ||
17 | |||
18 | if ($this->scale) | ||
19 | $raw = '_raw'; | ||
20 | foreach($this->data_sources as $ds) { | ||
21 | $rrdgraph[] = sprintf('DEF:min_%s%s=%s:%s:MIN', $ds, $raw, $filename, $ds); | ||
22 | $rrdgraph[] = sprintf('DEF:avg_%s%s=%s:%s:AVERAGE', $ds, $raw, $filename, $ds); | ||
23 | $rrdgraph[] = sprintf('DEF:max_%s%s=%s:%s:MAX', $ds, $raw, $filename, $ds); | ||
24 | } | ||
25 | if ($this->scale) { | ||
26 | foreach($this->data_sources as $ds) { | ||
27 | $rrdgraph[] = sprintf('CDEF:min_%s=min_%s_raw,%s,*', $ds, $ds, $this->scale); | ||
28 | $rrdgraph[] = sprintf('CDEF:avg_%s=avg_%s_raw,%s,*', $ds, $ds, $this->scale); | ||
29 | $rrdgraph[] = sprintf('CDEF:max_%s=max_%s_raw,%s,*', $ds, $ds, $this->scale); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | $rrdgraph[] = sprintf('CDEF:overlap=avg_%s,avg_%s,LT,avg_%1$s,avg_%2$s,IF', | ||
34 | $this->data_sources[0], $this->data_sources[1]); | ||
35 | |||
36 | foreach($this->data_sources as $ds) { | ||
37 | $rrdgraph[] = sprintf('AREA:avg_%s#%s', $ds, $this->get_faded_color($this->colors[$ds])); | ||
38 | } | ||
39 | |||
40 | $rrdgraph[] = sprintf('AREA:overlap#%s', | ||
41 | $this->get_faded_color( | ||
42 | $this->get_faded_color($this->colors[$this->data_sources[0]]), | ||
43 | $this->get_faded_color($this->colors[$this->data_sources[1]]) | ||
44 | ) | ||
45 | ); | ||
46 | |||
47 | foreach($this->data_sources as $ds) { | ||
48 | $rrdgraph[] = sprintf('LINE1:avg_%s#%s:\'%s\'', $ds, $this->colors[$ds], $this->ds_names[$ds]); | ||
49 | $rrdgraph[] = sprintf('GPRINT:min_%s:MIN:\'%s Min,\'', $ds, $this->rrd_format); | ||
50 | $rrdgraph[] = sprintf('GPRINT:avg_%s:AVERAGE:\'%s Avg,\'', $ds, $this->rrd_format); | ||
51 | $rrdgraph[] = sprintf('GPRINT:max_%s:MAX:\'%s Max,\'', $ds, $this->rrd_format); | ||
52 | $rrdgraph[] = sprintf('GPRINT:avg_%s:LAST:\'%s Last\l\'', $ds, $this->rrd_format); | ||
53 | } | ||
54 | |||
55 | return $rrdgraph; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | ?> | ||
diff --git a/type/GenericStacked.class.php b/type/GenericStacked.class.php new file mode 100644 index 0000000..99f05eb --- /dev/null +++ b/type/GenericStacked.class.php | |||
@@ -0,0 +1,65 @@ | |||
1 | <?php | ||
2 | |||
3 | require_once 'Default.class.php'; | ||
4 | |||
5 | class Type_GenericStacked extends Type_Default { | ||
6 | |||
7 | function rrd_gen_graph() { | ||
8 | $rrdgraph[] = '/usr/bin/rrdtool graph - -a PNG'; | ||
9 | $rrdgraph[] = sprintf('-w %d', is_numeric($this->width) ? $this->width : 400); | ||
10 | $rrdgraph[] = sprintf('-h %d', is_numeric($this->heigth) ? $this->heigth : 175); | ||
11 | $rrdgraph[] = '-l 0'; | ||
12 | $rrdgraph[] = sprintf('-t "%s"', $this->rrd_title); | ||
13 | $rrdgraph[] = sprintf('-v "%s"', $this->rrd_vertical); | ||
14 | $rrdgraph[] = sprintf('-s -%d', is_numeric($this->seconds) ? $this->seconds : 86400); | ||
15 | |||
16 | if (is_array($this->args['tinstance'])) | ||
17 | $array = is_array($this->order) ? $this->order : $this->args['tinstance']; | ||
18 | else | ||
19 | $array = $this->data_sources; | ||
20 | |||
21 | $i=0; | ||
22 | foreach ($array as $value) { | ||
23 | if (is_array($this->args['tinstance'])) { | ||
24 | $filename = $this->get_filename($value); | ||
25 | $ds = $this->data_sources[0]; | ||
26 | } else { | ||
27 | $filename = $this->get_filename(); | ||
28 | $ds = $value; | ||
29 | } | ||
30 | $rrdgraph[] = sprintf('DEF:min%s=%s:%s:MIN', $i, $filename, $ds); | ||
31 | $rrdgraph[] = sprintf('DEF:avg%s=%s:%s:AVERAGE', $i, $filename, $ds); | ||
32 | $rrdgraph[] = sprintf('DEF:max%s=%s:%s:MAX', $i, $filename, $ds); | ||
33 | $i++; | ||
34 | } | ||
35 | |||
36 | for ($i=count($array)-1 ; $i>=0 ; $i--) { | ||
37 | if ($i == (count($array)-1)) | ||
38 | $rrdgraph[] = sprintf('CDEF:cdef%d=avg%d', $i, $i); | ||
39 | else | ||
40 | $rrdgraph[] = sprintf('CDEF:cdef%d=cdef%d,avg%d,+', $i, $i+1, $i); | ||
41 | } | ||
42 | |||
43 | $i=0; | ||
44 | foreach ($array as $value) { | ||
45 | $color = $this->get_faded_color($this->colors[$value]); | ||
46 | $rrdgraph[] = sprintf('AREA:cdef%d#%s', $i, $color); | ||
47 | $i++; | ||
48 | } | ||
49 | |||
50 | $i=0; | ||
51 | foreach ($array as $value) { | ||
52 | $dsname = $this->ds_names[$value] != '' ? $this->ds_names[$value] : $value; | ||
53 | $rrdgraph[] = sprintf('LINE1:cdef%d#%s:\'%s\'', $i, $this->validate_color($this->colors[$value]), $dsname); | ||
54 | $rrdgraph[] = sprintf('GPRINT:min%d:MIN:\'%s Min,\'', $i, $this->rrd_format); | ||
55 | $rrdgraph[] = sprintf('GPRINT:avg%d:AVERAGE:\'%s Avg,\'', $i, $this->rrd_format); | ||
56 | $rrdgraph[] = sprintf('GPRINT:max%d:MAX:\'%s Max,\'', $i, $this->rrd_format); | ||
57 | $rrdgraph[] = sprintf('GPRINT:avg%d:LAST:\'%s Last\\l\'', $i, $this->rrd_format); | ||
58 | $i++; | ||
59 | } | ||
60 | |||
61 | return $rrdgraph; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | ?> | ||