Projet

Général

Profil

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

root / plugins / oracle / oracle-pga-monitor @ 809639ab

Historique | Voir | Annoter | Télécharger (3,32 ko)

1
#!/usr/bin/env ruby
2

    
3
=begin
4

    
5
Munin Plugin for PGA memory components monitoring
6

    
7
Author: Wilfred Chau <openapp.developer@gmail.com>
8
Date: 2011-05-13
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_<sid>_pga.rb /etc/munin/plugins/oracle_<sid>_pga.rb
36
           ** replace <sid> with your oralce sid
37

    
38
Parameters:
39
  autoconf
40
  config (required)
41

    
42
Configurable variables:
43
  orauser : oracle user who has select privilege to query v$pgastat 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
#%# family=auto
50
#%# capabilities=autoconf
51

    
52
=end
53

    
54
require 'rubygems'
55
require 'oci8'
56

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

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

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

    
73
#
74
# Queries
75
#
76
pga_target_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga_target
77
                    from V$PGASTAT where name = 'aggregate PGA target parameter'"
78

    
79
pga_query = "SELECT TO_CHAR(ROUND(decode(unit,'bytes',(value)/(1024*1024),value),2)) pga
80
                     from V$PGASTAT where name = 'total PGA inuse'"
81

    
82
pga_components = { 'pga_target' => pga_target_query,
83
                   'pga_in_use' => pga_query }
84

    
85
#
86
# autoconf
87
#
88
case ARGV[0]
89
when 'autoconf'
90
  if tnsname.length > 1 && orauser.length > 1 && orapass.length > 1
91
    puts 'yes'
92
  else
93
    puts 'no'
94
    puts "Usage: #{__FILE__} autoconf|conf"
95
  end
96
  exit 0
97
#
98
# config definition
99
#
100
when 'config'
101
  puts 'graph_args --base 1024k -r --lower-limit 0'
102
  puts "graph_title Oracle PGA from #{dbname}"
103
  puts 'graph_category db'
104
  puts 'graph_info This graph shows the PGA memory usage (in MB)'
105
  puts 'graph_vlabel MB'
106
  puts 'graph_scale no'
107
  puts 'graph_period second'
108

    
109
  pga_components.keys.each do |p|
110
    puts "#{p}.label #{p}"
111
    puts "#{p}.info PGA: #{p}"
112
    puts "#{p}.type GAUGE"
113
    puts "#{p}.draw LINE1"
114
  end
115

    
116
  exit 0
117
end
118

    
119
$conn = OCI8.new(orauser, orapass, tnsname)
120
pga_components.each do |pc, query|
121
  runQuery(pc, query)
122
end
123
$conn.logoff