oracledb.chart.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. # -*- coding: utf-8 -*-
  2. # Description: oracledb netdata python.d module
  3. # Author: ilyam8 (Ilya Mashchenko)
  4. # SPDX-License-Identifier: GPL-3.0-or-later
  5. from copy import deepcopy
  6. from bases.FrameworkServices.SimpleService import SimpleService
  7. try:
  8. import oracledb as cx_Oracle
  9. HAS_ORACLE_NEW = True
  10. HAS_ORACLE_OLD = False
  11. except ImportError:
  12. HAS_ORACLE_NEW = False
  13. try:
  14. import cx_Oracle
  15. HAS_ORACLE_OLD = True
  16. except ImportError:
  17. HAS_ORACLE_OLD = False
  18. ORDER = [
  19. 'session_count',
  20. 'session_limit_usage',
  21. 'logons',
  22. 'physical_disk_read_write',
  23. 'sorts_on_disk',
  24. 'full_table_scans',
  25. 'database_wait_time_ratio',
  26. 'shared_pool_free_memory',
  27. 'in_memory_sorts_ratio',
  28. 'sql_service_response_time',
  29. 'user_rollbacks',
  30. 'enqueue_timeouts',
  31. 'cache_hit_ratio',
  32. 'global_cache_blocks',
  33. 'activity',
  34. 'wait_time',
  35. 'tablespace_size',
  36. 'tablespace_usage',
  37. 'tablespace_usage_in_percent',
  38. 'allocated_size',
  39. 'allocated_usage',
  40. 'allocated_usage_in_percent',
  41. ]
  42. CHARTS = {
  43. 'session_count': {
  44. 'options': [None, 'Session Count', 'sessions', 'session activity', 'oracledb.session_count', 'line'],
  45. 'lines': [
  46. ['session_count', 'total', 'absolute', 1, 1000],
  47. ['average_active_sessions', 'active', 'absolute', 1, 1000],
  48. ]
  49. },
  50. 'session_limit_usage': {
  51. 'options': [None, 'Session Limit Usage', '%', 'session activity', 'oracledb.session_limit_usage', 'area'],
  52. 'lines': [
  53. ['session_limit_percent', 'usage', 'absolute', 1, 1000],
  54. ]
  55. },
  56. 'logons': {
  57. 'options': [None, 'Logons', 'events/s', 'session activity', 'oracledb.logons', 'area'],
  58. 'lines': [
  59. ['logons_per_sec', 'logons', 'absolute', 1, 1000],
  60. ]
  61. },
  62. 'physical_disk_read_write': {
  63. 'options': [None, 'Physical Disk Reads/Writes', 'events/s', 'disk activity',
  64. 'oracledb.physical_disk_read_writes', 'area'],
  65. 'lines': [
  66. ['physical_reads_per_sec', 'reads', 'absolute', 1, 1000],
  67. ['physical_writes_per_sec', 'writes', 'absolute', -1, 1000],
  68. ]
  69. },
  70. 'sorts_on_disk': {
  71. 'options': [None, 'Sorts On Disk', 'events/s', 'disk activity', 'oracledb.sorts_on_disks', 'line'],
  72. 'lines': [
  73. ['disk_sort_per_sec', 'sorts', 'absolute', 1, 1000],
  74. ]
  75. },
  76. 'full_table_scans': {
  77. 'options': [None, 'Full Table Scans', 'events/s', 'disk activity', 'oracledb.full_table_scans', 'line'],
  78. 'lines': [
  79. ['long_table_scans_per_sec', 'full table scans', 'absolute', 1, 1000],
  80. ]
  81. },
  82. 'database_wait_time_ratio': {
  83. 'options': [None, 'Database Wait Time Ratio', '%', 'database and buffer activity',
  84. 'oracledb.database_wait_time_ratio', 'line'],
  85. 'lines': [
  86. ['database_wait_time_ratio', 'wait time ratio', 'absolute', 1, 1000],
  87. ]
  88. },
  89. 'shared_pool_free_memory': {
  90. 'options': [None, 'Shared Pool Free Memory', '%', 'database and buffer activity',
  91. 'oracledb.shared_pool_free_memory', 'line'],
  92. 'lines': [
  93. ['shared_pool_free_percent', 'free memory', 'absolute', 1, 1000],
  94. ]
  95. },
  96. 'in_memory_sorts_ratio': {
  97. 'options': [None, 'In-Memory Sorts Ratio', '%', 'database and buffer activity',
  98. 'oracledb.in_memory_sorts_ratio', 'line'],
  99. 'lines': [
  100. ['memory_sorts_ratio', 'in-memory sorts', 'absolute', 1, 1000],
  101. ]
  102. },
  103. 'sql_service_response_time': {
  104. 'options': [None, 'SQL Service Response Time', 'seconds', 'database and buffer activity',
  105. 'oracledb.sql_service_response_time', 'line'],
  106. 'lines': [
  107. ['sql_service_response_time', 'time', 'absolute', 1, 1000],
  108. ]
  109. },
  110. 'user_rollbacks': {
  111. 'options': [None, 'User Rollbacks', 'events/s', 'database and buffer activity',
  112. 'oracledb.user_rollbacks', 'line'],
  113. 'lines': [
  114. ['user_rollbacks_per_sec', 'rollbacks', 'absolute', 1, 1000],
  115. ]
  116. },
  117. 'enqueue_timeouts': {
  118. 'options': [None, 'Enqueue Timeouts', 'events/s', 'database and buffer activity',
  119. 'oracledb.enqueue_timeouts', 'line'],
  120. 'lines': [
  121. ['enqueue_timeouts_per_sec', 'enqueue timeouts', 'absolute', 1, 1000],
  122. ]
  123. },
  124. 'cache_hit_ratio': {
  125. 'options': [None, 'Cache Hit Ratio', '%', 'cache', 'oracledb.cache_hit_ration', 'stacked'],
  126. 'lines': [
  127. ['buffer_cache_hit_ratio', 'buffer', 'absolute', 1, 1000],
  128. ['cursor_cache_hit_ratio', 'cursor', 'absolute', 1, 1000],
  129. ['library_cache_hit_ratio', 'library', 'absolute', 1, 1000],
  130. ['row_cache_hit_ratio', 'row', 'absolute', 1, 1000],
  131. ]
  132. },
  133. 'global_cache_blocks': {
  134. 'options': [None, 'Global Cache Blocks Events', 'events/s', 'cache', 'oracledb.global_cache_blocks', 'area'],
  135. 'lines': [
  136. ['global_cache_blocks_corrupted', 'corrupted', 'incremental', 1, 1000],
  137. ['global_cache_blocks_lost', 'lost', 'incremental', 1, 1000],
  138. ]
  139. },
  140. 'activity': {
  141. 'options': [None, 'Activities', 'events/s', 'activities', 'oracledb.activity', 'stacked'],
  142. 'lines': [
  143. ['activity_parse_count_total', 'parse count', 'incremental', 1, 1000],
  144. ['activity_execute_count', 'execute count', 'incremental', 1, 1000],
  145. ['activity_user_commits', 'user commits', 'incremental', 1, 1000],
  146. ['activity_user_rollbacks', 'user rollbacks', 'incremental', 1, 1000],
  147. ]
  148. },
  149. 'wait_time': {
  150. 'options': [None, 'Wait Time', 'ms', 'wait time', 'oracledb.wait_time', 'stacked'],
  151. 'lines': [
  152. ['wait_time_application', 'application', 'absolute', 1, 1000],
  153. ['wait_time_configuration', 'configuration', 'absolute', 1, 1000],
  154. ['wait_time_administrative', 'administrative', 'absolute', 1, 1000],
  155. ['wait_time_concurrency', 'concurrency', 'absolute', 1, 1000],
  156. ['wait_time_commit', 'commit', 'absolute', 1, 1000],
  157. ['wait_time_network', 'network', 'absolute', 1, 1000],
  158. ['wait_time_user_io', 'user I/O', 'absolute', 1, 1000],
  159. ['wait_time_system_io', 'system I/O', 'absolute', 1, 1000],
  160. ['wait_time_scheduler', 'scheduler', 'absolute', 1, 1000],
  161. ['wait_time_other', 'other', 'absolute', 1, 1000],
  162. ]
  163. },
  164. 'tablespace_size': {
  165. 'options': [None, 'Size', 'KiB', 'tablespace', 'oracledb.tablespace_size', 'line'],
  166. 'lines': [],
  167. },
  168. 'tablespace_usage': {
  169. 'options': [None, 'Usage', 'KiB', 'tablespace', 'oracledb.tablespace_usage', 'line'],
  170. 'lines': [],
  171. },
  172. 'tablespace_usage_in_percent': {
  173. 'options': [None, 'Usage', '%', 'tablespace', 'oracledb.tablespace_usage_in_percent', 'line'],
  174. 'lines': [],
  175. },
  176. 'allocated_size': {
  177. 'options': [None, 'Size', 'B', 'tablespace', 'oracledb.allocated_size', 'line'],
  178. 'lines': [],
  179. },
  180. 'allocated_usage': {
  181. 'options': [None, 'Usage', 'B', 'tablespace', 'oracledb.allocated_usage', 'line'],
  182. 'lines': [],
  183. },
  184. 'allocated_usage_in_percent': {
  185. 'options': [None, 'Usage', '%', 'tablespace', 'oracledb.allocated_usage_in_percent', 'line'],
  186. 'lines': [],
  187. },
  188. }
  189. CX_CONNECT_STRING_OLD = "{0}/{1}@//{2}/{3}"
  190. QUERY_SYSTEM = '''
  191. SELECT
  192. metric_name,
  193. value
  194. FROM
  195. gv$sysmetric
  196. ORDER BY
  197. begin_time
  198. '''
  199. QUERY_TABLESPACE = '''
  200. SELECT
  201. m.tablespace_name,
  202. m.used_space * t.block_size AS used_bytes,
  203. m.tablespace_size * t.block_size AS max_bytes,
  204. m.used_percent
  205. FROM
  206. dba_tablespace_usage_metrics m
  207. JOIN dba_tablespaces t ON m.tablespace_name = t.tablespace_name
  208. '''
  209. QUERY_ALLOCATED = '''
  210. SELECT
  211. nvl(b.tablespace_name,nvl(a.tablespace_name,'UNKNOWN')) tablespace_name,
  212. bytes_alloc used_bytes,
  213. bytes_alloc-nvl(bytes_free,0) max_bytes,
  214. ((bytes_alloc-nvl(bytes_free,0))/ bytes_alloc)*100 used_percent
  215. FROM
  216. (SELECT
  217. sum(bytes) bytes_free,
  218. tablespace_name
  219. FROM sys.dba_free_space
  220. GROUP BY tablespace_name
  221. ) a,
  222. (SELECT
  223. sum(bytes) bytes_alloc,
  224. tablespace_name
  225. FROM sys.dba_data_files
  226. GROUP BY tablespace_name
  227. ) b
  228. WHERE a.tablespace_name (+) = b.tablespace_name
  229. '''
  230. QUERY_ACTIVITIES_COUNT = '''
  231. SELECT
  232. name,
  233. value
  234. FROM
  235. v$sysstat
  236. WHERE
  237. name IN (
  238. 'parse count (total)',
  239. 'execute count',
  240. 'user commits',
  241. 'user rollbacks'
  242. )
  243. '''
  244. QUERY_WAIT_TIME = '''
  245. SELECT
  246. n.wait_class,
  247. round(m.time_waited / m.INTSIZE_CSEC, 3)
  248. FROM
  249. v$waitclassmetric m,
  250. v$system_wait_class n
  251. WHERE
  252. m.wait_class_id = n.wait_class_id
  253. AND n.wait_class != 'Idle'
  254. '''
  255. # QUERY_SESSION_COUNT = '''
  256. # SELECT
  257. # status,
  258. # type
  259. # FROM
  260. # v$session
  261. # GROUP BY
  262. # status,
  263. # type
  264. # '''
  265. # QUERY_PROCESSES_COUNT = '''
  266. # SELECT
  267. # COUNT(*)
  268. # FROM
  269. # v$process
  270. # '''
  271. # QUERY_PROCESS = '''
  272. # SELECT
  273. # program,
  274. # pga_used_mem,
  275. # pga_alloc_mem,
  276. # pga_freeable_mem,
  277. # pga_max_mem
  278. # FROM
  279. # gv$process
  280. # '''
  281. # PROCESS_METRICS = [
  282. # 'pga_used_memory',
  283. # 'pga_allocated_memory',
  284. # 'pga_freeable_memory',
  285. # 'pga_maximum_memory',
  286. # ]
  287. SYS_METRICS = {
  288. 'Average Active Sessions': 'average_active_sessions',
  289. 'Session Count': 'session_count',
  290. 'Session Limit %': 'session_limit_percent',
  291. 'Logons Per Sec': 'logons_per_sec',
  292. 'Physical Reads Per Sec': 'physical_reads_per_sec',
  293. 'Physical Writes Per Sec': 'physical_writes_per_sec',
  294. 'Disk Sort Per Sec': 'disk_sort_per_sec',
  295. 'Long Table Scans Per Sec': 'long_table_scans_per_sec',
  296. 'Database Wait Time Ratio': 'database_wait_time_ratio',
  297. 'Shared Pool Free %': 'shared_pool_free_percent',
  298. 'Memory Sorts Ratio': 'memory_sorts_ratio',
  299. 'SQL Service Response Time': 'sql_service_response_time',
  300. 'User Rollbacks Per Sec': 'user_rollbacks_per_sec',
  301. 'Enqueue Timeouts Per Sec': 'enqueue_timeouts_per_sec',
  302. 'Buffer Cache Hit Ratio': 'buffer_cache_hit_ratio',
  303. 'Cursor Cache Hit Ratio': 'cursor_cache_hit_ratio',
  304. 'Library Cache Hit Ratio': 'library_cache_hit_ratio',
  305. 'Row Cache Hit Ratio': 'row_cache_hit_ratio',
  306. 'Global Cache Blocks Corrupted': 'global_cache_blocks_corrupted',
  307. 'Global Cache Blocks Lost': 'global_cache_blocks_lost',
  308. }
  309. class Service(SimpleService):
  310. def __init__(self, configuration=None, name=None):
  311. SimpleService.__init__(self, configuration=configuration, name=name)
  312. self.order = ORDER
  313. self.definitions = deepcopy(CHARTS)
  314. self.user = configuration.get('user')
  315. self.password = configuration.get('password')
  316. self.server = configuration.get('server')
  317. self.service = configuration.get('service')
  318. self.protocol = configuration.get('protocol', 'tcps')
  319. self.alive = False
  320. self.conn = None
  321. self.active_tablespaces = set()
  322. def connect(self):
  323. if self.conn:
  324. self.conn.close()
  325. self.conn = None
  326. if HAS_ORACLE_NEW:
  327. try:
  328. self.conn = cx_Oracle.connect(
  329. f'{self.user}/{self.password}@{self.protocol}://{self.server}/{self.service}')
  330. except cx_Oracle.DatabaseError as error:
  331. self.error(error)
  332. return False
  333. else:
  334. try:
  335. self.conn = cx_Oracle.connect(
  336. CX_CONNECT_STRING_OLD.format(
  337. self.user,
  338. self.password,
  339. self.server,
  340. self.service,
  341. ))
  342. except cx_Oracle.DatabaseError as error:
  343. self.error(error)
  344. return False
  345. self.alive = True
  346. return True
  347. def reconnect(self):
  348. return self.connect()
  349. def check(self):
  350. if not HAS_ORACLE_NEW and not HAS_ORACLE_OLD:
  351. self.error("'oracledb' package is needed to use oracledb module")
  352. return False
  353. if not all([
  354. self.user,
  355. self.password,
  356. self.server,
  357. self.service
  358. ]):
  359. self.error("one of these parameters is not specified: user, password, server, service")
  360. return False
  361. if not self.connect():
  362. return False
  363. return bool(self.get_data())
  364. def get_data(self):
  365. if not self.alive and not self.reconnect():
  366. return None
  367. data = dict()
  368. # SYSTEM
  369. try:
  370. rv = self.gather_system_metrics()
  371. except cx_Oracle.Error as error:
  372. self.error(error)
  373. self.alive = False
  374. return None
  375. else:
  376. for name, value in rv:
  377. if name not in SYS_METRICS:
  378. continue
  379. data[SYS_METRICS[name]] = int(float(value) * 1000)
  380. # ACTIVITIES COUNT
  381. try:
  382. rv = self.gather_activities_count()
  383. except cx_Oracle.Error as error:
  384. self.error(error)
  385. self.alive = False
  386. return None
  387. else:
  388. for name, amount in rv:
  389. cleaned = name.replace(' ', '_').replace('(', '').replace(')', '')
  390. new_name = 'activity_{0}'.format(cleaned)
  391. data[new_name] = int(float(amount) * 1000)
  392. # WAIT TIME
  393. try:
  394. rv = self.gather_wait_time_metrics()
  395. except cx_Oracle.Error as error:
  396. self.error(error)
  397. self.alive = False
  398. return None
  399. else:
  400. for name, amount in rv:
  401. cleaned = name.replace(' ', '_').replace('/', '').lower()
  402. new_name = 'wait_time_{0}'.format(cleaned)
  403. data[new_name] = amount
  404. # TABLESPACE
  405. try:
  406. rv = self.gather_tablespace_metrics()
  407. except cx_Oracle.Error as error:
  408. self.error(error)
  409. self.alive = False
  410. return None
  411. else:
  412. for name, offline, size, used, used_in_percent in rv:
  413. # TODO: skip offline?
  414. if not (not offline and self.charts):
  415. continue
  416. # TODO: remove inactive?
  417. if name not in self.active_tablespaces:
  418. self.active_tablespaces.add(name)
  419. self.add_tablespace_to_charts(name)
  420. data['{0}_tablespace_size'.format(name)] = int(size * 1000)
  421. data['{0}_tablespace_used'.format(name)] = int(used * 1000)
  422. data['{0}_tablespace_used_in_percent'.format(name)] = int(used_in_percent * 1000)
  423. # ALLOCATED SPACE
  424. try:
  425. rv = self.gather_allocated_metrics()
  426. except cx_Oracle.Error as error:
  427. self.error(error)
  428. self.alive = False
  429. return None
  430. else:
  431. for name, offline, size, used, used_in_percent in rv:
  432. # TODO: skip offline?
  433. if not (not offline and self.charts):
  434. continue
  435. # TODO: remove inactive?
  436. if name not in self.active_tablespaces:
  437. self.active_tablespaces.add(name)
  438. self.add_tablespace_to_charts(name)
  439. data['{0}_allocated_size'.format(name)] = int(size * 1000)
  440. data['{0}_allocated_used'.format(name)] = int(used * 1000)
  441. data['{0}_allocated_used_in_percent'.format(name)] = int(used_in_percent * 1000)
  442. return data or None
  443. def gather_system_metrics(self):
  444. """
  445. :return:
  446. [['Buffer Cache Hit Ratio', 100],
  447. ['Memory Sorts Ratio', 100],
  448. ['Redo Allocation Hit Ratio', 100],
  449. ['User Transaction Per Sec', 0],
  450. ['Physical Reads Per Sec', 0],
  451. ['Physical Reads Per Txn', 0],
  452. ['Physical Writes Per Sec', 0],
  453. ['Physical Writes Per Txn', 0],
  454. ['Physical Reads Direct Per Sec', 0],
  455. ['Physical Reads Direct Per Txn', 0],
  456. ['Physical Writes Direct Per Sec', 0],
  457. ['Physical Writes Direct Per Txn', 0],
  458. ['Physical Reads Direct Lobs Per Sec', 0],
  459. ['Physical Reads Direct Lobs Per Txn', 0],
  460. ['Physical Writes Direct Lobs Per Sec', 0],
  461. ['Physical Writes Direct Lobs Per Txn', 0],
  462. ['Redo Generated Per Sec', Decimal('4.66666666666667')],
  463. ['Redo Generated Per Txn', 280],
  464. ['Logons Per Sec', Decimal('0.0166666666666667')],
  465. ['Logons Per Txn', 1],
  466. ['Open Cursors Per Sec', 0.35],
  467. ['Open Cursors Per Txn', 21],
  468. ['User Commits Per Sec', 0],
  469. ['User Commits Percentage', 0],
  470. ['User Rollbacks Per Sec', 0],
  471. ['User Rollbacks Percentage', 0],
  472. ['User Calls Per Sec', Decimal('0.0333333333333333')],
  473. ['User Calls Per Txn', 2],
  474. ['Recursive Calls Per Sec', 14.15],
  475. ['Recursive Calls Per Txn', 849],
  476. ['Logical Reads Per Sec', Decimal('0.683333333333333')],
  477. ['Logical Reads Per Txn', 41],
  478. ['DBWR Checkpoints Per Sec', 0],
  479. ['Background Checkpoints Per Sec', 0],
  480. ['Redo Writes Per Sec', Decimal('0.0333333333333333')],
  481. ['Redo Writes Per Txn', 2],
  482. ['Long Table Scans Per Sec', 0],
  483. ['Long Table Scans Per Txn', 0],
  484. ['Total Table Scans Per Sec', Decimal('0.0166666666666667')],
  485. ['Total Table Scans Per Txn', 1],
  486. ['Full Index Scans Per Sec', 0],
  487. ['Full Index Scans Per Txn', 0],
  488. ['Total Index Scans Per Sec', Decimal('0.216666666666667')],
  489. ['Total Index Scans Per Txn', 13],
  490. ['Total Parse Count Per Sec', 0.35],
  491. ['Total Parse Count Per Txn', 21],
  492. ['Hard Parse Count Per Sec', 0],
  493. ['Hard Parse Count Per Txn', 0],
  494. ['Parse Failure Count Per Sec', 0],
  495. ['Parse Failure Count Per Txn', 0],
  496. ['Cursor Cache Hit Ratio', Decimal('52.3809523809524')],
  497. ['Disk Sort Per Sec', 0],
  498. ['Disk Sort Per Txn', 0],
  499. ['Rows Per Sort', 8.6],
  500. ['Execute Without Parse Ratio', Decimal('27.5862068965517')],
  501. ['Soft Parse Ratio', 100],
  502. ['User Calls Ratio', Decimal('0.235017626321974')],
  503. ['Host CPU Utilization (%)', Decimal('0.124311845142959')],
  504. ['Network Traffic Volume Per Sec', 0],
  505. ['Enqueue Timeouts Per Sec', 0],
  506. ['Enqueue Timeouts Per Txn', 0],
  507. ['Enqueue Waits Per Sec', 0],
  508. ['Enqueue Waits Per Txn', 0],
  509. ['Enqueue Deadlocks Per Sec', 0],
  510. ['Enqueue Deadlocks Per Txn', 0],
  511. ['Enqueue Requests Per Sec', Decimal('216.683333333333')],
  512. ['Enqueue Requests Per Txn', 13001],
  513. ['DB Block Gets Per Sec', 0],
  514. ['DB Block Gets Per Txn', 0],
  515. ['Consistent Read Gets Per Sec', Decimal('0.683333333333333')],
  516. ['Consistent Read Gets Per Txn', 41],
  517. ['DB Block Changes Per Sec', 0],
  518. ['DB Block Changes Per Txn', 0],
  519. ['Consistent Read Changes Per Sec', 0],
  520. ['Consistent Read Changes Per Txn', 0],
  521. ['CPU Usage Per Sec', 0],
  522. ['CPU Usage Per Txn', 0],
  523. ['CR Blocks Created Per Sec', 0],
  524. ['CR Blocks Created Per Txn', 0],
  525. ['CR Undo Records Applied Per Sec', 0],
  526. ['CR Undo Records Applied Per Txn', 0],
  527. ['User Rollback UndoRec Applied Per Sec', 0],
  528. ['User Rollback Undo Records Applied Per Txn', 0],
  529. ['Leaf Node Splits Per Sec', 0],
  530. ['Leaf Node Splits Per Txn', 0],
  531. ['Branch Node Splits Per Sec', 0],
  532. ['Branch Node Splits Per Txn', 0],
  533. ['PX downgraded 1 to 25% Per Sec', 0],
  534. ['PX downgraded 25 to 50% Per Sec', 0],
  535. ['PX downgraded 50 to 75% Per Sec', 0],
  536. ['PX downgraded 75 to 99% Per Sec', 0],
  537. ['PX downgraded to serial Per Sec', 0],
  538. ['Physical Read Total IO Requests Per Sec', Decimal('2.16666666666667')],
  539. ['Physical Read Total Bytes Per Sec', Decimal('35498.6666666667')],
  540. ['GC CR Block Received Per Second', 0],
  541. ['GC CR Block Received Per Txn', 0],
  542. ['GC Current Block Received Per Second', 0],
  543. ['GC Current Block Received Per Txn', 0],
  544. ['Global Cache Average CR Get Time', 0],
  545. ['Global Cache Average Current Get Time', 0],
  546. ['Physical Write Total IO Requests Per Sec', Decimal('0.966666666666667')],
  547. ['Global Cache Blocks Corrupted', 0],
  548. ['Global Cache Blocks Lost', 0],
  549. ['Current Logons Count', 49],
  550. ['Current Open Cursors Count', 64],
  551. ['User Limit %', Decimal('0.00000114087015416959')],
  552. ['SQL Service Response Time', 0],
  553. ['Database Wait Time Ratio', 0],
  554. ['Database CPU Time Ratio', 0],
  555. ['Response Time Per Txn', 0],
  556. ['Row Cache Hit Ratio', 100],
  557. ['Row Cache Miss Ratio', 0],
  558. ['Library Cache Hit Ratio', 100],
  559. ['Library Cache Miss Ratio', 0],
  560. ['Shared Pool Free %', Decimal('7.82380268491548')],
  561. ['PGA Cache Hit %', Decimal('98.0399767109115')],
  562. ['Process Limit %', Decimal('17.6666666666667')],
  563. ['Session Limit %', Decimal('15.2542372881356')],
  564. ['Executions Per Txn', 29],
  565. ['Executions Per Sec', Decimal('0.483333333333333')],
  566. ['Txns Per Logon', 0],
  567. ['Database Time Per Sec', 0],
  568. ['Physical Write Total Bytes Per Sec', 15308.8],
  569. ['Physical Read IO Requests Per Sec', 0],
  570. ['Physical Read Bytes Per Sec', 0],
  571. ['Physical Write IO Requests Per Sec', 0],
  572. ['Physical Write Bytes Per Sec', 0],
  573. ['DB Block Changes Per User Call', 0],
  574. ['DB Block Gets Per User Call', 0],
  575. ['Executions Per User Call', 14.5],
  576. ['Logical Reads Per User Call', 20.5],
  577. ['Total Sorts Per User Call', 2.5],
  578. ['Total Table Scans Per User Call', 0.5],
  579. ['Current OS Load', 0.0390625],
  580. ['Streams Pool Usage Percentage', 0],
  581. ['PQ QC Session Count', 0],
  582. ['PQ Slave Session Count', 0],
  583. ['Queries parallelized Per Sec', 0],
  584. ['DML statements parallelized Per Sec', 0],
  585. ['DDL statements parallelized Per Sec', 0],
  586. ['PX operations not downgraded Per Sec', 0],
  587. ['Session Count', 72],
  588. ['Average Synchronous Single-Block Read Latency', 0],
  589. ['I/O Megabytes per Second', 0.05],
  590. ['I/O Requests per Second', Decimal('3.13333333333333')],
  591. ['Average Active Sessions', 0],
  592. ['Active Serial Sessions', 1],
  593. ['Active Parallel Sessions', 0],
  594. ['Captured user calls', 0],
  595. ['Replayed user calls', 0],
  596. ['Workload Capture and Replay status', 0],
  597. ['Background CPU Usage Per Sec', Decimal('1.22578833333333')],
  598. ['Background Time Per Sec', 0.0147551],
  599. ['Host CPU Usage Per Sec', Decimal('0.116666666666667')],
  600. ['Cell Physical IO Interconnect Bytes', 3048448],
  601. ['Temp Space Used', 0],
  602. ['Total PGA Allocated', 200657920],
  603. ['Total PGA Used by SQL Workareas', 0],
  604. ['Run Queue Per Sec', 0],
  605. ['VM in bytes Per Sec', 0],
  606. ['VM out bytes Per Sec', 0]]
  607. """
  608. metrics = list()
  609. with self.conn.cursor() as cursor:
  610. cursor.execute(QUERY_SYSTEM)
  611. for metric_name, value in cursor.fetchall():
  612. metrics.append([metric_name, value])
  613. return metrics
  614. def gather_tablespace_metrics(self):
  615. """
  616. :return:
  617. [['SYSTEM', 874250240.0, 3233169408.0, 27.040038107400033, 0],
  618. ['SYSAUX', 498860032.0, 3233169408.0, 15.429443033997678, 0],
  619. ['TEMP', 0.0, 3233177600.0, 0.0, 0],
  620. ['USERS', 1048576.0, 3233169408.0, 0.03243182981397305, 0]]
  621. """
  622. metrics = list()
  623. with self.conn.cursor() as cursor:
  624. cursor.execute(QUERY_TABLESPACE)
  625. for tablespace_name, used_bytes, max_bytes, used_percent in cursor.fetchall():
  626. if used_bytes is None:
  627. offline = True
  628. used = 0
  629. else:
  630. offline = False
  631. used = float(used_bytes)
  632. if max_bytes is None:
  633. size = 0
  634. else:
  635. size = float(max_bytes)
  636. if used_percent is None:
  637. used_percent = 0
  638. else:
  639. used_percent = float(used_percent)
  640. metrics.append(
  641. [
  642. tablespace_name,
  643. offline,
  644. size,
  645. used,
  646. used_percent,
  647. ]
  648. )
  649. return metrics
  650. def gather_allocated_metrics(self):
  651. """
  652. :return:
  653. [['SYSTEM', 874250240.0, 3233169408.0, 27.040038107400033, 0],
  654. ['SYSAUX', 498860032.0, 3233169408.0, 15.429443033997678, 0],
  655. ['TEMP', 0.0, 3233177600.0, 0.0, 0],
  656. ['USERS', 1048576.0, 3233169408.0, 0.03243182981397305, 0]]
  657. """
  658. metrics = list()
  659. with self.conn.cursor() as cursor:
  660. cursor.execute(QUERY_ALLOCATED)
  661. for tablespace_name, used_bytes, max_bytes, used_percent in cursor.fetchall():
  662. if used_bytes is None:
  663. offline = True
  664. used = 0
  665. else:
  666. offline = False
  667. used = float(used_bytes)
  668. if max_bytes is None:
  669. size = 0
  670. else:
  671. size = float(max_bytes)
  672. if used_percent is None:
  673. used_percent = 0
  674. else:
  675. used_percent = float(used_percent)
  676. metrics.append(
  677. [
  678. tablespace_name,
  679. offline,
  680. size,
  681. used,
  682. used_percent,
  683. ]
  684. )
  685. return metrics
  686. def gather_wait_time_metrics(self):
  687. """
  688. :return:
  689. [['Other', 0],
  690. ['Application', 0],
  691. ['Configuration', 0],
  692. ['Administrative', 0],
  693. ['Concurrency', 0],
  694. ['Commit', 0],
  695. ['Network', 0],
  696. ['User I/O', 0],
  697. ['System I/O', 0.002],
  698. ['Scheduler', 0]]
  699. """
  700. metrics = list()
  701. with self.conn.cursor() as cursor:
  702. cursor.execute(QUERY_WAIT_TIME)
  703. for wait_class_name, value in cursor.fetchall():
  704. metrics.append([wait_class_name, value])
  705. return metrics
  706. def gather_activities_count(self):
  707. """
  708. :return:
  709. [('user commits', 9104),
  710. ('user rollbacks', 17),
  711. ('parse count (total)', 483695),
  712. ('execute count', 2020356)]
  713. """
  714. with self.conn.cursor() as cursor:
  715. cursor.execute(QUERY_ACTIVITIES_COUNT)
  716. return cursor.fetchall()
  717. # def gather_process_metrics(self):
  718. # """
  719. # :return:
  720. #
  721. # [['PSEUDO', 'pga_used_memory', 0],
  722. # ['PSEUDO', 'pga_allocated_memory', 0],
  723. # ['PSEUDO', 'pga_freeable_memory', 0],
  724. # ['PSEUDO', 'pga_maximum_memory', 0],
  725. # ['oracle@localhost.localdomain (PMON)', 'pga_used_memory', 1793827],
  726. # ['oracle@localhost.localdomain (PMON)', 'pga_allocated_memory', 1888651],
  727. # ['oracle@localhost.localdomain (PMON)', 'pga_freeable_memory', 0],
  728. # ['oracle@localhost.localdomain (PMON)', 'pga_maximum_memory', 1888651],
  729. # ...
  730. # ...
  731. # """
  732. #
  733. # metrics = list()
  734. # with self.conn.cursor() as cursor:
  735. # cursor.execute(QUERY_PROCESS)
  736. # for row in cursor.fetchall():
  737. # for i, name in enumerate(PROCESS_METRICS, 1):
  738. # metrics.append([row[0], name, row[i]])
  739. # return metrics
  740. # def gather_processes_count(self):
  741. # with self.conn.cursor() as cursor:
  742. # cursor.execute(QUERY_PROCESSES_COUNT)
  743. # return cursor.fetchone()[0] # 53
  744. # def gather_sessions_count(self):
  745. # with self.conn.cursor() as cursor:
  746. # cursor.execute(QUERY_SESSION_COUNT)
  747. # total, active, inactive = 0, 0, 0
  748. # for status, _ in cursor.fetchall():
  749. # total += 1
  750. # active += status == 'ACTIVE'
  751. # inactive += status == 'INACTIVE'
  752. # return [total, active, inactive]
  753. def add_tablespace_to_charts(self, name):
  754. self.charts['tablespace_size'].add_dimension(
  755. [
  756. '{0}_tablespace_size'.format(name),
  757. name,
  758. 'absolute',
  759. 1,
  760. 1024 * 1000,
  761. ])
  762. self.charts['tablespace_usage'].add_dimension(
  763. [
  764. '{0}_tablespace_used'.format(name),
  765. name,
  766. 'absolute',
  767. 1,
  768. 1024 * 1000,
  769. ])
  770. self.charts['tablespace_usage_in_percent'].add_dimension(
  771. [
  772. '{0}_tablespace_used_in_percent'.format(name),
  773. name,
  774. 'absolute',
  775. 1,
  776. 1000,
  777. ])
  778. self.charts['allocated_size'].add_dimension(
  779. [
  780. '{0}_allocated_size'.format(name),
  781. name,
  782. 'absolute',
  783. 1,
  784. 1000,
  785. ])
  786. self.charts['allocated_usage'].add_dimension(
  787. [
  788. '{0}_allocated_used'.format(name),
  789. name,
  790. 'absolute',
  791. 1,
  792. 1000,
  793. ])
  794. self.charts['allocated_usage_in_percent'].add_dimension(
  795. [
  796. '{0}_allocated_used_in_percent'.format(name),
  797. name,
  798. 'absolute',
  799. 1,
  800. 1000,
  801. ])