Projet

Général

Profil

Révision 8de0f083

ID8de0f08367a148761be79b4fe8ce4f5c35131c96
Parent 6facd3c3
Enfant f1952dc3

Ajouté par Clemens Schwaighofer il y a plus de 13 ans

postgres database size in detail

shows the data, index, sequence and view size of a single database.

Uses the default munin postgresql perl plugin.

Voir les différences:

plugins/postgresql/postgres_size_detail_
1
#!/usr/bin/perl
2
# -*- cperl -*-
3
#
4
# Copyright (C) 2012, Clemens Schwaighofer
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; version 2 dated June,
9
# 1991.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301 USA.
20

  
21
=head1 NAME
22

  
23
postgres_size_detail_ - Plugin to monitor PostgreSQL database size for one database in detail (data, index, sequence, view)
24

  
25
=head1 CONFIGURATION
26

  
27
Configuration is done through libpq environment variables, for example
28
PGUSER, PGDATABASE, etc. For more information, see L<Munin::Plugin::Pgsql>.
29

  
30
To monitor a specific database, link to postgres_size_<databasename>.
31
This script cannot monitor all database detail sizes at the same time, a valid database name needs to be given.
32

  
33
=head1 SEE ALSO
34

  
35
L<Munin::Plugin::Pgsql>
36

  
37
=head1 MAGIC MARKERS
38

  
39
 #%# family=auto
40
 #%# capabilities=autoconf suggest
41

  
42
=head1 AUTHOR
43

  
44
Magnus Hagander <magnus@hagander.net>, Redpill Linpro AB
45

  
46
=head1 COPYRIGHT/License.
47

  
48
Copyright (c) 2012, Clemens Schwaighofer (gullevek@gullevek.org)
49

  
50
All rights reserved. This program is free software; you can
51
redistribute it and/or modify it under the terms of the GNU General
52
Public License as published by the Free Software Foundation; version 2
53
dated June, 1991.
54

  
55
=cut
56

  
57
use strict;
58
use warnings;
59

  
60
use Munin::Plugin::Pgsql;
61

  
62
my $pg = Munin::Plugin::Pgsql->new(
63
    basename => 'postgres_size_detail_',
64
    title    => 'PostgreSQL detail database size',
65
    info     => 'Size of database in detail',
66
    vlabel   => 'Size',
67
    paramdatabase => 1,
68
    basequery => "SELECT CASE WHEN relkind = 'r' OR relkind = 't' THEN 'db_detail_data' WHEN relkind = 'i' THEN 'db_detail_index' WHEN relkind = 'v' THEN 'db_detail_view' WHEN relkind = 'S' THEN 'db_detail_sequence' ELSE 'db_detail_other' END AS state,
69
	SUM(relpages::bigint * 8 * 1024) AS size 
70
	FROM pg_class pg, pg_namespace pgn WHERE pg.relnamespace = pgn.oid AND pgn.nspname NOT IN ('information_schema', 'pg_catalog') GROUP BY state",
71
    configquery    => [
72
        "VALUES ('db_detail_data','Data size'),('db_detail_index','Index size'),('db_detail_sequence','Sequence size'),('db_detail_view','View size')",
73
    ],
74
    suggestquery =>
75
        "SELECT datname FROM pg_database WHERE datallowconn AND NOT datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1 LIMIT 10",
76
    stack     => 1,
77
    graphmin  => 0,
78
    graphdraw => 'AREA',
79
	extraconfig => 'graph_total Total'
80
);
81

  
82
$pg->Process();
83

  

Formats disponibles : Unified diff