aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/plugin/libvirt.php
blob: 829c5925789a24feaa40bc9581ccfab08752218c (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php

# Collectd libvirt plugin

require_once 'conf/common.inc.php';
require_once 'inc/collectd.inc.php';

# LAYOUT
# libvirt/
# libvirt/disk_octets-XXXX.rrd
# libvirt/disk_ops-XXXX.rrd
# libvirt/if_dropped-XXXX.rrd
# libvirt/if_errors-XXXX.rrd
# libvirt/if_octets-XXXX.rrd
# libvirt/if_packets-XXXX.rrd
# libvirt/virt_cpu_total.rrd

require_once 'type/GenericIO.class.php';
$obj = new Type_GenericIO($CONFIG);

switch($obj->args['type']) {
	case 'disk_octets':
		$obj->data_sources = array('read', 'write');
		$obj->ds_names = array(
			'read' => 'Read',
			'write' => 'Written',
		);
		$obj->colors = array(
			'read' => '0000ff',
			'write' => '00b000',
		);
		$obj->rrd_title = sprintf('Disk Traffic (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Bytes per second';
		$obj->rrd_format = '%5.1lf%s';
	break;
	case 'disk_ops':
		$obj->data_sources = array('read', 'write');
		$obj->ds_names = array(
			'read' => 'Read',
			'write' => 'Written',
		);
		$obj->colors = array(
			'read' => '0000ff',
			'write' => '00b000',
		);
		$obj->rrd_title = sprintf('Disk Operations (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Ops per second';
		$obj->rrd_format = '%5.1lf%s';
	break;
	case 'if_dropped':
		$obj->data_sources = array('rx', 'tx');
		$obj->ds_names = array(
			'rx' => 'Receive',
			'tx' => 'Transmit',
		);
		$obj->colors = array(
			'rx' => '0000ff',
			'tx' => '00b000',
		);
		$obj->rrd_title = sprintf('Interface Packets Dropped (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Packets dropped per second';
	break;
	case 'if_errors':
		$obj->data_sources = array('rx', 'tx');
		$obj->ds_names = array(
			'rx' => 'Receive',
			'tx' => 'Transmit',
		);
		$obj->colors = array(
			'rx' => '0000ff',
			'tx' => '00b000',
		);
		$obj->rrd_title = sprintf('Interface Errors (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Errors per second';
	break;
	case 'if_octets':
		$obj->data_sources = array('rx', 'tx');
		$obj->ds_names = array(
			'rx' => 'Receive',
			'tx' => 'Transmit',
		);
		$obj->colors = array(
			'rx' => '0000ff',
			'tx' => '00b000',
		);
		$obj->rrd_title = sprintf('Interface Traffic (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Bytes per second';
	break;
	case 'if_packets':
		$obj->data_sources = array('rx', 'tx');
		$obj->ds_names = array(
			'rx' => 'Receive',
			'tx' => 'Transmit',
		);
		$obj->colors = array(
			'rx' => '0000ff',
			'tx' => '00b000',
		);
		$obj->rrd_title = sprintf('Interface Packets (%s)', $obj->args['tinstance']);
		$obj->rrd_vertical = 'Packets per second';
	break;
	case 'virt_cpu_total':
		require_once 'type/Default.class.php';
		$obj = new Type_Default($CONFIG);

		$obj->data_sources = array('value');
		$obj->ds_names = array(
			'value' => 'CPU time',
		);
		$obj->colors = array(
			'value' => '0000ff',
		);
		$obj->rrd_title = 'CPU usage';
		$obj->rrd_vertical = 'CPU time';
	break;
	case 'virt_vcpu':
		require_once 'type/Default.class.php';
		$obj = new Type_Default($CONFIG);

		$obj->data_sources = array('value');
		$obj->ds_names = array(
			'value' => 'VCPU time',
		);
		$obj->colors = array(
			'value' => '0000ff',
		);
		$obj->rrd_title = 'VCPU usage';
		$obj->rrd_vertical = 'VCPU time';
	break;
}

$obj->width = $width;
$obj->heigth = $heigth;
$obj->rrd_format = '%5.1lf%s';

if ($CONFIG['version'] < 5 && count($obj->data_sources) == 1) {
	$obj->data_sources = array('ns');

	$obj->ds_names['ns'] = $obj->ds_names['value'];
	unset($obj->ds_names['value']);

	$obj->colors['ns'] = $obj->colors['value'];
	unset($obj->colors['value']);
}

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