oracledb.chart.py 29 KB

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