Projet

Général

Profil

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

root / plugins / oracle / oracle__database_hitratio @ d0c8e0b0

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

1
#!/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

    
48
# Check for DBD::Oracle
49
if (! eval "require DBD::Oracle;") {
50
     exit 1;
51
}
52

    
53
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
54
#print "$dsn\n";
55
my $dbh = DBI->connect ($dsn, $dbuser,
56
			$dbpass,
57
			{RaiseError =>1}) || die "";
58

    
59

    
60

    
61
if (exists $ARGV[0]) {
62
    if ($ARGV[0] eq 'autoconf') {
63
	# Check for DBD::Oracle
64
	if (! eval "require DBD::Oracle;") {
65
	     print "no (DBD::Oracle not found)";
66
	     exit 1;
67
	}
68
        if ($dbh) {
69
            print "yes\n";
70
            exit 0;
71
        } else {
72
            print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
73
            exit 1;
74
	}
75
    }
76

    
77
    if ($ARGV[0] eq "config") {
78
	print "graph_title Oracle library and buffer cache hit ratios from $dbname\n";
79
	print "graph_args --upper-limit 110 -l 0\n";
80
	print "graph_vlabel %\n";
81
	print "graph_category db\n";
82
	print "graph_info This graph shows the percentage of blocks and libraries read from the cache\n";
83
	print "read_hitratio.label Cache hitratio\n";
84
	print "read_hitratio.type GAUGE\n";
85
	print "read_hitratio.draw LINE2\n";
86
	print "lib_hitratio.label Library hitratio\n";
87
	print "lib_hitratio.type GAUGE\n";
88
	print "lib_hitratio.draw LINE2\n";
89
	exit 0;
90
    }
91
}
92

    
93
#cache hitratio
94
my $sql_curr = "select (1-(pr.value/(dbg.value+cg.value)))*100 \
95
		from v\$sysstat pr, v\$sysstat dbg, v\$sysstat cg \
96
		where pr.name='physical reads' and dbg.name='db block gets' and cg.name='consistent gets'";
97

    
98
my $sth_curr = $dbh->prepare($sql_curr);
99
$sth_curr->execute();
100
my ($read_hitratio) = $sth_curr->fetchrow();
101
print "read_hitratio.value $read_hitratio\n";
102

    
103
#libray hit ratio
104
$sql_curr = "select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 \
105
		from v\$librarycache lc";
106

    
107
$sth_curr = $dbh->prepare($sql_curr);
108
$sth_curr->execute();
109
my ($lib_hitratio) = $sth_curr->fetchrow();
110
print "lib_hitratio.value $lib_hitratio\n";
111