root / plugins / oracle / oracle__locks @ ca01c6e3
Historique | Voir | Annoter | Télécharger (4,69 ko)
| 1 | beef8c8e | Joan Carles Soler | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # Plugin for monitor oracle locks |
||
| 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__locks \ |
||
| 12 | # /etc/munin/plugins/oracle_<databasename>_locks |
||
| 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 | # autoconf |
||
| 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 template1 |
||
| 28 | # dbuser - A Postgresql user account with read permission to |
||
| 29 | # the given database. Defaults to |
||
| 30 | # 'postgres'. 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. Remember that |
||
| 34 | # pg_hba.conf must be configured accordingly. |
||
| 35 | # |
||
| 36 | # Magic markers |
||
| 37 | #%# family=auto |
||
| 38 | #%# capabilities=autoconf |
||
| 39 | |||
| 40 | use strict; |
||
| 41 | use DBI; |
||
| 42 | |||
| 43 | my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
|
||
| 44 | my $dbname = $ENV{'dbname'} || 'ocrl';
|
||
| 45 | my $dbuser = $ENV{'dbuser'} || 'oracle';
|
||
| 46 | my $dbport = $ENV{'dbport'} || '1521';
|
||
| 47 | my $dbpass = $ENV{'dbpass'} || '';
|
||
| 48 | |||
| 49 | # Check for DBD::Oracle |
||
| 50 | if (! eval "require DBD::Oracle;") {
|
||
| 51 | exit 1; |
||
| 52 | } |
||
| 53 | |||
| 54 | my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname"; |
||
| 55 | #print "$dsn\n"; |
||
| 56 | my $dbh = DBI->connect ($dsn, $dbuser, |
||
| 57 | $dbpass, |
||
| 58 | {RaiseError =>1}) || die "";
|
||
| 59 | |||
| 60 | |||
| 61 | |||
| 62 | if (exists $ARGV[0]) {
|
||
| 63 | if ($ARGV[0] eq 'autoconf') {
|
||
| 64 | # Check for DBD::Oracle |
||
| 65 | if (! eval "require DBD::Oracle;") {
|
||
| 66 | print "no (DBD::Oracle not found)"; |
||
| 67 | exit 1; |
||
| 68 | } |
||
| 69 | if ($dbh) {
|
||
| 70 | print "yes\n"; |
||
| 71 | exit 0; |
||
| 72 | } else {
|
||
| 73 | print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr; |
||
| 74 | exit 1; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($ARGV[0] eq "config") {
|
||
| 79 | print "graph_title Oracle locks for $dbname\n"; |
||
| 80 | print "graph_args --base 1000 -l 0\n"; |
||
| 81 | print "graph_vlabel Locks\n"; |
||
| 82 | print "graph_category oracle\n"; |
||
| 83 | print "graph_info Shows oracle locks\n"; |
||
| 84 | print "graph_scale no\n"; |
||
| 85 | print "RS.label Row Share Locks\n"; |
||
| 86 | print "RS.info Row Share Oracle locks\n"; |
||
| 87 | print "RS.type GAUGE\n"; |
||
| 88 | #print "RS.warning 5\n"; |
||
| 89 | #print "RS.critical 10\n"; |
||
| 90 | print "RE.label Row Exclusive locks\n"; |
||
| 91 | print "RE.info Row Exclusive oracle locks\n"; |
||
| 92 | print "RE.type GAUGE\n"; |
||
| 93 | #print "RE.warning 5\n"; |
||
| 94 | #print "RE.critical 10\n"; |
||
| 95 | print "S.label Share locks\n"; |
||
| 96 | print "S.info Row Share oracle locks\n"; |
||
| 97 | print "S.type GAUGE\n"; |
||
| 98 | #print "S.warning 5\n"; |
||
| 99 | #print "S.critical 10\n"; |
||
| 100 | print "SRX.label Share Row Exclusive locks\n"; |
||
| 101 | print "SRX.info Share Row Exclusive oracle locks\n"; |
||
| 102 | print "SRX.type GAUGE\n"; |
||
| 103 | #print "SRX.warning 5\n"; |
||
| 104 | #print "SRX.critical 10\n"; |
||
| 105 | print "X.label Exclusive locks\n"; |
||
| 106 | print "X.info Exclusive oracle locks\n"; |
||
| 107 | print "X.type GAUGE\n"; |
||
| 108 | #print "X.warning 5\n"; |
||
| 109 | #print "X.critical 10\n"; |
||
| 110 | print "MR.label Media Recovery (Share) locks\n"; |
||
| 111 | print "MR.info Media Recovery (Share) oracle locks\n"; |
||
| 112 | print "MR.type GAUGE\n"; |
||
| 113 | #print "MR.warning 5\n"; |
||
| 114 | #print "MR.critical 10\n"; |
||
| 115 | print "RT.label Redo Thread (Exclusive) locks\n"; |
||
| 116 | print "RT.info Redo Thread (Exclusive) oracle locks\n"; |
||
| 117 | print "RT.type GAUGE\n"; |
||
| 118 | #print "RT.warning 5\n"; |
||
| 119 | #print "RT.critical 10\n"; |
||
| 120 | print "XR.label XR locks\n"; |
||
| 121 | print "XR.info XR oracle locks\n"; |
||
| 122 | print "XR.type GAUGE\n"; |
||
| 123 | #print "XR.warning 5\n"; |
||
| 124 | #print "XR.critical 10\n"; |
||
| 125 | print "TS.label Temp Segment locks\n"; |
||
| 126 | print "TS.info Temp Segment oracle locks\n"; |
||
| 127 | print "TS.type GAUGE\n"; |
||
| 128 | #print "TS.warning 5\n"; |
||
| 129 | #print "TS.critical 10\n"; |
||
| 130 | exit 0; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | #select MODE_HELD,count(MODE_HELD) from dba_locks group by MODE_HELD; |
||
| 135 | my $sql="select type,count(*) from v\$lock group by type"; |
||
| 136 | my $sth = $dbh->prepare ($sql); |
||
| 137 | $sth->execute (); |
||
| 138 | my $type = 0; |
||
| 139 | my $count = 0; |
||
| 140 | my ($RS,$RE,$S,$SRX,$X,$MR,$RT,$XR,$TS) = (0,0,0,0,0,0,0,0,0); |
||
| 141 | while ( ($type, $count) = $sth->fetchrow ()) {
|
||
| 142 | #print "$type.value $count\n"; |
||
| 143 | if ( $type eq "RS" ) {$RS=$count} ;
|
||
| 144 | if ( $type eq "RE" ) {$RE=$count} ;
|
||
| 145 | if ( $type eq "S" ) {$S=$count} ;
|
||
| 146 | if ( $type eq "SRX" ) {$SRX=$count} ;
|
||
| 147 | if ( $type eq "X" ) {$X=$count} ;
|
||
| 148 | if ( $type eq "MR" ) {$MR=$count} ;
|
||
| 149 | if ( $type eq "RT" ) {$RT=$count} ;
|
||
| 150 | if ( $type eq "XR" ) {$XR=$count} ;
|
||
| 151 | if ( $type eq "TS" ) {$TS=$count} ;
|
||
| 152 | } |
||
| 153 | print "RS.value $RS\n"; |
||
| 154 | print "RE.value $RE\n"; |
||
| 155 | print "S.value $S\n"; |
||
| 156 | print "SRX.value $SRX\n"; |
||
| 157 | print "X.value $X\n"; |
||
| 158 | print "MR.value $MR\n"; |
||
| 159 | print "RT.value $RT\n"; |
||
| 160 | print "XR.value $XR\n"; |
||
| 161 | print "TS.value $TS\n"; |
