aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/plugin/nut.php
blob: 848b09bdbf483388b6af8aa229ed2861f4732589 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php

# Collectd NUT plugin

require_once 'conf/common.inc.php';
require_once 'type/Default.class.php';
require_once 'inc/collectd.inc.php';

## LAYOUT
# nut-XXXX/
# nut-XXXX/frequency-XXXX.rrd
# nut-XXXX/percent-XXXX.rrd
# nut-XXXX/temerature-XXXX.rrd
# nut-XXXX/timeleft-XXXX.rrd
# nut-XXXX/voltage-XXXX.rrd

$obj = new Type_Default($CONFIG);
switch($obj->args['type']) {
	case 'frequency':
		if ($CONFIG['version'] < 5) {
			$obj->data_sources = array('frequency');
		} else {
			$obj->data_sources = array('value');
		}
		$obj->ds_names = array('output' => 'Output');
		$obj->rrd_title = sprintf('Frequency (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = 'Hz';
		$obj->rrd_format = '%5.1lf%s';
	break;
	case 'percent':
		if ($CONFIG['version'] < 5) {
			$obj->data_sources = array('percent');
		} else {
			$obj->data_sources = array('value');
		}
		$obj->ds_names = array('charge' => 'Charge',
		                       'load' => 'Load');
		$obj->rrd_title = sprintf('Charge & load (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = '%';
		$obj->rrd_format = '%5.1lf';
	break;
	case 'power':
		$obj->data_sources = array('value');
		$obj->ds_names = array('ups' => 'UPS');
		$obj->rrd_title = sprintf('Power (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = 'VA';
		$obj->rrd_format = '%5.1lf%s';
	break;
	case 'temperature':
		$obj->data_sources = array('value');
		$obj->ds_names = array('battery' => 'Battery');
		$obj->rrd_title = sprintf('Temperature (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = '°C';
		$obj->rrd_format = '%5.1lf%s';
	break;
	case 'timeleft':
		if ($CONFIG['version'] < 5) {
			$obj->data_sources = array('timeleft');
		} else {
			$obj->data_sources = array('value');
		}
		$obj->ds_names = array('timeleft' => 'Timeleft');
		$obj->rrd_title = sprintf('Timeleft (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = 'Seconds';
		$obj->rrd_format = '%5.1lf';
	break;
	case 'voltage':
		$obj->data_sources = array('value');
		$obj->ds_names = array('battery' => 'Battery',
		                       'input' => 'Input',
		                       'output' => 'Output');
		$obj->rrd_title = sprintf('Voltage (%s)', $obj->args['pinstance']);
		$obj->rrd_vertical = 'Volts';
		$obj->rrd_format = '%5.1lf';
	break;
}

collectd_flush($obj->identifiers);
$obj->rrd_graph();