root / plugins / oracle / oracle-sga @ b0b39b01
Historique | Voir | Annoter | Télécharger (4,59 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
|
| 3 |
=begin |
| 4 |
|
| 5 |
Munin Plugin for SGA memory components monitoring |
| 6 |
|
| 7 |
Author: Wilfred Chau <openapp.developer@gmail.com> |
| 8 |
Date: 2011-05-12 |
| 9 |
Version: 1.0 |
| 10 |
|
| 11 |
This program is free software; you can redistribute it and/or modify |
| 12 |
it under the terms of the GNU General Public License version 2 |
| 13 |
as published by the Free Software Foundation. |
| 14 |
|
| 15 |
This program is distributed in the hope that it will be useful, |
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
GNU General Public License for more details. |
| 19 |
|
| 20 |
You should have received a copy of the GNU General Public License along |
| 21 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 22 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 23 |
|
| 24 |
|
| 25 |
Prerequistes: |
| 26 |
1) env.ORACLE_HOME set in munin-node |
| 27 |
2) rubygems |
| 28 |
3) oci8 - DBI gem for connecting to Oracle |
| 29 |
* instruction of installing oci8 is available here: |
| 30 |
http://ruby-oci8.rubyforge.org/en/InstallBinaryPackage.html |
| 31 |
|
| 32 |
Usage: |
| 33 |
1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins) |
| 34 |
2) chmod to allow executable to others |
| 35 |
3) create symbolic link in /etc/munin/plugins |
| 36 |
ln -s /usr/share/munin/plugins/oracle_orcl_sga.rb /etc/munin/plugins/oracle_orcl_sga.rb |
| 37 |
|
| 38 |
Parameters: |
| 39 |
autoconf |
| 40 |
config (required) |
| 41 |
|
| 42 |
Configurable variables: |
| 43 |
orauser : oracle user who has select privilege to query v$sgastat view |
| 44 |
orapass : password for the oracle user |
| 45 |
dbport : port used by the monitored instance (notice: numeric value) |
| 46 |
dbname : database to be monitored |
| 47 |
dbhost : host or ip address of db instance |
| 48 |
|
| 49 |
|
| 50 |
#%# family=auto |
| 51 |
#%# capabilities=autoconf |
| 52 |
|
| 53 |
=end |
| 54 |
|
| 55 |
|
| 56 |
require 'rubygems' |
| 57 |
require 'oci8' |
| 58 |
|
| 59 |
orauser = 'munin' |
| 60 |
orapass = 'munin' |
| 61 |
dbport = 1522 |
| 62 |
dbname = 'orcl' |
| 63 |
dbhost = 'localhost' |
| 64 |
|
| 65 |
tnsname = "(DESCRIPTION = |
| 66 |
(ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
|
| 67 |
(CONNECT_DATA = (SID = #{dbname})))"
|
| 68 |
|
| 69 |
def runQuery(name, query) |
| 70 |
rows = $conn.exec(query) |
| 71 |
puts "#{name}.value #{rows.fetch().to_s}"
|
| 72 |
rows.close |
| 73 |
end |
| 74 |
|
| 75 |
# |
| 76 |
# Queries |
| 77 |
# |
| 78 |
shared_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'shared pool', |
| 79 |
decode(name, 'library cache',0, |
| 80 |
'dictionary chace',0, |
| 81 |
'free memory',0, |
| 82 |
'sql area',0, |
| 83 |
(bytes)/(1024*1024)),0)),2)) pool_misc |
| 84 |
from V$SGASTAT" |
| 85 |
|
| 86 |
buffer_cache_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL, |
| 87 |
decode(name, 'db_block_buffers', (bytes)/(1024/1024), |
| 88 |
'buffer_cache',(bytes)/(1024*1024),0),0)),2)) sga_bufcache |
| 89 |
from V$SGASTAT" |
| 90 |
|
| 91 |
fixed_area_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL, |
| 92 |
decode(name, 'fixed_sga', (bytes)/(1024*1024),0),0)),2)) sga_fixed |
| 93 |
from V$SGASTAT" |
| 94 |
|
| 95 |
java_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'java pool', (bytes)/(1024*1024),0)),2)) sga_jpool |
| 96 |
from V$SGASTAT" |
| 97 |
|
| 98 |
large_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'large pool', (bytes)/(1024*1024),0)),2)) sga_lpool |
| 99 |
from V$SGASTAT" |
| 100 |
|
| 101 |
log_buffer_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, NULL, |
| 102 |
decode(name, 'log_buffer', (bytes)/(1024*1024),0),0)),2)) sga_lbuffer |
| 103 |
from V$SGASTAT" |
| 104 |
|
| 105 |
memory_components = { "fixed_area" => fixed_area_query,
|
| 106 |
"buffer_cache" => buffer_cache_query, |
| 107 |
"java_pool" => java_pool_query, |
| 108 |
"large_pool" => large_pool_query, |
| 109 |
"log_buffer" => log_buffer_query, |
| 110 |
"shared_pool" => shared_pool_query } |
| 111 |
|
| 112 |
# |
| 113 |
# autoconf |
| 114 |
# |
| 115 |
if ARGV[0] == "autoconf" |
| 116 |
if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1 |
| 117 |
puts "yes" |
| 118 |
else |
| 119 |
puts "no" |
| 120 |
puts "Usage: #{__FILE__} autoconf|conf"
|
| 121 |
end |
| 122 |
exit 0 |
| 123 |
# |
| 124 |
# config definition |
| 125 |
# |
| 126 |
elsif ARGV[0] == "config" |
| 127 |
puts "graph_args --base 1024k -r --lower-limit 0" |
| 128 |
puts "graph_title Oracle SGA from #{dbname}"
|
| 129 |
puts "graph_category db" |
| 130 |
puts "graph_info This graph shows the SGA memory usage (in MB)" |
| 131 |
puts "graph_vlabel MB" |
| 132 |
puts "graph_scale no" |
| 133 |
puts "graph_period second" |
| 134 |
|
| 135 |
memory_components.keys.each do |m| |
| 136 |
puts "#{m}.label #{m}"
|
| 137 |
puts "#{m}.info SGA: #{m}"
|
| 138 |
puts "#{m}.type GAUGE"
|
| 139 |
|
| 140 |
# make sure fixed_area is at the bottom of the stack |
| 141 |
if (m == 'fixed_area') |
| 142 |
puts "#{m}.draw AREA"
|
| 143 |
else |
| 144 |
puts "#{m}.draw STACK"
|
| 145 |
end |
| 146 |
end |
| 147 |
|
| 148 |
exit 0 |
| 149 |
end |
| 150 |
|
| 151 |
$conn = OCI8.new(orauser, orapass, tnsname) |
| 152 |
memory_components.each do |mc, query| |
| 153 |
runQuery(mc, query) |
| 154 |
end |
| 155 |
$conn.logoff |
