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