add a LICENSE and a README to things are all nice at GitHub :)
[php-utility-classes.git] / examples / rrd / rrd-config.inc.php
CommitLineData
4a778b7e 1<?php
2// RRD info for CPU info
3$rrd_info = array();
4$rrd_info['*']['graph']['path'] = 'graphs';
5// $rrd_info['*']['page']['graph_url'] = 'http://127.0.0.1/testbed/rrd/';
6$rrd_info['*']['graph']['units_length'] = 6;
7// $rrd_info['*']['graph']['force_recreate'] = true;
8
9$rrd_info['index']['page']['type'] = 'index';
10// $rrd_info['index']['page']['index_ids'] = 'hd,-hd.root';
11// $rrd_info['index']['page']['scan_config'] = false;
12$rrd_info['index']['page']['scan_files'] = true;
13$rrd_info['index']['hidden'] = true;
14
15$rrd_info['overview']['page']['type'] = 'overview';
4d8d65db 16$rrd_info['overview']['page']['index_ids'] = 'cpu,load,mem,rrdup';
4a778b7e 17$rrd_info['overview']['page']['scan_config'] = false;
18$rrd_info['overview']['page']['text_intro'] = 'Go to the <a href="?stat=index">index page</a> for a full list of all available statistics';
19// $rrd_info['overview']['hidden'] = true;
20
21$rrd_info['cpu']['file'] = 'system.cpu.rrd';
22$rrd_info['cpu']['auto-update'] = true;
7b9ebce7
RK
23$rrd_info['cpu']['fields'][] = array('name' => 'user', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
24$rrd_info['cpu']['fields'][] = array('name' => 'nice', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
25$rrd_info['cpu']['fields'][] = array('name' => 'system', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
26$rrd_info['cpu']['fields'][] = array('name' => 'idle', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
27$rrd_info['cpu']['fields'][] = array('name' => 'iowait', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
28$rrd_info['cpu']['fields'][] = array('name' => 'irq', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
29$rrd_info['cpu']['fields'][] = array('name' => 'softirq', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
30$rrd_info['cpu']['fields'][] = array('name' => 'total', 'type' => 'DERIVE', 'heartbeat' => 600, 'min' => 0, 'max' => 'U');
4a778b7e 31$rrd_info['cpu']['update'] =
32 'function {
7b9ebce7
RK
33 $udata = array("user"=>null,"nice"=>null,"system"=>null,"idle"=>null,
34 "iowait"=>null,"irq"=>null,"softirq"=>null, "total"=>null);
35 $sdata = file("/proc/stat");
4a778b7e 36 foreach ($sdata as $sline) {
37 if (preg_match("/^\s*cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
38 $udata = array("user"=>$regs[1],"nice"=>$regs[2],"system"=>$regs[3],"idle"=>$regs[4],
7b9ebce7
RK
39 "iowait"=>$regs[5],"irq"=>$regs[6],"softirq"=>$regs[7],
40 "total"=>$regs[1]+$regs[2]+$regs[3]+$regs[4]+$regs[5]+$regs[6]+$regs[7]);
4a778b7e 41 }
42 }
43 return $udata;
44 }';
45$rrd_info['cpu']['graph']['rows'][] = array('name'=>'total', 'gType'=>'');
46$rrd_info['cpu']['graph']['rows'][] = array('name'=>'softirq_tmp', 'dsname'=>'softirq', 'gType'=>'');
47$rrd_info['cpu']['graph']['rows'][] = array('name'=>'irq_tmp', 'dsname'=>'irq', 'gType'=>'');
48$rrd_info['cpu']['graph']['rows'][] = array('name'=>'iowait_tmp', 'dsname'=>'iowait', 'gType'=>'');
49$rrd_info['cpu']['graph']['rows'][] = array('name'=>'system_tmp', 'dsname'=>'system', 'gType'=>'');
50$rrd_info['cpu']['graph']['rows'][] = array('name'=>'nice_tmp', 'dsname'=>'nice', 'gType'=>'');
51$rrd_info['cpu']['graph']['rows'][] = array('name'=>'user_tmp', 'dsname'=>'user', 'gType'=>'');
7b9ebce7 52$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'softirq', 'rpn_expr'=>'softirq_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#CCCCCC', 'color_bg'=>'#606060', 'legend'=>'softIRQ');
4a778b7e 53$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'irq', 'rpn_expr'=>'irq_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#808080', 'legend'=>'IRQ', 'stack'=>true);
54$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'iowait', 'rpn_expr'=>'iowait_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FF00FF', 'legend'=>'I/O wait', 'stack'=>true);
55$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'system', 'rpn_expr'=>'system_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FF0000', 'legend'=>'System', 'stack'=>true);
7b9ebce7 56$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'nice', 'rpn_expr'=>'nice_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FFFF00', 'color_bg'=>'#606060', 'legend'=>'Nice', 'stack'=>true);
4a778b7e 57$rrd_info['cpu']['graph']['rows'][] = array('dType'=>'CDEF', 'name'=>'user', 'rpn_expr'=>'user_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'User', 'stack'=>true);
58$rrd_info['cpu']['graph']['units_length'] = 4;
7b9ebce7 59$rrd_info['cpu']['graph']['label_y'] = '% CPU Usage';
4a778b7e 60$rrd_info['cpu']['graph']['min_y'] = 0;
61$rrd_info['cpu']['graph']['max_y'] = 100;
62$rrd_info['cpu']['graph']['fix_scale_y'] = true;
63// $rrd_info['cpu']['graph']['force_recreate'] = true;
64
4a778b7e 65$rrd_info['mem']['file'] = 'system.mem.rrd';
66$rrd_info['mem']['auto-update'] = true;
67$rrd_info['mem']['fields'][] = array('name' => 'total', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
68$rrd_info['mem']['fields'][] = array('name' => 'used', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
69$rrd_info['mem']['fields'][] = array('name' => 'buffers', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
70$rrd_info['mem']['fields'][] = array('name' => 'cached', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
71$rrd_info['mem']['fields'][] = array('name' => 'swap_total', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
72$rrd_info['mem']['fields'][] = array('name' => 'swap_used', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
73$rrd_info['mem']['update'] =
74 'function {
7b9ebce7 75 $sdata = explode("\n", `/usr/bin/free -wb`);
4a778b7e 76 $udata = array("total"=>null,"used"=>null,"buffers"=>null,"cached"=>null,
77 "swap_total"=>null,"swap_used"=>null);
78 foreach ($sdata as $sline) {
7b9ebce7
RK
79 if (preg_match("/Mem:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
80 $udata["total"] = $regs[1];
81 $udata["used"] = $regs[2];
82 $udata["buffers"] = $regs[5];
83 $udata["cached"] = $regs[6];
4a778b7e 84 }
85 elseif (preg_match("/Swap:\s+(\d+)\s+(\d+)\s+(\d+)/", $sline, $regs)) {
7b9ebce7
RK
86 $udata["swap_total"] = $regs[1];
87 $udata["swap_used"] = $regs[2];
4a778b7e 88 }
89 }
90 return $udata;
91 }';
92$rrd_info['mem']['graph']['rows'][] = array('name'=>'total', 'gType'=>'LINE1', 'color'=>'#000000', 'legend'=>'Available');
93$rrd_info['mem']['graph']['rows'][] = array('name'=>'used', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'Used');
94$rrd_info['mem']['graph']['rows'][] = array('name'=>'buffers', 'gType'=>'AREA', 'color'=>'#FFFF00', 'legend'=>'Buffers', 'stack'=>true);
95$rrd_info['mem']['graph']['rows'][] = array('name'=>'cached', 'gType'=>'AREA', 'color'=>'#008000', 'legend'=>'Cache', 'stack'=>true);
96$rrd_info['mem']['graph']['rows'][] = array('name'=>'swap_total', 'gType'=>'LINE1', 'color'=>'#CCCCCC', 'legend'=>'Swap avail.');
97$rrd_info['mem']['graph']['rows'][] = array('name'=>'swap_used', 'gType'=>'LINE2', 'color'=>'#00FFFF', 'legend'=>'Swap used');
98$rrd_info['mem']['graph']['units_binary'] = true;
99$rrd_info['mem']['graph']['units_exponent'] = 6;
100$rrd_info['mem']['graph']['units_length'] = 6;
101$rrd_info['mem']['graph']['label_y'] = 'Memory';
102$rrd_info['mem']['graph']['min_y'] = 0;
103// $rrd_info['mem']['graph']['max_y'] = 100;
104// $rrd_info['mem']['graph']['fix_scale_y'] = true;
105// $rrd_info['mem']['graph']['force_recreate'] = true;
106$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'total', 'gType'=>'');
107$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'swap_total', 'gType'=>'');
108$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'used_tmp', 'dsname'=>'used', 'gType'=>'');
109$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'buffers_tmp', 'dsname'=>'buffers', 'gType'=>'');
110$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'cached_tmp', 'dsname'=>'cached', 'gType'=>'');
111$rrd_info['mem']['graph.pct']['rows'][] = array('name'=>'swap_tmp', 'dsname'=>'swap_used', 'gType'=>'');
112$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'used', 'rpn_expr'=>'used_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'Used');
113$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'buffers', 'rpn_expr'=>'buffers_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#FFFF00', 'legend'=>'Buffers', 'stack'=>true);
114$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'cached', 'rpn_expr'=>'cached_tmp,total,/,100,*', 'gType'=>'AREA', 'color'=>'#008000', 'legend'=>'Cache', 'stack'=>true);
115$rrd_info['mem']['graph.pct']['rows'][] = array('dType'=>'CDEF', 'name'=>'swap_used', 'rpn_expr'=>'swap_tmp,swap_total,/,100,*', 'gType'=>'LINE2', 'color'=>'#00FFFF', 'legend'=>'Swap');
116$rrd_info['mem']['graph.pct']['units_exponent'] = 0;
117$rrd_info['mem']['graph.pct']['units_length'] = 4;
118$rrd_info['mem']['graph.pct']['label_y'] = '% Memory';
119$rrd_info['mem']['graph.pct']['min_y'] = 0;
120$rrd_info['mem']['graph.pct']['max_y'] = 100;
121$rrd_info['mem']['graph.pct']['fix_scale_y'] = true;
122// $rrd_info['mem']['graph.pct']['force_recreate'] = true;
123$rrd_info['mem']['page.pct']['graph_sub'] = 'pct';
124
125$rrd_info['load']['file'] = 'system.load.rrd';
126$rrd_info['load']['auto-update'] = true;
127$rrd_info['load']['fields'][] = array('name' => 'load1', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
128$rrd_info['load']['fields'][] = array('name' => 'load5', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
129$rrd_info['load']['fields'][] = array('name' => 'load15', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
130$rrd_info['load']['update'] = 'function { $sdata = explode(" ",file_get_contents("/proc/loadavg")); return array("load1"=>$sdata[0],"load5"=>$sdata[1],"load15"=>$sdata[2]); }';
131$rrd_info['load']['graph']['rows'][] = array('name'=>'load1', 'gType'=>'AREA', 'color'=>'#00CC00', 'legend'=>'1 Min.');
132$rrd_info['load']['graph']['rows'][] = array('name'=>'load5', 'gType'=>'LINE1', 'color'=>'#FF4000', 'legend'=>'5 Min.');
133$rrd_info['load']['graph']['rows'][] = array('name'=>'load15', 'gType'=>'LINE1', 'color'=>'#0000FF', 'legend'=>'15 Min.');
134$rrd_info['load']['graph']['units_length'] = 4;
135$rrd_info['load']['graph']['units_exponent'] = 0;
136$rrd_info['load']['graph']['label_y'] = 'Load average';
137$rrd_info['load']['graph']['min_y'] = 0;
138// $rrd_info['load']['graph']['force_recreate'] = true;
139$rrd_info['load']['page']['data_colorize'] = true;
140
4a778b7e 141/* !!! be sure to call this one _last_ of all auto-update rrd stats */
142$rrd_info['rrdup']['file'] = 'test.rrdup.rrd';
143// $rrd_info['rrdup']['auto-update'] = true;
144$rrd_info['rrdup']['fields'][] = array('name' => 'usertime', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
145$rrd_info['rrdup']['fields'][] = array('name' => 'systime', 'type' => 'GAUGE', 'heartbeat' => 600, 'min' => 'U', 'max' => 'U');
146$rrd_info['rrdup']['update'] = 'function { $sdata = posix_times(); return array("usertime"=>$sdata["cutime"],"systime"=>$sdata["cstime"]); }';
147$rrd_info['rrdup']['graph']['rows'][] = array('name'=>'systime', 'gType'=>'AREA', 'color'=>'#FF0000', 'legend'=>'System CPU time');
148$rrd_info['rrdup']['graph']['rows'][] = array('name'=>'usertime', 'gType'=>'AREA', 'color'=>'#0000FF', 'legend'=>'User CPU time', 'stack'=>true);
149$rrd_info['rrdup']['graph']['scale'] = 0.01;
150$rrd_info['rrdup']['graph']['units_length'] = 4;
151$rrd_info['rrdup']['graph']['units_exponent'] = 0;
152$rrd_info['rrdup']['graph']['label_y'] = 'RRD update (seconds)';
153$rrd_info['rrdup']['graph']['min_y'] = 0;
154// $rrd_info['rrdup']['graph']['force_recreate'] = true;
155
4a778b7e 156?>