aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/plugin/postgresql.php
blob: 361322d4ebf704a4b9260307a9c60f78a95405af (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
<?php

# Collectd Postgresql plugin

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

## LAYOUT
# postgresql-X/pg_blks-heap_hit.rrd
# postgresql-X/pg_blks-heap_read.rrd
# postgresql-X/pg_blks-idx_hit.rrd
# postgresql-X/pg_blks-idx_read.rrd
# postgresql-X/pg_blks-tidx_hit.rrd
# postgresql-X/pg_blks-tidx_read.rrd
# postgresql-X/pg_blks-toast_hit.rrd
# postgresql-X/pg_blks-toast_read.rrd
# postgresql-X/pg_db_size.rrd
# postgresql-X/pg_n_tup_c-del.rrd
# postgresql-X/pg_n_tup_c-hot_upd.rrd
# postgresql-X/pg_n_tup_c-ins.rrd
# postgresql-X/pg_n_tup_c-upd.rrd

$obj = new Type_GenericStacked($CONFIG);
$obj->rrd_format = '%5.1lf%s';

switch($obj->args['type']) {
	case 'pg_blks':
		$obj->ds_names = array(
			'heap_hit'   => 'Heap hit',
			'heap_read'  => 'Heap read',
			'idx_hit'    => 'Index hit',
			'idx_read'   => 'Index read',
			'tidx_hit'   => 'Toast index hit',
			'tidx_read'  => 'Toast index read',
			'toast_hit'  => 'Toast hit',
			'toast_read' => 'Toast read',
		);
		$obj->rrd_title = sprintf('PostgreSQL Disk I/O (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Blocks';
	break;
	case 'pg_db_size':
		$obj->ds_names = array(
			'value' => 'Size',
		);
		$obj->colors = array(
			'value' => '0000ff',
		);
		$obj->rrd_title = sprintf('PostgreSQL DB size (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Bytes';
	break;
	case 'pg_n_tup_c':
		$obj->order = array(
			'ins',
			'upd',
			'hot_upd',
			'del',
		);
		$obj->ds_names = array(
			'ins'     => 'Insert',
			'upd'     => 'Update',
			'hot_upd' => 'Hot Update',
			'del'     => 'Delete',
		);
		$obj->colors = array(
			'ins'     => '00ff00',
			'upd'     => 'ff7c00',
			'hot_upd' => '0000ff',
			'del'     => 'ff0000',
		);
		$obj->rrd_title = sprintf('PostgreSQL Row actions (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Rows';
	break;
	case 'pg_n_tup_g':
		$obj->order = array('live', 'dead');
		$obj->ds_names = array(
			'live' => 'Live',
			'dead' => 'Dead',
		);
		$obj->colors = array(
			'live' => '00ff00',
			'dead' => 'ff0000',
		);
		$obj->rrd_title = sprintf('PostgreSQL Table states (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Rows';
	break;
	case 'pg_numbackends':
		$obj->ds_names = array(
			'value' => 'Backends',
		);
		$obj->colors = array(
			'value' => '0000ff',
		);
		$obj->rrd_title = sprintf('PostgreSQL Backends (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Number';
	break;
	case 'pg_scan':
		$obj->ds_names = array(
			'seq'           => 'Sequential',
			'seq_tup_read'  => 'Sequential rows',
			'idx'           => 'Index',
			'idx_tup_fetch' => 'Index Rows',
		);
		$obj->rrd_title = sprintf('PostgreSQL Scans (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Scans / Rows';
	break;
	case 'pg_xact':
		$obj->ds_names = array(
			'commit'   => 'Commit',
			'rollback' => 'Rollback',
		);
		$obj->colors = array(
			'commit'   => '00ff00',
			'rollback' => 'ff0000',
		);
		$obj->rrd_title = sprintf('PostgreSQL Transactions (%s)',
			!empty($obj->args['pinstance']) ? $obj->args['pinstance'] : '');
		$obj->rrd_vertical = 'Transactions';
	break;
	default:
		$obj->rrd_title = sprintf('%s/%s', $obj->args['pinstance'], $obj->args['type']);
	break;
}

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