Révision 624ffe79
Initial version
| plugins/other/oracle_sysmetricspl | ||
|---|---|---|
| 1 |
#! /usr/local/bin/perl -w |
|
| 2 |
# anders@fupp.net, 2007-09-19 |
|
| 3 |
# If you found this plugin useful, let me know. :-) |
|
| 4 |
# |
|
| 5 |
# Munin plugin to show: |
|
| 6 |
# |
|
| 7 |
# - number of user transactions per second. |
|
| 8 |
# - number of full index scans per second. |
|
| 9 |
# - any value from v$sysmetric, if extended. |
|
| 10 |
# |
|
| 11 |
# For making this plugin run, make sure that: |
|
| 12 |
# |
|
| 13 |
# 1) The user or group that munin-node runs as, has access to $ORACLE_HOME |
|
| 14 |
# and especially the library directories. Adding the user to a group to |
|
| 15 |
# give access is not enough, if so it needs to have the group as its primary |
|
| 16 |
# group. |
|
| 17 |
# |
|
| 18 |
# 2) The Perl installation indicated with the path on line 1, has DBI and |
|
| 19 |
# DBD::Oracle installed. |
|
| 20 |
# |
|
| 21 |
# 3) You use 32-bit libraries ($ORACLE_HOME/lib32) if your Perl is 32-bit, |
|
| 22 |
# and vice versa ($ORACLE_HOME/lib) for 64-bit. |
|
| 23 |
# |
|
| 24 |
# PS: A solution for 2 and 3 may be to use $ORACLE_HOME/perl/bin/perl. |
|
| 25 |
# |
|
| 26 |
# 4) Configuration variables below are set correctly. |
|
| 27 |
# |
|
| 28 |
# 5) That the user munin-node runs has, has access to a valid tnsnames.ora |
|
| 29 |
# file in $ORACLE_HOME/network/admin/tnsnames.ora or $HOME/.tnsnames.ora. |
|
| 30 |
# Some admins may prefer to have a separate tnsnames.ora for monitoring. |
|
| 31 |
# |
|
| 32 |
# 6) You link up this script to oracle_transactions or oracle_indexscans in |
|
| 33 |
# the plugins-dir. |
|
| 34 |
|
|
| 35 |
# --- configuration --- |
|
| 36 |
$ENV{'ORACLE_HOME'} = '/foo/oracle/10.2';
|
|
| 37 |
$ENV{'LD_LIBRARY_PATH'} = '/foo/oracle/10.2/lib';
|
|
| 38 |
$ENV{'HOME'} = '/home/munin';
|
|
| 39 |
|
|
| 40 |
my $dbdriver="Oracle"; |
|
| 41 |
my $dbhost="localhost"; |
|
| 42 |
my $dbuser="myuser"; |
|
| 43 |
my $dbpw="mypass"; |
|
| 44 |
my $dbname="mydb"; |
|
| 45 |
# --- end, configuration --- |
|
| 46 |
|
|
| 47 |
my $name = $0; |
|
| 48 |
# Remove extra chars |
|
| 49 |
$name =~ s@^.*?(\w+)$@$1@; |
|
| 50 |
# Remove base name for plugin |
|
| 51 |
$name =~ s@^oracle_@@; |
|
| 52 |
|
|
| 53 |
use DBI; |
|
| 54 |
$|=1; # Flush stdout after every write. |
|
| 55 |
|
|
| 56 |
sub dbconnect {
|
|
| 57 |
if ($dbh = DBI->connect("dbi:$dbdriver:$dbname",$dbuser,$dbpw,{ PrintError => 1 })) {
|
|
| 58 |
return(1); |
|
| 59 |
} else {
|
|
| 60 |
return(0); |
|
| 61 |
} |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
sub dbdisconnect {
|
|
| 65 |
$dbh->disconnect; |
|
| 66 |
} |
|
| 67 |
|
|
| 68 |
sub listvalues {
|
|
| 69 |
if (dbconnect) {
|
|
| 70 |
$dbq = $dbh->prepare('select * from v$sysmetric');
|
|
| 71 |
$dbq->execute; |
|
| 72 |
my $columns = $dbq->{NAME};
|
|
| 73 |
my $kolonner = "@$columns"; |
|
| 74 |
|
|
| 75 |
print "Kolonner: $kolonner\n"; |
|
| 76 |
|
|
| 77 |
while ( my @row = $dbq->fetchrow_array ) {
|
|
| 78 |
print "@row\n"; |
|
| 79 |
} |
|
| 80 |
$dbq->finish; |
|
| 81 |
dbdisconnect; |
|
| 82 |
} |
|
| 83 |
} |
|
| 84 |
|
|
| 85 |
sub getvalues {
|
|
| 86 |
my $metric = shift; |
|
| 87 |
my $label = shift; |
|
| 88 |
|
|
| 89 |
if (dbconnect) {
|
|
| 90 |
$dbq = $dbh->prepare('select * from v$sysmetric');
|
|
| 91 |
$dbq->execute; |
|
| 92 |
while ( my $row = $dbq->fetchrow_hashref() ) {
|
|
| 93 |
if ($row->{METRIC_NAME} eq "$metric") {
|
|
| 94 |
my $val = $row->{VALUE};
|
|
| 95 |
$val =~ s@,@.@; |
|
| 96 |
if (substr($val,0,1) eq "." ) {
|
|
| 97 |
print "$label.value 0" . $val . "\n"; |
|
| 98 |
} else {
|
|
| 99 |
print "$label.value " . $val . "\n"; |
|
| 100 |
} |
|
| 101 |
|
|
| 102 |
last; |
|
| 103 |
} |
|
| 104 |
} |
|
| 105 |
$dbq->finish; |
|
| 106 |
dbdisconnect; |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
|
|
| 110 |
sub printconfig {
|
|
| 111 |
if ($name eq "transactions") {
|
|
| 112 |
print "graph_title User transactions\n"; |
|
| 113 |
print "graph_vlabel transactions per second\n"; |
|
| 114 |
print "graph_category Oracle\n"; |
|
| 115 |
print "graph_info This graph shows the number of users transactions per second in Oracle\n"; |
|
| 116 |
print "graph_args --base 1000 -l 0\n"; |
|
| 117 |
print "transactions.label transactions\n"; |
|
| 118 |
print "transactions.type GAUGE\n"; |
|
| 119 |
print "transactions.graph yes\n"; |
|
| 120 |
} elsif ($name eq "indexscans") {
|
|
| 121 |
print "graph_title Full index scans\n"; |
|
| 122 |
print "graph_vlabel indexscans per second\n"; |
|
| 123 |
print "graph_category Oracle\n"; |
|
| 124 |
print "graph_info This graph shows the number of full index scans per second in Oracle\n"; |
|
| 125 |
print "graph_args --base 1000 -l 0\n"; |
|
| 126 |
print "indexscans.label indexscans\n"; |
|
| 127 |
print "indexscans.type GAUGE\n"; |
|
| 128 |
print "indexscans.graph yes\n"; |
|
| 129 |
} else {
|
|
| 130 |
print "No config for $name.\n"; |
|
| 131 |
} |
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
sub dovalues {
|
|
| 135 |
if ($name eq "transactions") {
|
|
| 136 |
getvalues("User Transaction Per Sec", "transactions");
|
|
| 137 |
} elsif ($name eq "indexscans") {
|
|
| 138 |
getvalues("Full Index Scans Per Sec", "indexscans");
|
|
| 139 |
} else {
|
|
| 140 |
listvalues; |
|
| 141 |
} |
|
| 142 |
} |
|
| 143 |
|
|
| 144 |
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
|
|
| 145 |
print "yes\n"; |
|
| 146 |
} elsif ($ARGV[0] && $ARGV[0] eq "config") {
|
|
| 147 |
printconfig; |
|
| 148 |
} else {
|
|
| 149 |
dovalues; |
|
| 150 |
} |
|
Formats disponibles : Unified diff