-
Notifications
You must be signed in to change notification settings - Fork 0
/
postgres_querylength_
executable file
·101 lines (81 loc) · 3.87 KB
/
postgres_querylength_
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
#!/usr/bin/perl
# -*- cperl -*-
#
# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
# Copyright (C) 2019 Code Yellow BV
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2 dated June,
# 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 USA.
=head1 NAME
postgres_querylength_ - Plugin to monitor PostgreSQL long running queries.
=head1 CONFIGURATION
Configuration is done through libpq environment variables, for example
PGUSER, PGDATABASE, etc. For more information, see L<Munin::Plugin::Pgsql>.
To monitor a specific database, link to postgres_querylength_<databasename>.
To monitor all databases, link to postgres_querylength_ALL.
=head1 SEE ALSO
L<Munin::Plugin::Pgsql>
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=head1 AUTHOR
Magnus Hagander <[email protected]>, Redpill Linpro AB
=head1 COPYRIGHT/License.
Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
All rights reserved. This program is free software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
dated June, 1991.
=cut
use strict;
use warnings;
use Munin::Plugin::Pgsql;
my $pg = Munin::Plugin::Pgsql->new(
basename => 'postgres_querylength_',
title => 'PostgreSQL query length',
info => 'Most long-running queries and transactions',
vlabel => 'Age (seconds)',
basequery => [
"SELECT 'query',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE state NOT LIKE 'idle%' AND application_name != 'pg_dump' %%FILTER%%
UNION ALL
SELECT 'transaction',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-xact_start)),0) FROM pg_stat_activity WHERE application_name != 'pg_dump' %%FILTER%%",
[
9.1,
"SELECT 'query',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE query NOT LIKE '<IDLE%' AND application_name != 'pg_dump' %%FILTER%%
UNION ALL
SELECT 'transaction',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-xact_start)),0) FROM pg_stat_activity WHERE application_name != 'pg_dump' %%FILTER%%",
],
[
9.1,
"SELECT 'query',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE current_query NOT LIKE '<IDLE%' AND application_name != 'pg_dump' %%FILTER%%
UNION ALL
SELECT 'transaction',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-xact_start)),0) FROM pg_stat_activity WHERE application_name != 'pg_dump' %%FILTER%%",
],
[
8.2,
"SELECT 'query',COALESCE(max(extract(epoch FROM CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE current_query NOT LIKE '<IDLE%' AND application_name != 'pg_dump' %%FILTER%%"
]
],
wildcardfilter => " AND datname=?",
configquery => [
"VALUES ('query','Oldest query'),('transaction','Oldest transaction')",
[8.2, "VALUES ('query','Oldest query')"],
[8.1, "SELECT 'query','Oldest query'"]
],
suggestquery =>
"SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1 LIMIT 10",
stack => 0
);
$pg->Process();