Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / postgresql / postgres_queries3_ @ a0415034

Historique | Voir | Annoter | Télécharger (2,67 ko)

1
#!/usr/bin/env perl
2

    
3
# postgres_queries3: see stats on number of rows 
4
# read, inserted, updated and deleted on a per table basis
5
#
6
# Author:
7
#    Samuel Smith leon36 <snail> gmail <dot> com
8
#
9
# Created:
10
#    20140701
11
#
12
# Usage:
13
#    Place in /etc/munin/plugins/ (or link it there using ln -s)
14
#    Place table names after '_' and delimit with '-'
15
#    EX: postgres_queries3_table1-table2-table3
16
#
17
# Parameters:
18
#    config   (required)
19
#    conf:
20
#    [postgres_*]
21
#    user postgres
22
#
23
#
24
# General info:
25
#    Require permission for database access and read (no writes are processed).
26
#    Recommended user is PostgreSQL database owner.
27
#    On debian systems install libipc-run3-perl
28
#
29
# Log info:
30
# 20140701 - Initial 
31
# 20140924 - 
32
#	-ignore internal pg tables
33
#	-missing stuff in config	
34

    
35

    
36
use strict;
37
use IPC::Run3 qw( run3 );
38

    
39

    
40
my %values;
41

    
42
my $query = \<<EOF;
43
select	
44
	'sel_seq.value '	|| SUM(seq_scan)	|| E'\n' ||
45
	'sel_seq_rows.value '	|| SUM(seq_tup_read)	|| E'\n' ||
46
	'sel_idx.value '	|| SUM(idx_scan)	|| E'\n' ||
47
	'sel_idx_rows.value '	|| SUM(idx_tup_fetch)	|| E'\n' ||
48
	'inserts.value '	|| SUM(n_tup_ins)	|| E'\n' ||
49
	'updates.value '	|| SUM(n_tup_upd)	|| E'\n' ||
50
	'deletes.value '	|| SUM(n_tup_del)
51
		from pg_stat_all_tables where relname not like 'pg_%';
52
EOF
53

    
54

    
55
$0 =~ /postgres_queries3_(.*)/;
56

    
57
my @dbs = split(/-/,$1);
58

    
59
if( defined $ARGV[0] and $ARGV[0] eq "config" ){
60
print qq/graph_title Postgres All Queries
61
graph_args --base 1000 -l 0 -r
62
graph_vlabel Queries per \${graph_period}
63
graph_category PostgreSQL
64
graph_info Shows number of select, insert, update and delete queries
65
sel_seq.label s_selects
66
sel_seq.info Sequential selects on all tables
67
sel_seq.type DERIVE
68
sel_seq.min 0
69
sel_seq.max 100
70
sel_seq_rows.label s_select rows
71
sel_seq_rows.info Rows returned from sequential selects
72
sel_seq_rows.type DERIVE
73
sel_seq_rows.min 0
74
sel_seq_rows.max 100
75
sel_idx.label i_selects
76
sel_idx.info Sequential selects on all indexes
77
sel_idx.type DERIVE
78
sel_idx.min 0
79
sel_idx.max 100
80
sel_idx_rows.label i_select rows
81
sel_idx_rows.info Rows returned form index selects
82
sel_idx_rows.type DERIVE
83
sel_idx_rows.min 0
84
sel_idx_rows.min 100
85
inserts.label inserts
86
inserts.info Rows inserted on all tables
87
inserts.type DERIVE
88
inserts.min 0
89
inserts.max 100
90
updates.label updates
91
updates.info Rows updated on all tables
92
updates.type DERIVE
93
updates.min 0
94
updates.max 100
95
deletes.label deletes
96
deletes.info Rows deleted from all tables
97
deletes.type DERIVE
98
deletes.min 0
99
deletes.max 100
100
/;
101
exit;
102
}
103

    
104
foreach my $db (@dbs){
105
	my @out;
106

    
107
	run3( "psql -At $db", $query, \@out);
108

    
109
	foreach my $line (@out){
110
		my($key, $value) = split(/ /, $line);
111
		$values{$key} += $value;
112
	}
113
	
114

    
115
}
116

    
117
foreach my $key (keys %values){
118
	print "$key $values{$key}\n";
119
}