Révision b0b39b01
Ruby plugins: apply style changes as suggested by "rubocop --fix-layout"
| plugins/oracle/oracle-sga | ||
|---|---|---|
| 1 | 1 |
#!/usr/bin/env 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 privilege 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 |
# |
|
| 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 |
|
|
| 48 | 50 |
#%# family=auto |
| 49 | 51 |
#%# capabilities=autoconf |
| 50 | 52 |
|
| 53 |
=end |
|
| 54 |
|
|
| 55 |
|
|
| 51 | 56 |
require 'rubygems' |
| 52 | 57 |
require 'oci8' |
| 53 | 58 |
|
| ... | ... | |
| 57 | 62 |
dbname = 'orcl' |
| 58 | 63 |
dbhost = 'localhost' |
| 59 | 64 |
|
| 60 |
tnsname = "(DESCRIPTION =
|
|
| 65 |
tnsname = "(DESCRIPTION = |
|
| 61 | 66 |
(ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
|
| 62 | 67 |
(CONNECT_DATA = (SID = #{dbname})))"
|
| 63 | 68 |
|
| 64 |
def runQuery (name,query)
|
|
| 65 |
rows = $conn.exec(query)
|
|
| 66 |
puts "#{name}.value #{rows.fetch().to_s}"
|
|
| 67 |
rows.close
|
|
| 69 |
def runQuery(name, query)
|
|
| 70 |
rows = $conn.exec(query)
|
|
| 71 |
puts "#{name}.value #{rows.fetch().to_s}"
|
|
| 72 |
rows.close |
|
| 68 | 73 |
end |
| 69 | 74 |
|
| 70 |
|
|
| 71 | 75 |
# |
| 72 | 76 |
# Queries |
| 73 | 77 |
# |
| ... | ... | |
| 98 | 102 |
decode(name, 'log_buffer', (bytes)/(1024*1024),0),0)),2)) sga_lbuffer |
| 99 | 103 |
from V$SGASTAT" |
| 100 | 104 |
|
| 101 |
|
|
| 102 |
memory_components = { "fixed_area" => fixed_area_query,
|
|
| 105 |
memory_components = { "fixed_area" => fixed_area_query,
|
|
| 103 | 106 |
"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 |
} |
|
| 107 |
"java_pool" => java_pool_query, |
|
| 108 |
"large_pool" => large_pool_query, |
|
| 109 |
"log_buffer" => log_buffer_query, |
|
| 110 |
"shared_pool" => shared_pool_query } |
|
| 109 | 111 |
|
| 110 | 112 |
# |
| 111 | 113 |
# autoconf |
| 112 | 114 |
# |
| 113 | 115 |
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
|
|
| 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
|
|
| 121 | 123 |
# |
| 122 | 124 |
# config definition |
| 123 | 125 |
# |
| 124 | 126 |
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 db"
|
|
| 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
|
|
| 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
|
|
| 147 | 149 |
end |
| 148 | 150 |
|
| 149 | 151 |
$conn = OCI8.new(orauser, orapass, tnsname) |
| 150 | 152 |
memory_components.each do |mc, query| |
| 151 |
runQuery(mc, query)
|
|
| 153 |
runQuery(mc, query)
|
|
| 152 | 154 |
end |
| 153 | 155 |
$conn.logoff |
Formats disponibles : Unified diff