Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / oracle / oracle-sga @ 809639ab

Historique | Voir | Annoter | Télécharger (4,58 ko)

1 7a37bfb1 Lars Kruse
#!/usr/bin/env ruby
2 b0b39b01 Lars Kruse
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
Prerequistes:
25 809639ab Lars Kruse
  1) env.ORACLE_HOME set in munin-node
26
  2) rubygems
27
  3) oci8 - DBI gem for connecting to Oracle
28
     * instruction of installing oci8 is available here:
29
       http://ruby-oci8.rubyforge.org/en/InstallBinaryPackage.html
30 b0b39b01 Lars Kruse
31
Usage:
32 809639ab Lars Kruse
  1) copy this script to the munin install plugins directory (e.g. /usr/share/munin/plugins)
33
  2) chmod to allow executable to others
34
  3) create symbolic link in /etc/munin/plugins
35 b0b39b01 Lars Kruse
           ln -s /usr/share/munin/plugins/oracle_orcl_sga.rb /etc/munin/plugins/oracle_orcl_sga.rb
36
37
Parameters:
38 809639ab Lars Kruse
  autoconf
39
  config (required)
40 b0b39b01 Lars Kruse
41
Configurable variables:
42 809639ab Lars Kruse
  orauser : oracle user who has select privilege to query v$sgastat 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 b0b39b01 Lars Kruse
48 074e0ae0 Wilfred Chau
#%# family=auto
49
#%# capabilities=autoconf
50
51 b0b39b01 Lars Kruse
=end
52
53 074e0ae0 Wilfred Chau
require 'rubygems'
54
require 'oci8'
55
56
orauser  = 'munin'
57
orapass  = 'munin'
58
dbport   = 1522
59
dbname   = 'orcl'
60
dbhost   = 'localhost'
61
62 b0b39b01 Lars Kruse
tnsname = "(DESCRIPTION =
63 074e0ae0 Wilfred Chau
            (ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
64
            (CONNECT_DATA = (SID = #{dbname})))"
65
66 b0b39b01 Lars Kruse
def runQuery(name, query)
67
  rows = $conn.exec(query)
68 809639ab Lars Kruse
  puts "#{name}.value #{rows.fetch}"
69 b0b39b01 Lars Kruse
  rows.close
70 074e0ae0 Wilfred Chau
end
71
72
#
73
# Queries
74
#
75 17f78427 Lars Kruse
shared_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'shared pool',
76 074e0ae0 Wilfred Chau
                    decode(name, 'library cache',0,
77
                                 'dictionary chace',0,
78
                                 'free memory',0,
79
                                 'sql area',0,
80
                                 (bytes)/(1024*1024)),0)),2)) pool_misc
81
                    from V$SGASTAT"
82
83
buffer_cache_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL,
84
                     decode(name, 'db_block_buffers', (bytes)/(1024/1024),
85
                            'buffer_cache',(bytes)/(1024*1024),0),0)),2)) sga_bufcache
86
                     from V$SGASTAT"
87
88
fixed_area_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool,NULL,
89
                   decode(name, 'fixed_sga', (bytes)/(1024*1024),0),0)),2)) sga_fixed
90
                   from V$SGASTAT"
91
92
java_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'java pool', (bytes)/(1024*1024),0)),2)) sga_jpool
93
                   from V$SGASTAT"
94
95
large_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'large pool', (bytes)/(1024*1024),0)),2)) sga_lpool
96
                   from V$SGASTAT"
97
98
log_buffer_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, NULL,
99
                   decode(name, 'log_buffer', (bytes)/(1024*1024),0),0)),2)) sga_lbuffer
100 17f78427 Lars Kruse
                   from V$SGASTAT"
101 074e0ae0 Wilfred Chau
102 809639ab Lars Kruse
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 074e0ae0 Wilfred Chau
109
#
110
# autoconf
111
#
112 809639ab Lars Kruse
case ARGV[0]
113
when 'autoconf'
114 b0b39b01 Lars Kruse
  if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1
115 809639ab Lars Kruse
    puts 'yes'
116 b0b39b01 Lars Kruse
  else
117 809639ab Lars Kruse
    puts 'no'
118 b0b39b01 Lars Kruse
    puts "Usage: #{__FILE__} autoconf|conf"
119
  end
120
  exit 0
121 074e0ae0 Wilfred Chau
#
122
# config definition
123
#
124 809639ab Lars Kruse
when 'config'
125
  puts 'graph_args --base 1024k -r --lower-limit 0'
126 b0b39b01 Lars Kruse
  puts "graph_title Oracle SGA from #{dbname}"
127 809639ab Lars Kruse
  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 b0b39b01 Lars Kruse
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 809639ab Lars Kruse
    if m == 'fixed_area'
140 b0b39b01 Lars Kruse
      puts "#{m}.draw AREA"
141
    else
142
      puts "#{m}.draw STACK"
143
    end
144
  end
145
146
  exit 0
147 074e0ae0 Wilfred Chau
end
148
149
$conn = OCI8.new(orauser, orapass, tnsname)
150
memory_components.each do |mc, query|
151 b0b39b01 Lars Kruse
  runQuery(mc, query)
152 074e0ae0 Wilfred Chau
end
153
$conn.logoff