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
#!/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
Prerequistes:
25
  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

    
31
Usage:
32
  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
           ln -s /usr/share/munin/plugins/oracle_orcl_sga.rb /etc/munin/plugins/oracle_orcl_sga.rb
36

    
37
Parameters:
38
  autoconf
39
  config (required)
40

    
41
Configurable variables:
42
  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

    
48
#%# family=auto
49
#%# capabilities=autoconf
50

    
51
=end
52

    
53
require 'rubygems'
54
require 'oci8'
55

    
56
orauser  = 'munin'
57
orapass  = 'munin'
58
dbport   = 1522
59
dbname   = 'orcl'
60
dbhost   = 'localhost'
61

    
62
tnsname = "(DESCRIPTION =
63
            (ADDRESS = (PROTOCOL = TCP)(HOST = #{dbhost})(PORT = #{dbport}))
64
            (CONNECT_DATA = (SID = #{dbname})))"
65

    
66
def runQuery(name, query)
67
  rows = $conn.exec(query)
68
  puts "#{name}.value #{rows.fetch}"
69
  rows.close
70
end
71

    
72
#
73
# Queries
74
#
75
shared_pool_query = "SELECT TO_CHAR(ROUND(SUM(decode(pool, 'shared pool',
76
                    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
                   from V$SGASTAT"
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
# autoconf
111
#
112
case ARGV[0]
113
when '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
when '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
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