1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

- have some dirs

This commit is contained in:
Steve Schnepp 2012-02-13 18:24:46 +01:00
parent 0b089ea777
commit 08346aac58
687 changed files with 0 additions and 0 deletions

122
plugins/oracle/oracle-pga-monitor Executable file
View file

@ -0,0 +1,122 @@
#! /usr/bin/ruby
#
# Munin Plugin for PGA memory components monitoring
#
# Author: Wilfred Chau <openapp.developer@gmail.com>
# Date: 2011-05-13
# Version: 1.0
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
# Prerequistes:
# 1) env.ORACLE_HOME set in munin-node
# 2) rubygems
# 3) oci8 - DBI gem for connecting to Oracle
# * instruction of installing oci8 is available here:
# http://ruby-oci8.rubyforge.org/en/InstallBinaryPackage.html
#
# Usage:
# 1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins)
# 2) chmod to allow executable to others
# 3) create symbolic link in /etc/munin/plugins
# ln -s /usr/share/munin/plugins/oracle_<sid>_pga.rb /etc/munin/plugins/oracle_<sid>_pga.rb
# ** replace <sid> with your oralce sid
#
# Parameters:
# autoconf
# config (required)
#
# Configurable variables:
# orauser : oracle user who has select priviledge to query v$pgastat view
# orapass : password for the oracle user
# dbport : port used by the monitored instance (notice: numeric value)
# dbname : database to be monitored
# dbhost : host or ip address of db instance
#
#
#%# family=auto
#%# capabilities=autoconf
require 'rubygems'
require 'oci8'
orauser = 'munin'
orapass = 'munin'
dbport = 1522
dbname = 'orcl'
dbhost = 'localhost'
tnsname = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
(CONNECT_DATA = (SID = #{dbname})))"
def runQuery (name,query)
rows = $conn.exec(query)
puts "#{name}.value #{rows.fetch().to_s}"
rows.close
end
#
# Queries
#
pga_target_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga_target
from V$PGASTAT where name = 'aggregate PGA target parameter'"
pga_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga
from V$PGASTAT where name = 'total PGA inuse'"
pga_components = { "pga_target" => pga_target_query,
"pga_in_use" => pga_query
}
#
# autoconf
#
if ARGV[0] == "autoconf"
if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1
puts "yes"
else
puts "no"
puts "Usage: #{__FILE__} autoconf|conf"
end
exit 0
#
# config definition
#
elsif ARGV[0] == "config"
puts "graph_args --base 1024k -r --lower-limit 0"
puts "graph_title Oracle PGA from #{dbname}"
puts "graph_category Oracle"
puts "graph_info This graph shows the PGA memory usage (in MB)"
puts "graph_vlabel MB"
puts "graph_scale no"
puts "graph_period second"
pga_components.keys.each do |p|
puts "#{p}.label #{p}"
puts "#{p}.info PGA: #{p}"
puts "#{p}.type GAUGE"
puts "#{p}.draw LINE1"
end
exit 0
end
$conn = OCI8.new(orauser, orapass, tnsname)
pga_components.each do |pc, query|
runQuery(pc, query)
end
$conn.logoff

153
plugins/oracle/oracle-sga Executable file
View file

@ -0,0 +1,153 @@
#! /usr/bin/ruby
#
# Munin Plugin for SGA memory components monitoring
#
# Author: Wilfred Chau <openapp.developer@gmail.com>
# Date: 2011-05-12
# Version: 1.0
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#
# Prerequistes:
# 1) env.ORACLE_HOME set in munin-node
# 2) rubygems
# 3) oci8 - DBI gem for connecting to Oracle
# * instruction of installing oci8 is available here:
# http://ruby-oci8.rubyforge.org/en/InstallBinaryPackage.html
#
# Usage:
# 1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins)
# 2) chmod to allow executable to others
# 3) create symbolic link in /etc/munin/plugins
# ln -s /usr/share/munin/plugins/oracle_orcl_sga.rb /etc/munin/plugins/oracle_orcl_sga.rb
#
# Parameters:
# autoconf
# config (required)
#
# Configurable variables:
# orauser : oracle user who has select priviledge to query v$sgastat view
# orapass : password for the oracle user
# dbport : port used by the monitored instance (notice: numeric value)
# dbname : database to be monitored
# dbhost : host or ip address of db instance
#
#
#%# family=auto
#%# capabilities=autoconf
require 'rubygems'
require 'oci8'
orauser = 'munin'
orapass = 'munin'
dbport = 1522
dbname = 'orcl'
dbhost = 'localhost'
tnsname = "(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
(CONNECT_DATA = (SID = #{dbname})))"
def runQuery (name,query)
rows = $conn.exec(query)
puts "#{name}.value #{rows.fetch().to_s}"
rows.close
end
#
# Queries
#
shared_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'shared pool',
decode(name, 'library cache',0,
'dictionary chace',0,
'free memory',0,
'sql area',0,
(bytes)/(1024*1024)),0)),2)) pool_misc
from V$SGASTAT"
buffer_cache_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL,
decode(name, 'db_block_buffers', (bytes)/(1024/1024),
'buffer_cache',(bytes)/(1024*1024),0),0)),2)) sga_bufcache
from V$SGASTAT"
fixed_area_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL,
decode(name, 'fixed_sga', (bytes)/(1024*1024),0),0)),2)) sga_fixed
from V$SGASTAT"
java_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'java pool', (bytes)/(1024*1024),0)),2)) sga_jpool
from V$SGASTAT"
large_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'large pool', (bytes)/(1024*1024),0)),2)) sga_lpool
from V$SGASTAT"
log_buffer_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, NULL,
decode(name, 'log_buffer', (bytes)/(1024*1024),0),0)),2)) sga_lbuffer
from V$SGASTAT"
memory_components = { "fixed_area" => fixed_area_query,
"buffer_cache" => buffer_cache_query,
"java_pool" => java_pool_query,
"large_pool" => large_pool_query,
"log_buffer" => log_buffer_query,
"shared_pool" => shared_pool_query
}
#
# autoconf
#
if ARGV[0] == "autoconf"
if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1
puts "yes"
else
puts "no"
puts "Usage: #{__FILE__} autoconf|conf"
end
exit 0
#
# config definition
#
elsif ARGV[0] == "config"
puts "graph_args --base 1024k -r --lower-limit 0"
puts "graph_title Oracle SGA from #{dbname}"
puts "graph_category Oracle"
puts "graph_info This graph shows the SGA memory usage (in MB)"
puts "graph_vlabel MB"
puts "graph_scale no"
puts "graph_period second"
memory_components.keys.each do |m|
puts "#{m}.label #{m}"
puts "#{m}.info SGA: #{m}"
puts "#{m}.type GAUGE"
# make sure fixed_area is at the bottom of the stack
if ( m == 'fixed_area' )
puts "#{m}.draw AREA"
else
puts "#{m}.draw STACK"
end
end
exit 0
end
$conn = OCI8.new(orauser, orapass, tnsname)
memory_components.each do |mc, query|
runQuery(mc, query)
end
$conn.logoff

View file

@ -0,0 +1,153 @@
#!/usr/bin/perl -w
# Plugin for monitor oracle connections.
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/oracle__connections \
# /etc/munin/plugins/oracle_<databasename>_connections
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or oracle server
# host through environment variables.
#
#
# Parameters:
# autoconf
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbname - Which database to use. Defaults to orcl
# dbuser - A oracle user account with read permission to
# the v$session view. Defaults to
# 'oracle'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef.
#
# showusers - If set to 1 show usernames and num. of connections.
# Default is not show users (0).
# Magic markers
#%# family=auto
#%# capabilities=autoconf
use strict;
use DBI;
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'orcl';
my $dbuser = $ENV{'dbuser'} || 'oracle';
my $dbport = $ENV{'dbport'} || '1521';
my $dbpass = $ENV{'dbpass'} || '';
my $showusers = $ENV{'showusers'} || '0';
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
exit 1;
}
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
#print "$dsn\n";
my $dbh = DBI->connect ($dsn, $dbuser,
$dbpass,
{RaiseError =>1}) || die "";
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
print "no (DBD::Oracle not found)";
exit 1;
}
if ($dbh) {
print "yes\n";
exit 0;
} else {
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
exit 1;
}
}
if ($ARGV[0] eq "config") {
my $sql_max = "select value from v\$parameter where name = 'sessions'";
my $sth_max = $dbh->prepare($sql_max);
$sth_max->execute();
my ($max_connections) = $sth_max->fetchrow();
my $warning = int ($max_connections * 0.7);
my $critical = int ($max_connections * 0.8);
print "graph_title Oracle active connections from $dbname\n";
print "graph_args -l 0 --base 1000\n";
print "graph_vlabel Connections\n";
print "graph_category oracle\n";
print "graph_info Shows active oracle connections from $dbname\n";
print "graph_scale no\n";
if ( $showusers ) {
my $sql = "select username, count(username) from v\$session where username is not null group by username";
my $sth = $dbh->prepare($sql);
$sth->execute();
my $setarea = "yes";
while ( my ($datname,$curr_conn) = $sth->fetchrow_array ) {
print "$datname.label $datname active connections\n";
print "$datname.info $datname active connections\n";
print "$datname.type GAUGE\n";
if ($setarea eq "yes") {
print "$datname.draw AREA\n";
$setarea="";
} else {
print "$datname.draw STACK\n";
}
}
} else {
print "connections.label active connections\n";
print "connections.info active connections\n";
print "connections.type GAUGE\n";
print "connections.warning $warning\n";
print "connections.critical $critical\n";
}
print "total.label active connections\n";
print "total.info active connections\n";
print "total.type GAUGE\n";
print "total.warning $warning\n";
print "total.critical $critical\n";
print "max_connections.label Max. connections\n";
print "max_connections.info Max. connections\n";
print "max_connections.type GAUGE\n";
exit 0;
}
}
my $sql_max = "select value from v\$parameter where name = 'sessions'";
my $sth_max = $dbh->prepare($sql_max);
$sth_max->execute();
my ($max_connections) = $sth_max->fetchrow();
if ( $showusers ) {
my $sql = "select username, count(username) from v\$session where username is not null group by username";
my $sth = $dbh->prepare($sql);
$sth->execute();
my $total = 0;
while ( my ($datname,$curr_conn) = $sth->fetchrow_array ) {
print "$datname.value $curr_conn\n";
$total = $total+$curr_conn;
}
print "total.value $total\n";
} else {
my $sql = "select count(username) from v\$session where username is not null";
my $sth = $dbh->prepare($sql);
$sth->execute();
my ($curr_conn) = $sth->fetchrow_array;
print "connections.value $curr_conn\n";
}
print "max_connections.value $max_connections\n";

View file

@ -0,0 +1,111 @@
#!/usr/bin/perl -w
# Plugin for monitor oracle database reads.
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/oracle__database__hitratio \
# /etc/munin/plugins/oracle_<databasename>_database__hitratio
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or Oracle server
# host through environment variables.
#
#
# Parameters:
#
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbname - Which database to use. Defaults to orl1
# dbuser - A Oracle user account with read permission to
# the given database. Defaults to
# 'oracle'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef.
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf
use strict;
use DBI;
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'orl1';
my $dbuser = $ENV{'dbuser'} || 'oracle';
my $dbport = $ENV{'dbport'} || '1521';
my $dbpass = $ENV{'dbpass'} || '';
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
exit 1;
}
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
#print "$dsn\n";
my $dbh = DBI->connect ($dsn, $dbuser,
$dbpass,
{RaiseError =>1}) || die "";
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
print "no (DBD::Oracle not found)";
exit 1;
}
if ($dbh) {
print "yes\n";
exit 0;
} else {
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
exit 1;
}
}
if ($ARGV[0] eq "config") {
print "graph_title Oracle library and buffer cache hit ratios from $dbname\n";
print "graph_args --upper-limit 110 -l 0\n";
print "graph_vlabel %\n";
print "graph_category Oracle\n";
print "graph_info This graph shows the percentage of blocks and libraries read from the cache\n";
print "read_hitratio.label Cache hitratio\n";
print "read_hitratio.type GAUGE\n";
print "read_hitratio.draw LINE2\n";
print "lib_hitratio.label Library hitratio\n";
print "lib_hitratio.type GAUGE\n";
print "lib_hitratio.draw LINE2\n";
exit 0;
}
}
#cache hitratio
my $sql_curr = "select (1-(pr.value/(dbg.value+cg.value)))*100 \
from v\$sysstat pr, v\$sysstat dbg, v\$sysstat cg \
where pr.name='physical reads' and dbg.name='db block gets' and cg.name='consistent gets'";
my $sth_curr = $dbh->prepare($sql_curr);
$sth_curr->execute();
my ($read_hitratio) = $sth_curr->fetchrow();
print "read_hitratio.value $read_hitratio\n";
#libray hit ratio
$sql_curr = "select sum(lc.pins)/(sum(lc.pins)+sum(lc.reloads))*100 \
from v\$librarycache lc";
$sth_curr = $dbh->prepare($sql_curr);
$sth_curr->execute();
my ($lib_hitratio) = $sth_curr->fetchrow();
print "lib_hitratio.value $lib_hitratio\n";

161
plugins/oracle/oracle__locks Executable file
View file

@ -0,0 +1,161 @@
#!/usr/bin/perl -w
# Plugin for monitor oracle locks
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/oracle__locks \
# /etc/munin/plugins/oracle_<databasename>_locks
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or oracle server
# host through environment variables.
#
#
# Parameters:
# autoconf
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbname - Which database to use. Defaults to template1
# dbuser - A Postgresql user account with read permission to
# the given database. Defaults to
# 'postgres'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef. Remember that
# pg_hba.conf must be configured accordingly.
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf
use strict;
use DBI;
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'ocrl';
my $dbuser = $ENV{'dbuser'} || 'oracle';
my $dbport = $ENV{'dbport'} || '1521';
my $dbpass = $ENV{'dbpass'} || '';
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
exit 1;
}
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
#print "$dsn\n";
my $dbh = DBI->connect ($dsn, $dbuser,
$dbpass,
{RaiseError =>1}) || die "";
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
print "no (DBD::Oracle not found)";
exit 1;
}
if ($dbh) {
print "yes\n";
exit 0;
} else {
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
exit 1;
}
}
if ($ARGV[0] eq "config") {
print "graph_title Oracle locks for $dbname\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel Locks\n";
print "graph_category oracle\n";
print "graph_info Shows oracle locks\n";
print "graph_scale no\n";
print "RS.label Row Share Locks\n";
print "RS.info Row Share Oracle locks\n";
print "RS.type GAUGE\n";
#print "RS.warning 5\n";
#print "RS.critical 10\n";
print "RE.label Row Exclusive locks\n";
print "RE.info Row Exclusive oracle locks\n";
print "RE.type GAUGE\n";
#print "RE.warning 5\n";
#print "RE.critical 10\n";
print "S.label Share locks\n";
print "S.info Row Share oracle locks\n";
print "S.type GAUGE\n";
#print "S.warning 5\n";
#print "S.critical 10\n";
print "SRX.label Share Row Exclusive locks\n";
print "SRX.info Share Row Exclusive oracle locks\n";
print "SRX.type GAUGE\n";
#print "SRX.warning 5\n";
#print "SRX.critical 10\n";
print "X.label Exclusive locks\n";
print "X.info Exclusive oracle locks\n";
print "X.type GAUGE\n";
#print "X.warning 5\n";
#print "X.critical 10\n";
print "MR.label Media Recovery (Share) locks\n";
print "MR.info Media Recovery (Share) oracle locks\n";
print "MR.type GAUGE\n";
#print "MR.warning 5\n";
#print "MR.critical 10\n";
print "RT.label Redo Thread (Exclusive) locks\n";
print "RT.info Redo Thread (Exclusive) oracle locks\n";
print "RT.type GAUGE\n";
#print "RT.warning 5\n";
#print "RT.critical 10\n";
print "XR.label XR locks\n";
print "XR.info XR oracle locks\n";
print "XR.type GAUGE\n";
#print "XR.warning 5\n";
#print "XR.critical 10\n";
print "TS.label Temp Segment locks\n";
print "TS.info Temp Segment oracle locks\n";
print "TS.type GAUGE\n";
#print "TS.warning 5\n";
#print "TS.critical 10\n";
exit 0;
}
}
#select MODE_HELD,count(MODE_HELD) from dba_locks group by MODE_HELD;
my $sql="select type,count(*) from v\$lock group by type";
my $sth = $dbh->prepare ($sql);
$sth->execute ();
my $type = 0;
my $count = 0;
my ($RS,$RE,$S,$SRX,$X,$MR,$RT,$XR,$TS) = (0,0,0,0,0,0,0,0,0);
while ( ($type, $count) = $sth->fetchrow ()) {
#print "$type.value $count\n";
if ( $type eq "RS" ) {$RS=$count} ;
if ( $type eq "RE" ) {$RE=$count} ;
if ( $type eq "S" ) {$S=$count} ;
if ( $type eq "SRX" ) {$SRX=$count} ;
if ( $type eq "X" ) {$X=$count} ;
if ( $type eq "MR" ) {$MR=$count} ;
if ( $type eq "RT" ) {$RT=$count} ;
if ( $type eq "XR" ) {$XR=$count} ;
if ( $type eq "TS" ) {$TS=$count} ;
}
print "RS.value $RS\n";
print "RE.value $RE\n";
print "S.value $S\n";
print "SRX.value $SRX\n";
print "X.value $X\n";
print "MR.value $MR\n";
print "RT.value $RT\n";
print "XR.value $XR\n";
print "TS.value $TS\n";

View file

@ -0,0 +1,113 @@
#!/usr/bin/perl -w
# Plugin for monitor oracle database reads.
#
# Licenced under GPL v2.
#
# Usage:
#
# Symlink into /etc/munin/plugins/ and add the monitored
# database to the filename. e.g.:
#
# ln -s /usr/share/munin/plugins/oracle__database__hitratio \
# /etc/munin/plugins/oracle_<databasename>_database__hitratio
# This should, however, be given through autoconf and suggest.
#
# If required, give username, password and/or Oracle server
# host through environment variables.
#
#
# Parameters:
#
# config (required)
#
# Config variables:
#
# dbhost - Which database server to use. Defaults to
# 'localhost'.
# dbname - Which database to use. Defaults to orl1
# dbuser - A Oracle user account with read permission to
# the given database. Defaults to
# 'oracle'. Anyway, Munin must be told which user
# this plugin should be run as.
# dbpass - The corresponding password, if
# applicable. Default to undef.
#
# Magic markers
#%# family=auto
#%# capabilities=autoconf
use strict;
use DBI;
my $dbhost = $ENV{'dbhost'} || '127.0.0.1';
my $dbname = $ENV{'dbname'} || 'orl1';
my $dbuser = $ENV{'dbuser'} || 'oracle';
my $dbport = $ENV{'dbport'} || '1521';
my $dbpass = $ENV{'dbpass'} || '';
my $warning = $ENV{'warning'} || '90';
my $critical = $ENV{'critical'} || '96';
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
exit 1;
}
my $dsn = "DBI:Oracle:dbname=$dbname;host=$dbhost;port=$dbport;sid=$dbname";
#print "$dsn\n";
my $dbh = DBI->connect ($dsn, $dbuser,
$dbpass,
{RaiseError =>1}) || die "";
if (exists $ARGV[0]) {
if ($ARGV[0] eq 'autoconf') {
# Check for DBD::Oracle
if (! eval "require DBD::Oracle;") {
print "no (DBD::Oracle not found)";
exit 1;
}
if ($dbh) {
print "yes\n";
exit 0;
} else {
print "no Unable to access Database $dbname on host $dbhost as user $dbuser.\nError returned was: ". $DBI::errstr;
exit 1;
}
}
if ($ARGV[0] eq "config") {
print "graph_title Oracle tablespace usage (in %) from $dbname\n";
print "graph_args --upper-limit 100 -l 0\n";
print "graph_vlabel %\n";
print "graph_category Oracle\n";
print "graph_info This graph shows the tablespace usage (in %)\n";
print "graph_scale no\n";
print "warning $warning\n";
print "critical $critical\n";
my $sql_curr = "SELECT unique tablespace_name from dba_data_files";
my $sth_curr = $dbh->prepare($sql_curr);
$sth_curr->execute();
while ( my ($datname) = $sth_curr->fetchrow_array ) {
print "$datname.label $datname\n";
print "$datname.info $datname tablespace\n";
print "$datname.type GAUGE\n";
print "$datname.draw LINE2\n";
}
exit 0;
}
}
my $sql_curr = "select a.tablespace_name, b.free,a.total,trunc(b.free/a.total * 1000) / 10 prc \
from ( \
select tablespace_name,sum(bytes) total \
from dba_data_files group by tablespace_name) A, \
( select tablespace_name,sum(bytes) free \
from dba_free_space group by tablespace_name) B \
where a.tablespace_name=b.tablespace_name";
my $sth_curr = $dbh->prepare($sql_curr);
$sth_curr->execute();
while ( my ($datname,$free,$total,$prc) = $sth_curr->fetchrow_array ) {
my $in_use = 100 - ($free/$total)*100;
print "$datname.value $in_use\n";
}

153
plugins/oracle/oracle_connections Executable file
View file

@ -0,0 +1,153 @@
#!/bin/bash
#
# Munin plugin to monitor oracle connections w/o DBD::Oracle, or perl for that
# matter ;-)
#
# Author: Kevin Kunkel (kunkel.kevin@gmail.com) on December 11, 2007
# (Based off the perl munin plugin by Joan Carles Soler)
#
# Licenced under GPL v2.
#
# Usage:
#
# If required, give username, password and/or oracle server
# host through environment variables.
#
# Parameters:
# autoconf
# config (required)
#
# Config variables:
#
# ORACLE_SID - Which database to use. Defaults to orcl
# oracle_user - A oracle user account with read permission to
# the v$session view. Defaults to
# 'oracle'. Anyway, Munin must be told which user
# this plugin should be run as.
# oracle_pass - The corresponding password, if
# applicable. Default to undef.
#
# SHOW_ORACLE_USERS - If set to 1 show usernames and num. of connections.
# Default is not show users (0).
# Magic markers
#%# family=auto
#%# capabilities=autoconf
# Hard-code environment variables here
#oracle_user=
#oracle_pass=
#ORACLE_SID=
#ORACLE_HOME=
#SHOW_ORACLE_USERS=
# End variable hard-code
if [ -z "$ORACLE_HOME" ] ; then
# Adjust to your oratab locations
for oratab in /var/opt/oracle/oratab /etc/oratab
do
[ ! -f $oratab ] && continue
IFS=:
while read SID HOME STARTUP;
do
if [ "$SID" = "*" ]
then
ORACLE_HOME=$HOME
break
fi
done < $oratab
[ -n "$ORACLE_HOME" ] && break
break
done
fi
if [ -z "$ORACLE_SID" ]
then
ORACLE_SID="orcl"
fi
if [ -z "$oracle_user" ]
then
oracle_user="oracle"
fi
if [ -z "$SHOW_ORACLE_USERS" ]
then
SHOW_ORACLE_USERS=0
else
if [ $SHOW_ORACLE_USERS -ne 1 ]
then
SHOW_ORACLE_USERS=0
fi
fi
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_HOME PATH ORACLE_SID
if [ "$1" = "autoconf" ]
then
echo yes
exit 0
fi
if [ "$1" = "config" ]
then
WARN_CRIT=`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{print $1 * 0.7 " " $1 * 0.8 }'
set pagesize 0
select value from v\\$parameter where name = 'sessions';
EOF`
echo "graph_title Oracle active connections to $ORACLE_SID"
echo "graph_args -l 0 --base 1000"
echo "graph_vlabel Connections"
echo "graph_category Oracle"
echo "graph_info Shows active oracle connections to $ORACLE_SID"
echo "graph_scale no"
if [ $SHOW_ORACLE_USERS -eq 1 ]
then
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{ print $1 ".label " $1 " active connections"
print $1 ".info " $1 " active connections"
print $1 ".type GAUGE" }; END {
print "total.label active connections"
print "total.info active connections"
print "total.type GAUGE"
}'
set pagesize 0
select username, count(username) from v\$session where username is not null group by username;
EOF
echo $WARN_CRIT| awk '{ print "total.warning " $1 "\ntotal.critical " $2 }'
else
echo "connections.label active connections"
echo "connections.info active connections"
echo "connections.type GAUGE"
echo $WARN_CRIT| awk '{ print "connections.warning " $1 "\nconnections.critical " $2 }'
fi
fi
if [ $SHOW_ORACLE_USERS -eq 1 ]
then
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$'|awk 'BEGIN { total=0 } {
print $1 ".value " $2
total=total+$2 } END { print "total.value " total }'
set pagesize 0
select username, count(username) from v\$session where username is not null group by username;
EOF
else
sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | grep -v '^$'|\
awk '{ print "connections.value " $1 }'
set pagesize 0
select count(username) from v\$session where username is not null;
EOF
fi
echo "max_connections.value" "`sqlplus -s ${oracle_user}/${oracle_pass}@$ORACLE_SID << EOF | \
grep -v '^$' | awk '{print $1 }'
set pagesize 0
select value from v\\$parameter where name = 'sessions';
EOF`"

View file

@ -0,0 +1,150 @@
#! /usr/local/bin/perl -w
# anders@fupp.net, 2007-09-19
# If you found this plugin useful, let me know. :-)
#
# Munin plugin to show:
#
# - number of user transactions per second.
# - number of full index scans per second.
# - any value from v$sysmetric, if extended.
#
# For making this plugin run, make sure that:
#
# 1) The user or group that munin-node runs as, has access to $ORACLE_HOME
# and especially the library directories. Adding the user to a group to
# give access is not enough, if so it needs to have the group as its primary
# group.
#
# 2) The Perl installation indicated with the path on line 1, has DBI and
# DBD::Oracle installed.
#
# 3) You use 32-bit libraries ($ORACLE_HOME/lib32) if your Perl is 32-bit,
# and vice versa ($ORACLE_HOME/lib) for 64-bit.
#
# PS: A solution for 2 and 3 may be to use $ORACLE_HOME/perl/bin/perl.
#
# 4) Configuration variables below are set correctly.
#
# 5) That the user munin-node runs has, has access to a valid tnsnames.ora
# file in $ORACLE_HOME/network/admin/tnsnames.ora or $HOME/.tnsnames.ora.
# Some admins may prefer to have a separate tnsnames.ora for monitoring.
#
# 6) You link up this script to oracle_transactions or oracle_indexscans in
# the plugins-dir.
# --- configuration ---
$ENV{'ORACLE_HOME'} = '/foo/oracle/10.2';
$ENV{'LD_LIBRARY_PATH'} = '/foo/oracle/10.2/lib';
$ENV{'HOME'} = '/home/munin';
my $dbdriver="Oracle";
my $dbhost="localhost";
my $dbuser="myuser";
my $dbpw="mypass";
my $dbname="mydb";
# --- end, configuration ---
my $name = $0;
# Remove extra chars
$name =~ s@^.*?(\w+)$@$1@;
# Remove base name for plugin
$name =~ s@^oracle_@@;
use DBI;
$|=1; # Flush stdout after every write.
sub dbconnect {
if ($dbh = DBI->connect("dbi:$dbdriver:$dbname",$dbuser,$dbpw,{ PrintError => 1 })) {
return(1);
} else {
return(0);
}
}
sub dbdisconnect {
$dbh->disconnect;
}
sub listvalues {
if (dbconnect) {
$dbq = $dbh->prepare('select * from v$sysmetric');
$dbq->execute;
my $columns = $dbq->{NAME};
my $kolonner = "@$columns";
print "Kolonner: $kolonner\n";
while ( my @row = $dbq->fetchrow_array ) {
print "@row\n";
}
$dbq->finish;
dbdisconnect;
}
}
sub getvalues {
my $metric = shift;
my $label = shift;
if (dbconnect) {
$dbq = $dbh->prepare('select * from v$sysmetric');
$dbq->execute;
while ( my $row = $dbq->fetchrow_hashref() ) {
if ($row->{METRIC_NAME} eq "$metric") {
my $val = $row->{VALUE};
$val =~ s@,@.@;
if (substr($val,0,1) eq "." ) {
print "$label.value 0" . $val . "\n";
} else {
print "$label.value " . $val . "\n";
}
last;
}
}
$dbq->finish;
dbdisconnect;
}
}
sub printconfig {
if ($name eq "transactions") {
print "graph_title User transactions\n";
print "graph_vlabel transactions per second\n";
print "graph_category Oracle\n";
print "graph_info This graph shows the number of users transactions per second in Oracle\n";
print "graph_args --base 1000 -l 0\n";
print "transactions.label transactions\n";
print "transactions.type GAUGE\n";
print "transactions.graph yes\n";
} elsif ($name eq "indexscans") {
print "graph_title Full index scans\n";
print "graph_vlabel indexscans per second\n";
print "graph_category Oracle\n";
print "graph_info This graph shows the number of full index scans per second in Oracle\n";
print "graph_args --base 1000 -l 0\n";
print "indexscans.label indexscans\n";
print "indexscans.type GAUGE\n";
print "indexscans.graph yes\n";
} else {
print "No config for $name.\n";
}
}
sub dovalues {
if ($name eq "transactions") {
getvalues("User Transaction Per Sec", "transactions");
} elsif ($name eq "indexscans") {
getvalues("Full Index Scans Per Sec", "indexscans");
} else {
listvalues;
}
}
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
print "yes\n";
} elsif ($ARGV[0] && $ARGV[0] eq "config") {
printconfig;
} else {
dovalues;
}