Projet

Général

Profil

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

root / plugins / oracle / oracle__tablespace_usage @ d0c8e0b0

Historique | Voir | Annoter | Télécharger (3,41 ko)

1 8e5bf1c1 Joan Carles Soler
#!/usr/bin/perl -w
2
# Plugin for monitor oracle database reads.
3
#
4
# Licenced under GPL v2.
5
#
6
# Usage:
7
#
8
#       Symlink into /etc/munin/plugins/ and add the monitored
9
#       database to the filename. e.g.:
10
#
11
#       ln -s /usr/share/munin/plugins/oracle__database__hitratio \
12
#         /etc/munin/plugins/oracle_<databasename>_database__hitratio
13
#       This should, however, be given through autoconf and suggest.
14
#
15
#       If required, give username, password and/or Oracle server
16
#       host through environment variables.
17
#
18
#
19
# Parameters:
20
#
21
#       config   (required)
22
#
23
# Config variables:
24
#
25
#       dbhost     - Which database server to use. Defaults to
26
#                    'localhost'.
27
#       dbname     - Which database to use. Defaults to orl1
28
#       dbuser     - A Oracle user account with read permission to
29
#                    the given database. Defaults to
30
#                    'oracle'. Anyway, Munin must be told which user
31
#                    this plugin should be run as.
32
#       dbpass     - The corresponding password, if
33
#                    applicable. Default to undef.
34
#
35
# Magic markers
36
#%# family=auto
37
#%# capabilities=autoconf
38
39
use strict;
40
use DBI;
41
42
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
43
my $dbname = $ENV{'dbname'} || 'orl1';
44
my $dbuser = $ENV{'dbuser'} || 'oracle';
45
my $dbport = $ENV{'dbport'} || '1521';
46
my $dbpass = $ENV{'dbpass'} || '';
47
my $warning = $ENV{'warning'} || '90';
48
my $critical = $ENV{'critical'} || '96';
49
50
# Check for DBD::Oracle
51
if (! eval "require DBD::Oracle;") {
52
     exit 1;
53
}
54
55
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
56
#print "$dsn\n";
57
my $dbh = DBI->connect ($dsn, $dbuser,
58
			$dbpass,
59
			{RaiseError =>1}) || die "";
60
61
62
63
if (exists $ARGV[0]) {
64
    if ($ARGV[0] eq 'autoconf') {
65
	# Check for DBD::Oracle
66
	if (! eval "require DBD::Oracle;") {
67
	     print "no (DBD::Oracle not found)";
68
	     exit 1;
69
	}
70
        if ($dbh) {
71
            print "yes\n";
72
            exit 0;
73
        } else {
74
            print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
75
            exit 1;
76
	}
77
    }
78
79
    if ($ARGV[0] eq "config") {
80
	print "graph_title Oracle tablespace usage (in %) from $dbname\n";
81
	print "graph_args --upper-limit 100 -l 0\n";
82
	print "graph_vlabel %\n";
83 afcc3e9b dipohl
	print "graph_category db\n";
84 8e5bf1c1 Joan Carles Soler
	print "graph_info This graph shows the tablespace usage (in %)\n";
85
        print "graph_scale no\n";
86
        print "warning $warning\n";
87
        print "critical $critical\n";
88
	my $sql_curr = "SELECT unique tablespace_name from dba_data_files";
89
	my $sth_curr = $dbh->prepare($sql_curr);
90
	$sth_curr->execute();
91
        while ( my ($datname) = $sth_curr->fetchrow_array ) {
92
                print "$datname.label $datname\n";
93
                print "$datname.info $datname tablespace\n";
94
                print "$datname.type GAUGE\n";
95
	        print "$datname.draw LINE2\n";
96
	}
97
	exit 0;
98
    }
99
}
100
101
my $sql_curr = "select a.tablespace_name, b.free,a.total,trunc(b.free/a.total * 1000) / 10 prc \
102
		from ( \
103
		select tablespace_name,sum(bytes) total \
104
		from dba_data_files group by tablespace_name) A, \
105
		( select tablespace_name,sum(bytes) free \
106
		from dba_free_space group by tablespace_name) B \
107
		where a.tablespace_name=b.tablespace_name";
108
my $sth_curr = $dbh->prepare($sql_curr);
109
$sth_curr->execute();
110
while ( my ($datname,$free,$total,$prc) = $sth_curr->fetchrow_array ) {
111
	my $in_use = 100 - ($free/$total)*100;
112
	print "$datname.value $in_use\n";
113
}