Class: Opstat::Plugins::OracleTablespacesSizes

Inherits:
Task
  • Object
show all
Defined in:
lib/plugins/oracle_tablespaces_sizes.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, queue, config) ⇒ OracleTablespacesSizes

Returns a new instance of OracleTablespacesSizes.



7
8
9
10
11
12
13
# File 'lib/plugins/oracle_tablespaces_sizes.rb', line 7

def initialize (name, queue, config)
  super(name, queue, config)
  self
  @su_user = config['su_user']
  @db_user = config['db_user']
  @db_password = config['db_password']
end

Instance Method Details

#parseObject



47
48
49
50
51
52
53
54
55
# File 'lib/plugins/oracle_tablespaces_sizes.rb', line 47

def parse
  report = []
  @cmd ||= sql_cmd.result(binding)
  oracle_output = IO.popen(@cmd)
  report  = oracle_output.readlines.join
  oracle_output.close
  oplogger.debug report
  return report
end

#sql_cmdObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/plugins/oracle_tablespaces_sizes.rb', line 15

def sql_cmd
  @query ||= ERB.new <<-EOF
su - <%= @su_user %> -c 'echo "     set pagesize 10000
             set heading on
             column dummy noprint
             column  name    format a19     heading \\\"Tablespace Name\\\"
             column  bytes   format 999999999999    heading \"Total\"
             column  used    format 999999999999   heading \"Used\"
             column  free    format 999999999999  heading \"Free\"

             select nvl(b.tablespace_name, nvl(a.tablespace_name,'"'UNKOWN'"')) name,
               bytes_alloc bytes,
               bytes_alloc-nvl(bytes_free,0) used,
               nvl(bytes_free,0) free
             from ( select sum(bytes) bytes_free,
                      tablespace_name
                    from  sys.dba_free_space
                    group by tablespace_name ) a,
                  ( select sum(bytes) bytes_alloc,
                      tablespace_name
                    from sys.dba_data_files
                    group by tablespace_name
                    union all
                    select sum(bytes) bytes_alloc,
                      tablespace_name
                    from sys.dba_temp_files
                    group by tablespace_name )b
                    where a.tablespace_name (+) = b.tablespace_name;
            "|sqlplus -S <%= @db_user %>/<%= @db_password %>' 
EOF
end