Created
March 23, 2017 10:02
-
-
Save jurgenhaas/da4e72a013f0099f1386ec106a8810ed to your computer and use it in GitHub Desktop.
Sample to monitor Oracle table space from Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
__author__ = 'jurgenhaas' | |
import subprocess | |
class Oracle: | |
def __init__(self, agentConfig, checksLogger, rawConfig): | |
self.agentConfig = agentConfig | |
self.checksLogger = checksLogger | |
self.rawConfig = rawConfig | |
def run(self): | |
system_names = {'SYSAUX': 1, 'SYSTEM': 2, 'UNDOTBS1': 3} | |
out = subprocess.check_output('/usr/bin/sd-agent/plugins/Oracle.sh') | |
r_allocated = 0 | |
r_used = 0 | |
r_percentage = 0 | |
r_allocated_userdata = 0 | |
r_used_userdata = 0 | |
r_percentage_userdata = 0 | |
r_percentage_max = 0 | |
try: | |
for name, allocated, used, blocks, percentage, dummy in [line.split('|') for line in out.splitlines()]: | |
print name.strip() + ':' | |
r_allocated += int(allocated) | |
r_used += float(used) | |
if name.strip() not in system_names: | |
print ' is userdata' | |
r_allocated_userdata += int(allocated) | |
r_used_userdata += float(used) | |
percentage = float(percentage.rstrip('%')) | |
if percentage > r_percentage_max: | |
r_percentage_max = percentage | |
except Exception, e: | |
pass | |
if r_allocated > 0: | |
r_percentage = r_used / r_allocated * 100 | |
if r_allocated_userdata > 0: | |
r_percentage_userdata = r_used_userdata / r_allocated_userdata * 100 | |
result = { | |
'allocated': str(r_allocated), | |
'allocated_userdata': str(r_allocated_userdata), | |
'used': str(r_used), | |
'used_userdata': str(r_used_userdata), | |
'percentage': str(r_percentage), | |
'percentage_userdata': str(r_percentage_userdata), | |
'percentage_max': str(r_percentage_max) | |
} | |
return result | |
if __name__ == '__main__': | |
oracle = Oracle(None, None, None) | |
print oracle.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe | |
export ORACLE_SID=XE | |
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh` | |
export ORACLE_BASE=/u01/app/oracle | |
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH | |
export PATH=$ORACLE_HOME/bin:$PATH | |
sqlplus -S sys/root as sysdba < Oracle.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set colsep '|' | |
set echo off | |
set feedback off | |
set linesize 1000 | |
set pagesize 0 | |
set sqlprompt '' | |
set trimspool on | |
set headsep off | |
select nvl(b.tablespace_name, | |
nvl(a.tablespace_name,'UNKNOWN')) | |
tablespace_name, | |
kbytes_alloc kbytes, | |
kbytes_alloc-nvl(kbytes_free,0) | |
size_alloc_bytes, | |
round(((kbytes_alloc-nvl(kbytes_free,0))/ kbytes_alloc)*200) used_chart, | |
to_char(((kbytes_alloc-nvl(kbytes_free,0))/ kbytes_alloc)*100, | |
'999G999G999G999G999G999G990D00') ||'%' used, | |
data_files | |
from ( select sum(bytes)/1024/1024 Kbytes_free, | |
max(bytes)/1024/1024 largest, | |
tablespace_name | |
from sys.dba_free_space | |
group by tablespace_name ) a, | |
( select sum(bytes)/1024/1024 Kbytes_alloc, | |
tablespace_name, | |
count(*) data_files | |
from sys.dba_data_files | |
group by tablespace_name ) b | |
where a.tablespace_name (+) = b.tablespace_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment