root / plugins / oracle / oracle-pga-monitor @ 17f78427
Historique | Voir | Annoter | Télécharger (3,36 ko)
| 1 |
#!/usr/bin/env ruby |
|---|---|
| 2 |
# |
| 3 |
# Munin Plugin for PGA memory components monitoring |
| 4 |
# |
| 5 |
# Author: Wilfred Chau <openapp.developer@gmail.com> |
| 6 |
# Date: 2011-05-13 |
| 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_<sid>_pga.rb /etc/munin/plugins/oracle_<sid>_pga.rb |
| 35 |
# ** replace <sid> with your oralce sid |
| 36 |
# |
| 37 |
# Parameters: |
| 38 |
# autoconf |
| 39 |
# config (required) |
| 40 |
# |
| 41 |
# Configurable variables: |
| 42 |
# orauser : oracle user who has select privilege to query v$pgastat view |
| 43 |
# orapass : password for the oracle user |
| 44 |
# dbport : port used by the monitored instance (notice: numeric value) |
| 45 |
# dbname : database to be monitored |
| 46 |
# dbhost : host or ip address of db instance |
| 47 |
# |
| 48 |
# |
| 49 |
#%# family=auto |
| 50 |
#%# capabilities=autoconf |
| 51 |
|
| 52 |
require 'rubygems' |
| 53 |
require 'oci8' |
| 54 |
|
| 55 |
orauser = 'munin' |
| 56 |
orapass = 'munin' |
| 57 |
dbport = 1522 |
| 58 |
dbname = 'orcl' |
| 59 |
dbhost = 'localhost' |
| 60 |
|
| 61 |
tnsname = "(DESCRIPTION = |
| 62 |
(ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
|
| 63 |
(CONNECT_DATA = (SID = #{dbname})))"
|
| 64 |
|
| 65 |
def runQuery (name,query) |
| 66 |
rows = $conn.exec(query) |
| 67 |
puts "#{name}.value #{rows.fetch().to_s}"
|
| 68 |
rows.close |
| 69 |
end |
| 70 |
|
| 71 |
|
| 72 |
# |
| 73 |
# Queries |
| 74 |
# |
| 75 |
pga_target_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga_target |
| 76 |
from V$PGASTAT where name = 'aggregate PGA target parameter'" |
| 77 |
|
| 78 |
pga_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga |
| 79 |
from V$PGASTAT where name = 'total PGA inuse'" |
| 80 |
|
| 81 |
pga_components = { "pga_target" => pga_target_query,
|
| 82 |
"pga_in_use" => pga_query |
| 83 |
} |
| 84 |
|
| 85 |
# |
| 86 |
# autoconf |
| 87 |
# |
| 88 |
if ARGV[0] == "autoconf" |
| 89 |
if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1 |
| 90 |
puts "yes" |
| 91 |
else |
| 92 |
puts "no" |
| 93 |
puts "Usage: #{__FILE__} autoconf|conf"
|
| 94 |
end |
| 95 |
exit 0 |
| 96 |
# |
| 97 |
# config definition |
| 98 |
# |
| 99 |
elsif ARGV[0] == "config" |
| 100 |
puts "graph_args --base 1024k -r --lower-limit 0" |
| 101 |
puts "graph_title Oracle PGA from #{dbname}"
|
| 102 |
puts "graph_category db" |
| 103 |
puts "graph_info This graph shows the PGA memory usage (in MB)" |
| 104 |
puts "graph_vlabel MB" |
| 105 |
puts "graph_scale no" |
| 106 |
puts "graph_period second" |
| 107 |
|
| 108 |
pga_components.keys.each do |p| |
| 109 |
puts "#{p}.label #{p}"
|
| 110 |
puts "#{p}.info PGA: #{p}"
|
| 111 |
puts "#{p}.type GAUGE"
|
| 112 |
puts "#{p}.draw LINE1"
|
| 113 |
end |
| 114 |
|
| 115 |
exit 0 |
| 116 |
end |
| 117 |
|
| 118 |
$conn = OCI8.new(orauser, orapass, tnsname) |
| 119 |
pga_components.each do |pc, query| |
| 120 |
runQuery(pc, query) |
| 121 |
end |
| 122 |
$conn.logoff |
