mysql.chart.py 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. # -*- coding: utf-8 -*-
  2. # Description: MySQL netdata python.d module
  3. # Author: Pawel Krupa (paulfantom)
  4. # Author: Ilya Mashchenko (ilyam8)
  5. # SPDX-License-Identifier: GPL-3.0-or-later
  6. from bases.FrameworkServices.MySQLService import MySQLService
  7. # query executed on MySQL server
  8. QUERY_GLOBAL = 'SHOW GLOBAL STATUS;'
  9. QUERY_SLAVE = 'SHOW SLAVE STATUS;'
  10. QUERY_VARIABLES = 'SHOW GLOBAL VARIABLES LIKE \'max_connections\';'
  11. QUERY_USER_STATISTICS = 'SHOW USER_STATISTICS;'
  12. GLOBAL_STATS = [
  13. 'Bytes_received',
  14. 'Bytes_sent',
  15. 'Queries',
  16. 'Questions',
  17. 'Slow_queries',
  18. 'Handler_commit',
  19. 'Handler_delete',
  20. 'Handler_prepare',
  21. 'Handler_read_first',
  22. 'Handler_read_key',
  23. 'Handler_read_next',
  24. 'Handler_read_prev',
  25. 'Handler_read_rnd',
  26. 'Handler_read_rnd_next',
  27. 'Handler_rollback',
  28. 'Handler_savepoint',
  29. 'Handler_savepoint_rollback',
  30. 'Handler_update',
  31. 'Handler_write',
  32. 'Table_locks_immediate',
  33. 'Table_locks_waited',
  34. 'Select_full_join',
  35. 'Select_full_range_join',
  36. 'Select_range',
  37. 'Select_range_check',
  38. 'Select_scan',
  39. 'Sort_merge_passes',
  40. 'Sort_range',
  41. 'Sort_scan',
  42. 'Created_tmp_disk_tables',
  43. 'Created_tmp_files',
  44. 'Created_tmp_tables',
  45. 'Connections',
  46. 'Aborted_connects',
  47. 'Max_used_connections',
  48. 'Binlog_cache_disk_use',
  49. 'Binlog_cache_use',
  50. 'Threads_connected',
  51. 'Threads_created',
  52. 'Threads_cached',
  53. 'Threads_running',
  54. 'Thread_cache_misses',
  55. 'Innodb_data_read',
  56. 'Innodb_data_written',
  57. 'Innodb_data_reads',
  58. 'Innodb_data_writes',
  59. 'Innodb_data_fsyncs',
  60. 'Innodb_data_pending_reads',
  61. 'Innodb_data_pending_writes',
  62. 'Innodb_data_pending_fsyncs',
  63. 'Innodb_log_waits',
  64. 'Innodb_log_write_requests',
  65. 'Innodb_log_writes',
  66. 'Innodb_os_log_fsyncs',
  67. 'Innodb_os_log_pending_fsyncs',
  68. 'Innodb_os_log_pending_writes',
  69. 'Innodb_os_log_written',
  70. 'Innodb_row_lock_current_waits',
  71. 'Innodb_rows_inserted',
  72. 'Innodb_rows_read',
  73. 'Innodb_rows_updated',
  74. 'Innodb_rows_deleted',
  75. 'Innodb_buffer_pool_pages_data',
  76. 'Innodb_buffer_pool_pages_dirty',
  77. 'Innodb_buffer_pool_pages_free',
  78. 'Innodb_buffer_pool_pages_flushed',
  79. 'Innodb_buffer_pool_pages_misc',
  80. 'Innodb_buffer_pool_pages_total',
  81. 'Innodb_buffer_pool_bytes_data',
  82. 'Innodb_buffer_pool_bytes_dirty',
  83. 'Innodb_buffer_pool_read_ahead',
  84. 'Innodb_buffer_pool_read_ahead_evicted',
  85. 'Innodb_buffer_pool_read_ahead_rnd',
  86. 'Innodb_buffer_pool_read_requests',
  87. 'Innodb_buffer_pool_write_requests',
  88. 'Innodb_buffer_pool_reads',
  89. 'Innodb_buffer_pool_wait_free',
  90. 'Innodb_deadlocks',
  91. 'Qcache_hits',
  92. 'Qcache_lowmem_prunes',
  93. 'Qcache_inserts',
  94. 'Qcache_not_cached',
  95. 'Qcache_queries_in_cache',
  96. 'Qcache_free_memory',
  97. 'Qcache_free_blocks',
  98. 'Qcache_total_blocks',
  99. 'Key_blocks_unused',
  100. 'Key_blocks_used',
  101. 'Key_blocks_not_flushed',
  102. 'Key_read_requests',
  103. 'Key_write_requests',
  104. 'Key_reads',
  105. 'Key_writes',
  106. 'Open_files',
  107. 'Opened_files',
  108. 'Binlog_stmt_cache_disk_use',
  109. 'Binlog_stmt_cache_use',
  110. 'Connection_errors_accept',
  111. 'Connection_errors_internal',
  112. 'Connection_errors_max_connections',
  113. 'Connection_errors_peer_address',
  114. 'Connection_errors_select',
  115. 'Connection_errors_tcpwrap',
  116. 'Com_delete',
  117. 'Com_insert',
  118. 'Com_select',
  119. 'Com_update',
  120. 'Com_replace'
  121. ]
  122. GALERA_STATS = [
  123. 'wsrep_local_recv_queue',
  124. 'wsrep_local_send_queue',
  125. 'wsrep_received',
  126. 'wsrep_replicated',
  127. 'wsrep_received_bytes',
  128. 'wsrep_replicated_bytes',
  129. 'wsrep_local_bf_aborts',
  130. 'wsrep_local_cert_failures',
  131. 'wsrep_flow_control_paused_ns',
  132. 'wsrep_cluster_weight',
  133. 'wsrep_cluster_size',
  134. 'wsrep_cluster_status',
  135. 'wsrep_local_state',
  136. 'wsrep_open_transactions',
  137. 'wsrep_connected',
  138. 'wsrep_ready',
  139. 'wsrep_thread_count'
  140. ]
  141. def slave_seconds(value):
  142. try:
  143. return int(value)
  144. except (TypeError, ValueError):
  145. return -1
  146. def slave_running(value):
  147. return 1 if value == 'Yes' else -1
  148. SLAVE_STATS = [
  149. ('Seconds_Behind_Master', slave_seconds),
  150. ('Slave_SQL_Running', slave_running),
  151. ('Slave_IO_Running', slave_running)
  152. ]
  153. USER_STATISTICS = [
  154. 'Select_commands',
  155. 'Update_commands',
  156. 'Other_commands',
  157. 'Cpu_time',
  158. 'Rows_read',
  159. 'Rows_sent',
  160. 'Rows_deleted',
  161. 'Rows_inserted',
  162. 'Rows_updated'
  163. ]
  164. VARIABLES = [
  165. 'max_connections'
  166. ]
  167. ORDER = [
  168. 'net',
  169. 'queries',
  170. 'queries_type',
  171. 'handlers',
  172. 'table_locks',
  173. 'join_issues',
  174. 'sort_issues',
  175. 'tmp',
  176. 'connections',
  177. 'connections_active',
  178. 'connection_errors',
  179. 'binlog_cache',
  180. 'binlog_stmt_cache',
  181. 'threads',
  182. 'threads_creation_rate',
  183. 'thread_cache_misses',
  184. 'innodb_io',
  185. 'innodb_io_ops',
  186. 'innodb_io_pending_ops',
  187. 'innodb_log',
  188. 'innodb_os_log',
  189. 'innodb_os_log_fsync_writes',
  190. 'innodb_os_log_io',
  191. 'innodb_cur_row_lock',
  192. 'innodb_deadlocks',
  193. 'innodb_rows',
  194. 'innodb_buffer_pool_pages',
  195. 'innodb_buffer_pool_flush_pages_requests',
  196. 'innodb_buffer_pool_bytes',
  197. 'innodb_buffer_pool_read_ahead',
  198. 'innodb_buffer_pool_reqs',
  199. 'innodb_buffer_pool_ops',
  200. 'qcache_ops',
  201. 'qcache',
  202. 'qcache_freemem',
  203. 'qcache_memblocks',
  204. 'key_blocks',
  205. 'key_requests',
  206. 'key_disk_ops',
  207. 'files',
  208. 'files_rate',
  209. 'slave_behind',
  210. 'slave_status',
  211. 'galera_writesets',
  212. 'galera_bytes',
  213. 'galera_queue',
  214. 'galera_conflicts',
  215. 'galera_flow_control',
  216. 'galera_cluster_status',
  217. 'galera_cluster_state',
  218. 'galera_cluster_size',
  219. 'galera_cluster_weight',
  220. 'galera_connected',
  221. 'galera_ready',
  222. 'galera_open_transactions',
  223. 'galera_thread_count',
  224. 'userstats_cpu',
  225. ]
  226. CHARTS = {
  227. 'net': {
  228. 'options': [None, 'Bandwidth', 'kilobits/s', 'bandwidth', 'mysql.net', 'area'],
  229. 'lines': [
  230. ['Bytes_received', 'in', 'incremental', 8, 1000],
  231. ['Bytes_sent', 'out', 'incremental', -8, 1000]
  232. ]
  233. },
  234. 'queries': {
  235. 'options': [None, 'Queries', 'queries/s', 'queries', 'mysql.queries', 'line'],
  236. 'lines': [
  237. ['Queries', 'queries', 'incremental'],
  238. ['Questions', 'questions', 'incremental'],
  239. ['Slow_queries', 'slow_queries', 'incremental']
  240. ]
  241. },
  242. 'queries_type': {
  243. 'options': [None, 'Query Type', 'queries/s', 'query_types', 'mysql.queries_type', 'stacked'],
  244. 'lines': [
  245. ['Com_select', 'select', 'incremental'],
  246. ['Com_delete', 'delete', 'incremental'],
  247. ['Com_update', 'update', 'incremental'],
  248. ['Com_insert', 'insert', 'incremental'],
  249. ['Qcache_hits', 'cache_hits', 'incremental'],
  250. ['Com_replace', 'replace', 'incremental']
  251. ]
  252. },
  253. 'handlers': {
  254. 'options': [None, 'Handlers', 'handlers/s', 'handlers', 'mysql.handlers', 'line'],
  255. 'lines': [
  256. ['Handler_commit', 'commit', 'incremental'],
  257. ['Handler_delete', 'delete', 'incremental'],
  258. ['Handler_prepare', 'prepare', 'incremental'],
  259. ['Handler_read_first', 'read_first', 'incremental'],
  260. ['Handler_read_key', 'read_key', 'incremental'],
  261. ['Handler_read_next', 'read_next', 'incremental'],
  262. ['Handler_read_prev', 'read_prev', 'incremental'],
  263. ['Handler_read_rnd', 'read_rnd', 'incremental'],
  264. ['Handler_read_rnd_next', 'read_rnd_next', 'incremental'],
  265. ['Handler_rollback', 'rollback', 'incremental'],
  266. ['Handler_savepoint', 'savepoint', 'incremental'],
  267. ['Handler_savepoint_rollback', 'savepoint_rollback', 'incremental'],
  268. ['Handler_update', 'update', 'incremental'],
  269. ['Handler_write', 'write', 'incremental']
  270. ]
  271. },
  272. 'table_locks': {
  273. 'options': [None, 'Tables Locks', 'locks/s', 'locks', 'mysql.table_locks', 'line'],
  274. 'lines': [
  275. ['Table_locks_immediate', 'immediate', 'incremental'],
  276. ['Table_locks_waited', 'waited', 'incremental', -1, 1]
  277. ]
  278. },
  279. 'join_issues': {
  280. 'options': [None, 'Select Join Issues', 'joins/s', 'issues', 'mysql.join_issues', 'line'],
  281. 'lines': [
  282. ['Select_full_join', 'full_join', 'incremental'],
  283. ['Select_full_range_join', 'full_range_join', 'incremental'],
  284. ['Select_range', 'range', 'incremental'],
  285. ['Select_range_check', 'range_check', 'incremental'],
  286. ['Select_scan', 'scan', 'incremental']
  287. ]
  288. },
  289. 'sort_issues': {
  290. 'options': [None, 'Sort Issues', 'issues/s', 'issues', 'mysql.sort_issues', 'line'],
  291. 'lines': [
  292. ['Sort_merge_passes', 'merge_passes', 'incremental'],
  293. ['Sort_range', 'range', 'incremental'],
  294. ['Sort_scan', 'scan', 'incremental']
  295. ]
  296. },
  297. 'tmp': {
  298. 'options': [None, 'Tmp Operations', 'counter', 'temporaries', 'mysql.tmp', 'line'],
  299. 'lines': [
  300. ['Created_tmp_disk_tables', 'disk_tables', 'incremental'],
  301. ['Created_tmp_files', 'files', 'incremental'],
  302. ['Created_tmp_tables', 'tables', 'incremental']
  303. ]
  304. },
  305. 'connections': {
  306. 'options': [None, 'Connections', 'connections/s', 'connections', 'mysql.connections', 'line'],
  307. 'lines': [
  308. ['Connections', 'all', 'incremental'],
  309. ['Aborted_connects', 'aborted', 'incremental']
  310. ]
  311. },
  312. 'connections_active': {
  313. 'options': [None, 'Connections Active', 'connections', 'connections', 'mysql.connections_active', 'line'],
  314. 'lines': [
  315. ['Threads_connected', 'active', 'absolute'],
  316. ['max_connections', 'limit', 'absolute'],
  317. ['Max_used_connections', 'max_active', 'absolute']
  318. ]
  319. },
  320. 'binlog_cache': {
  321. 'options': [None, 'Binlog Cache', 'transactions/s', 'binlog', 'mysql.binlog_cache', 'line'],
  322. 'lines': [
  323. ['Binlog_cache_disk_use', 'disk', 'incremental'],
  324. ['Binlog_cache_use', 'all', 'incremental']
  325. ]
  326. },
  327. 'threads': {
  328. 'options': [None, 'Threads', 'threads', 'threads', 'mysql.threads', 'line'],
  329. 'lines': [
  330. ['Threads_connected', 'connected', 'absolute'],
  331. ['Threads_cached', 'cached', 'absolute', -1, 1],
  332. ['Threads_running', 'running', 'absolute'],
  333. ]
  334. },
  335. 'threads_creation_rate': {
  336. 'options': [None, 'Threads Creation Rate', 'threads/s', 'threads', 'mysql.threads_creation_rate', 'line'],
  337. 'lines': [
  338. ['Threads_created', 'created', 'incremental'],
  339. ]
  340. },
  341. 'thread_cache_misses': {
  342. 'options': [None, 'mysql Threads Cache Misses', 'misses', 'threads', 'mysql.thread_cache_misses', 'area'],
  343. 'lines': [
  344. ['Thread_cache_misses', 'misses', 'absolute', 1, 100]
  345. ]
  346. },
  347. 'innodb_io': {
  348. 'options': [None, 'InnoDB I/O Bandwidth', 'KiB/s', 'innodb', 'mysql.innodb_io', 'area'],
  349. 'lines': [
  350. ['Innodb_data_read', 'read', 'incremental', 1, 1024],
  351. ['Innodb_data_written', 'write', 'incremental', -1, 1024]
  352. ]
  353. },
  354. 'innodb_io_ops': {
  355. 'options': [None, 'InnoDB I/O Operations', 'operations/s', 'innodb', 'mysql.innodb_io_ops', 'line'],
  356. 'lines': [
  357. ['Innodb_data_reads', 'reads', 'incremental'],
  358. ['Innodb_data_writes', 'writes', 'incremental', -1, 1],
  359. ['Innodb_data_fsyncs', 'fsyncs', 'incremental']
  360. ]
  361. },
  362. 'innodb_io_pending_ops': {
  363. 'options': [None, 'InnoDB Pending I/O Operations', 'operations', 'innodb',
  364. 'mysql.innodb_io_pending_ops', 'line'],
  365. 'lines': [
  366. ['Innodb_data_pending_reads', 'reads', 'absolute'],
  367. ['Innodb_data_pending_writes', 'writes', 'absolute', -1, 1],
  368. ['Innodb_data_pending_fsyncs', 'fsyncs', 'absolute']
  369. ]
  370. },
  371. 'innodb_log': {
  372. 'options': [None, 'InnoDB Log Operations', 'operations/s', 'innodb', 'mysql.innodb_log', 'line'],
  373. 'lines': [
  374. ['Innodb_log_waits', 'waits', 'incremental'],
  375. ['Innodb_log_write_requests', 'write_requests', 'incremental', -1, 1],
  376. ['Innodb_log_writes', 'writes', 'incremental', -1, 1],
  377. ]
  378. },
  379. 'innodb_os_log': {
  380. 'options': [None, 'InnoDB OS Log Pending Operations', 'operations', 'innodb', 'mysql.innodb_os_log', 'line'],
  381. 'lines': [
  382. ['Innodb_os_log_pending_fsyncs', 'fsyncs', 'absolute'],
  383. ['Innodb_os_log_pending_writes', 'writes', 'absolute', -1, 1],
  384. ]
  385. },
  386. 'innodb_os_log_fsync_writes': {
  387. 'options': [None, 'InnoDB OS Log Operations', 'operations/s', 'innodb', 'mysql.innodb_os_log_fsyncs', 'line'],
  388. 'lines': [
  389. ['Innodb_os_log_fsyncs', 'fsyncs', 'incremental'],
  390. ]
  391. },
  392. 'innodb_os_log_io': {
  393. 'options': [None, 'InnoDB OS Log Bandwidth', 'KiB/s', 'innodb', 'mysql.innodb_os_log_io', 'area'],
  394. 'lines': [
  395. ['Innodb_os_log_written', 'write', 'incremental', -1, 1024],
  396. ]
  397. },
  398. 'innodb_cur_row_lock': {
  399. 'options': [None, 'InnoDB Current Row Locks', 'operations', 'innodb',
  400. 'mysql.innodb_cur_row_lock', 'area'],
  401. 'lines': [
  402. ['Innodb_row_lock_current_waits', 'current_waits', 'absolute']
  403. ]
  404. },
  405. 'innodb_deadlocks': {
  406. 'options': [None, 'InnoDB Deadlocks', 'operations/s', 'innodb',
  407. 'mysql.innodb_deadlocks', 'area'],
  408. 'lines': [
  409. ['Innodb_deadlocks', 'deadlocks', 'incremental']
  410. ]
  411. },
  412. 'innodb_rows': {
  413. 'options': [None, 'InnoDB Row Operations', 'operations/s', 'innodb', 'mysql.innodb_rows', 'area'],
  414. 'lines': [
  415. ['Innodb_rows_inserted', 'inserted', 'incremental'],
  416. ['Innodb_rows_read', 'read', 'incremental', 1, 1],
  417. ['Innodb_rows_updated', 'updated', 'incremental', 1, 1],
  418. ['Innodb_rows_deleted', 'deleted', 'incremental', -1, 1],
  419. ]
  420. },
  421. 'innodb_buffer_pool_pages': {
  422. 'options': [None, 'InnoDB Buffer Pool Pages', 'pages', 'innodb',
  423. 'mysql.innodb_buffer_pool_pages', 'line'],
  424. 'lines': [
  425. ['Innodb_buffer_pool_pages_data', 'data', 'absolute'],
  426. ['Innodb_buffer_pool_pages_dirty', 'dirty', 'absolute', -1, 1],
  427. ['Innodb_buffer_pool_pages_free', 'free', 'absolute'],
  428. ['Innodb_buffer_pool_pages_misc', 'misc', 'absolute', -1, 1],
  429. ['Innodb_buffer_pool_pages_total', 'total', 'absolute']
  430. ]
  431. },
  432. 'innodb_buffer_pool_flush_pages_requests': {
  433. 'options': [None, 'InnoDB Buffer Pool Flush Pages Requests', 'requests/s', 'innodb',
  434. 'mysql.innodb_buffer_pool_pages_flushed', 'line'],
  435. 'lines': [
  436. ['Innodb_buffer_pool_pages_flushed', 'flush pages', 'incremental'],
  437. ]
  438. },
  439. 'innodb_buffer_pool_bytes': {
  440. 'options': [None, 'InnoDB Buffer Pool Bytes', 'MiB', 'innodb', 'mysql.innodb_buffer_pool_bytes', 'area'],
  441. 'lines': [
  442. ['Innodb_buffer_pool_bytes_data', 'data', 'absolute', 1, 1024 * 1024],
  443. ['Innodb_buffer_pool_bytes_dirty', 'dirty', 'absolute', -1, 1024 * 1024]
  444. ]
  445. },
  446. 'innodb_buffer_pool_read_ahead': {
  447. 'options': [None, 'mysql InnoDB Buffer Pool Read Ahead', 'operations/s', 'innodb',
  448. 'mysql.innodb_buffer_pool_read_ahead', 'area'],
  449. 'lines': [
  450. ['Innodb_buffer_pool_read_ahead', 'all', 'incremental'],
  451. ['Innodb_buffer_pool_read_ahead_evicted', 'evicted', 'incremental', -1, 1],
  452. ['Innodb_buffer_pool_read_ahead_rnd', 'random', 'incremental']
  453. ]
  454. },
  455. 'innodb_buffer_pool_reqs': {
  456. 'options': [None, 'InnoDB Buffer Pool Requests', 'requests/s', 'innodb',
  457. 'mysql.innodb_buffer_pool_reqs', 'area'],
  458. 'lines': [
  459. ['Innodb_buffer_pool_read_requests', 'reads', 'incremental'],
  460. ['Innodb_buffer_pool_write_requests', 'writes', 'incremental', -1, 1]
  461. ]
  462. },
  463. 'innodb_buffer_pool_ops': {
  464. 'options': [None, 'InnoDB Buffer Pool Operations', 'operations/s', 'innodb',
  465. 'mysql.innodb_buffer_pool_ops', 'area'],
  466. 'lines': [
  467. ['Innodb_buffer_pool_reads', 'disk reads', 'incremental'],
  468. ['Innodb_buffer_pool_wait_free', 'wait free', 'incremental', -1, 1]
  469. ]
  470. },
  471. 'qcache_ops': {
  472. 'options': [None, 'QCache Operations', 'queries/s', 'qcache', 'mysql.qcache_ops', 'line'],
  473. 'lines': [
  474. ['Qcache_hits', 'hits', 'incremental'],
  475. ['Qcache_lowmem_prunes', 'lowmem prunes', 'incremental', -1, 1],
  476. ['Qcache_inserts', 'inserts', 'incremental'],
  477. ['Qcache_not_cached', 'not cached', 'incremental', -1, 1]
  478. ]
  479. },
  480. 'qcache': {
  481. 'options': [None, 'QCache Queries in Cache', 'queries', 'qcache', 'mysql.qcache', 'line'],
  482. 'lines': [
  483. ['Qcache_queries_in_cache', 'queries', 'absolute']
  484. ]
  485. },
  486. 'qcache_freemem': {
  487. 'options': [None, 'QCache Free Memory', 'MiB', 'qcache', 'mysql.qcache_freemem', 'area'],
  488. 'lines': [
  489. ['Qcache_free_memory', 'free', 'absolute', 1, 1024 * 1024]
  490. ]
  491. },
  492. 'qcache_memblocks': {
  493. 'options': [None, 'QCache Memory Blocks', 'blocks', 'qcache', 'mysql.qcache_memblocks', 'line'],
  494. 'lines': [
  495. ['Qcache_free_blocks', 'free', 'absolute'],
  496. ['Qcache_total_blocks', 'total', 'absolute']
  497. ]
  498. },
  499. 'key_blocks': {
  500. 'options': [None, 'MyISAM Key Cache Blocks', 'blocks', 'myisam', 'mysql.key_blocks', 'line'],
  501. 'lines': [
  502. ['Key_blocks_unused', 'unused', 'absolute'],
  503. ['Key_blocks_used', 'used', 'absolute', -1, 1],
  504. ['Key_blocks_not_flushed', 'not flushed', 'absolute']
  505. ]
  506. },
  507. 'key_requests': {
  508. 'options': [None, 'MyISAM Key Cache Requests', 'requests/s', 'myisam', 'mysql.key_requests', 'area'],
  509. 'lines': [
  510. ['Key_read_requests', 'reads', 'incremental'],
  511. ['Key_write_requests', 'writes', 'incremental', -1, 1]
  512. ]
  513. },
  514. 'key_disk_ops': {
  515. 'options': [None, 'MyISAM Key Cache Disk Operations', 'operations/s',
  516. 'myisam', 'mysql.key_disk_ops', 'area'],
  517. 'lines': [
  518. ['Key_reads', 'reads', 'incremental'],
  519. ['Key_writes', 'writes', 'incremental', -1, 1]
  520. ]
  521. },
  522. 'files': {
  523. 'options': [None, 'Open Files', 'files', 'files', 'mysql.files', 'line'],
  524. 'lines': [
  525. ['Open_files', 'files', 'absolute']
  526. ]
  527. },
  528. 'files_rate': {
  529. 'options': [None, 'Opened Files Rate', 'files/s', 'files', 'mysql.files_rate', 'line'],
  530. 'lines': [
  531. ['Opened_files', 'files', 'incremental']
  532. ]
  533. },
  534. 'binlog_stmt_cache': {
  535. 'options': [None, 'Binlog Statement Cache', 'statements/s', 'binlog',
  536. 'mysql.binlog_stmt_cache', 'line'],
  537. 'lines': [
  538. ['Binlog_stmt_cache_disk_use', 'disk', 'incremental'],
  539. ['Binlog_stmt_cache_use', 'all', 'incremental']
  540. ]
  541. },
  542. 'connection_errors': {
  543. 'options': [None, 'Connection Errors', 'connections/s', 'connections',
  544. 'mysql.connection_errors', 'line'],
  545. 'lines': [
  546. ['Connection_errors_accept', 'accept', 'incremental'],
  547. ['Connection_errors_internal', 'internal', 'incremental'],
  548. ['Connection_errors_max_connections', 'max', 'incremental'],
  549. ['Connection_errors_peer_address', 'peer_addr', 'incremental'],
  550. ['Connection_errors_select', 'select', 'incremental'],
  551. ['Connection_errors_tcpwrap', 'tcpwrap', 'incremental']
  552. ]
  553. },
  554. 'slave_behind': {
  555. 'options': [None, 'Slave Behind Seconds', 'seconds', 'slave', 'mysql.slave_behind', 'line'],
  556. 'lines': [
  557. ['Seconds_Behind_Master', 'seconds', 'absolute']
  558. ]
  559. },
  560. 'slave_status': {
  561. 'options': [None, 'Slave Status', 'status', 'slave', 'mysql.slave_status', 'line'],
  562. 'lines': [
  563. ['Slave_SQL_Running', 'sql_running', 'absolute'],
  564. ['Slave_IO_Running', 'io_running', 'absolute']
  565. ]
  566. },
  567. 'galera_writesets': {
  568. 'options': [None, 'Replicated Writesets', 'writesets/s', 'galera', 'mysql.galera_writesets', 'line'],
  569. 'lines': [
  570. ['wsrep_received', 'rx', 'incremental'],
  571. ['wsrep_replicated', 'tx', 'incremental', -1, 1],
  572. ]
  573. },
  574. 'galera_bytes': {
  575. 'options': [None, 'Replicated Bytes', 'KiB/s', 'galera', 'mysql.galera_bytes', 'area'],
  576. 'lines': [
  577. ['wsrep_received_bytes', 'rx', 'incremental', 1, 1024],
  578. ['wsrep_replicated_bytes', 'tx', 'incremental', -1, 1024],
  579. ]
  580. },
  581. 'galera_queue': {
  582. 'options': [None, 'Galera Queue', 'writesets', 'galera', 'mysql.galera_queue', 'line'],
  583. 'lines': [
  584. ['wsrep_local_recv_queue', 'rx', 'absolute'],
  585. ['wsrep_local_send_queue', 'tx', 'absolute', -1, 1],
  586. ]
  587. },
  588. 'galera_conflicts': {
  589. 'options': [None, 'Replication Conflicts', 'transactions', 'galera', 'mysql.galera_conflicts', 'area'],
  590. 'lines': [
  591. ['wsrep_local_bf_aborts', 'bf_aborts', 'incremental'],
  592. ['wsrep_local_cert_failures', 'cert_fails', 'incremental', -1, 1],
  593. ]
  594. },
  595. 'galera_flow_control': {
  596. 'options': [None, 'Flow Control', 'millisec', 'galera', 'mysql.galera_flow_control', 'area'],
  597. 'lines': [
  598. ['wsrep_flow_control_paused_ns', 'paused', 'incremental', 1, 1000000],
  599. ]
  600. },
  601. 'galera_cluster_status': {
  602. 'options': [None, 'Cluster Component Status', 'status', 'galera', 'mysql.galera_cluster_status', 'line'],
  603. 'lines': [
  604. ['wsrep_cluster_status', 'status', 'absolute'],
  605. ]
  606. },
  607. 'galera_cluster_state': {
  608. 'options': [None, 'Cluster Component State', 'state', 'galera', 'mysql.galera_cluster_state', 'line'],
  609. 'lines': [
  610. ['wsrep_local_state', 'state', 'absolute'],
  611. ]
  612. },
  613. 'galera_cluster_size': {
  614. 'options': [None, 'Number of Nodes in the Cluster', 'num', 'galera', 'mysql.galera_cluster_size', 'line'],
  615. 'lines': [
  616. ['wsrep_cluster_size', 'nodes', 'absolute'],
  617. ]
  618. },
  619. 'galera_cluster_weight': {
  620. 'options': [None, 'The Total Weight of the Current Members in the Cluster', 'weight', 'galera',
  621. 'mysql.galera_cluster_weight', 'line'],
  622. 'lines': [
  623. ['wsrep_cluster_weight', 'weight', 'absolute'],
  624. ]
  625. },
  626. 'galera_connected': {
  627. 'options': [None, 'Whether the Node is Connected to the Cluster', 'boolean', 'galera',
  628. 'mysql.galera_connected', 'line'],
  629. 'lines': [
  630. ['wsrep_connected', 'connected', 'absolute'],
  631. ]
  632. },
  633. 'galera_ready': {
  634. 'options': [None, 'Whether the Node is Ready to Accept Queries', 'boolean', 'galera',
  635. 'mysql.galera_ready', 'line'],
  636. 'lines': [
  637. ['wsrep_ready', 'ready', 'absolute'],
  638. ]
  639. },
  640. 'galera_open_transactions': {
  641. 'options': [None, 'Open Transactions', 'num', 'galera', 'mysql.galera_open_transactions', 'line'],
  642. 'lines': [
  643. ['wsrep_open_transactions', 'open transactions', 'absolute'],
  644. ]
  645. },
  646. 'galera_thread_count': {
  647. 'options': [None, 'Total Number of WSRep (applier/rollbacker) Threads', 'num', 'galera',
  648. 'mysql.galera_thread_count', 'line'],
  649. 'lines': [
  650. ['wsrep_thread_count', 'threads', 'absolute'],
  651. ]
  652. },
  653. 'userstats_cpu': {
  654. 'options': [None, 'Users CPU time', 'percentage', 'userstats', 'mysql.userstats_cpu', 'stacked'],
  655. 'lines': []
  656. }
  657. }
  658. def slave_status_chart_template(channel_name):
  659. order = [
  660. 'slave_behind_{0}'.format(channel_name),
  661. 'slave_status_{0}'.format(channel_name)
  662. ]
  663. charts = {
  664. order[0]: {
  665. 'options': [None, 'Slave Behind Seconds Channel {0}'.format(channel_name),
  666. 'seconds', 'slave', 'mysql.slave_behind', 'line'],
  667. 'lines': [
  668. ['Seconds_Behind_Master_{0}'.format(channel_name), 'seconds', 'absolute']
  669. ]
  670. },
  671. order[1]: {
  672. 'options': [None, 'Slave Status Channel {0}'.format(channel_name),
  673. 'status', 'slave', 'mysql.slave_status', 'line'],
  674. 'lines': [
  675. ['Slave_SQL_Running_{0}'.format(channel_name), 'sql_running', 'absolute'],
  676. ['Slave_IO_Running_{0}'.format(channel_name), 'io_running', 'absolute']
  677. ]
  678. },
  679. }
  680. return order, charts
  681. def userstats_chart_template(name):
  682. order = [
  683. 'userstats_rows_{0}'.format(name),
  684. 'userstats_commands_{0}'.format(name)
  685. ]
  686. family = 'userstats {0}'.format(name)
  687. charts = {
  688. order[0]: {
  689. 'options': [None, 'Rows Operations', 'operations/s', family, 'mysql.userstats_rows', 'stacked'],
  690. 'lines': [
  691. ['userstats_{0}_Rows_read'.format(name), 'read', 'incremental'],
  692. ['userstats_{0}_Rows_send'.format(name), 'send', 'incremental'],
  693. ['userstats_{0}_Rows_updated'.format(name), 'updated', 'incremental'],
  694. ['userstats_{0}_Rows_inserted'.format(name), 'inserted', 'incremental'],
  695. ['userstats_{0}_Rows_deleted'.format(name), 'deleted', 'incremental']
  696. ]
  697. },
  698. order[1]: {
  699. 'options': [None, 'Commands', 'commands/s', family, 'mysql.userstats_commands', 'stacked'],
  700. 'lines': [
  701. ['userstats_{0}_Select_commands'.format(name), 'select', 'incremental'],
  702. ['userstats_{0}_Update_commands'.format(name), 'update', 'incremental'],
  703. ['userstats_{0}_Other_commands'.format(name), 'other', 'incremental']
  704. ]
  705. }
  706. }
  707. return order, charts
  708. # https://dev.mysql.com/doc/refman/8.0/en/replication-channels.html
  709. DEFAULT_REPL_CHANNEL = ''
  710. # Write Set REPlication
  711. # https://galeracluster.com/library/documentation/galera-status-variables.html
  712. # https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html
  713. class WSRepDataConverter:
  714. unknown_value = -1
  715. def convert(self, key, value):
  716. if key == 'wsrep_connected':
  717. return self.convert_connected(value)
  718. elif key == 'wsrep_ready':
  719. return self.convert_ready(value)
  720. elif key == 'wsrep_cluster_status':
  721. return self.convert_cluster_status(value)
  722. return value
  723. def convert_connected(self, value):
  724. # https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_connected
  725. if value == 'OFF':
  726. return 0
  727. if value == 'ON':
  728. return 1
  729. return self.unknown_value
  730. def convert_ready(self, value):
  731. # https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_ready
  732. if value == 'OFF':
  733. return 0
  734. if value == 'ON':
  735. return 1
  736. return self.unknown_value
  737. def convert_cluster_status(self, value):
  738. # https://www.percona.com/doc/percona-xtradb-cluster/LATEST/wsrep-status-index.html#wsrep_cluster_status
  739. # https://github.com/codership/wsrep-API/blob/eab2d5d5a31672c0b7d116ef1629ff18392fd7d0/wsrep_api.h
  740. # typedef enum wsrep_view_status {
  741. # WSREP_VIEW_PRIMARY, //!< primary group configuration (quorum present)
  742. # WSREP_VIEW_NON_PRIMARY, //!< non-primary group configuration (quorum lost)
  743. # WSREP_VIEW_DISCONNECTED, //!< not connected to group, retrying.
  744. # WSREP_VIEW_MAX
  745. # } wsrep_view_status_t;
  746. value = value.lower()
  747. if value == 'primary':
  748. return 0
  749. elif value == 'non-primary':
  750. return 1
  751. elif value == 'disconnected':
  752. return 2
  753. return self.unknown_value
  754. wsrep_converter = WSRepDataConverter()
  755. class Service(MySQLService):
  756. def __init__(self, configuration=None, name=None):
  757. MySQLService.__init__(self, configuration=configuration, name=name)
  758. self.order = ORDER
  759. self.definitions = CHARTS
  760. self.queries = dict(
  761. global_status=QUERY_GLOBAL,
  762. slave_status=QUERY_SLAVE,
  763. variables=QUERY_VARIABLES,
  764. user_statistics=QUERY_USER_STATISTICS,
  765. )
  766. self.repl_channels = [DEFAULT_REPL_CHANNEL]
  767. def _get_data(self):
  768. raw_data = self._get_raw_data(description=True)
  769. if not raw_data:
  770. return None
  771. data = dict()
  772. if 'global_status' in raw_data:
  773. global_status = self.get_global_status(raw_data['global_status'])
  774. if global_status:
  775. data.update(global_status)
  776. if 'slave_status' in raw_data:
  777. status = self.get_slave_status(raw_data['slave_status'])
  778. if status:
  779. data.update(status)
  780. if 'user_statistics' in raw_data:
  781. if raw_data['user_statistics'][0]:
  782. data.update(self.get_userstats(raw_data))
  783. else:
  784. self.queries.pop('user_statistics')
  785. if 'variables' in raw_data:
  786. variables = dict(raw_data['variables'][0])
  787. for key in VARIABLES:
  788. if key in variables:
  789. data[key] = variables[key]
  790. return data or None
  791. @staticmethod
  792. def convert_wsrep(key, value):
  793. return wsrep_converter.convert(key, value)
  794. def get_global_status(self, raw_global_status):
  795. # (
  796. # (
  797. # ('Aborted_clients', '18'),
  798. # ('Aborted_connects', '33'),
  799. # ('Access_denied_errors', '80'),
  800. # ('Acl_column_grants', '0'),
  801. # ('Acl_database_grants', '0'),
  802. # ('Acl_function_grants', '0'),
  803. # ('wsrep_ready', 'OFF'),
  804. # ('wsrep_rollbacker_thread_count', '0'),
  805. # ('wsrep_thread_count', '0')
  806. # ),
  807. # (
  808. # ('Variable_name', 253, 60, 64, 64, 0, 0),
  809. # ('Value', 253, 48, 2048, 2048, 0, 0),
  810. # )
  811. # )
  812. rows = raw_global_status[0]
  813. if not rows:
  814. return
  815. global_status = dict(rows)
  816. data = dict()
  817. for key in GLOBAL_STATS:
  818. if key not in global_status:
  819. continue
  820. value = global_status[key]
  821. data[key] = value
  822. for key in GALERA_STATS:
  823. if key not in global_status:
  824. continue
  825. value = global_status[key]
  826. value = self.convert_wsrep(key, value)
  827. data[key] = value
  828. if 'Threads_created' in data and 'Connections' in data:
  829. data['Thread_cache_misses'] = round(int(data['Threads_created']) / float(data['Connections']) * 10000)
  830. return data
  831. def get_slave_status(self, slave_status_data):
  832. rows, description = slave_status_data[0], slave_status_data[1]
  833. description_keys = [v[0] for v in description]
  834. if not rows:
  835. return
  836. data = dict()
  837. for row in rows:
  838. slave_data = dict(zip(description_keys, row))
  839. channel_name = slave_data.get('Channel_Name', DEFAULT_REPL_CHANNEL)
  840. if channel_name not in self.repl_channels and len(self.charts) > 0:
  841. self.add_repl_channel_charts(channel_name)
  842. self.repl_channels.append(channel_name)
  843. for key, func in SLAVE_STATS:
  844. if key not in slave_data:
  845. continue
  846. value = slave_data[key]
  847. if channel_name:
  848. key = '{0}_{1}'.format(key, channel_name)
  849. data[key] = func(value)
  850. return data
  851. def add_repl_channel_charts(self, name):
  852. self.add_new_charts(slave_status_chart_template, name)
  853. def get_userstats(self, raw_data):
  854. # (
  855. # (
  856. # ('netdata', 1L, 0L, 60L, 0.15842499999999984, 0.15767439999999996, 5206L, 963957L, 0L, 0L,
  857. # 61L, 0L, 0L, 0L, 0L, 0L, 62L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
  858. # ),
  859. # (
  860. # ('User', 253, 7, 128, 128, 0, 0),
  861. # ('Total_connections', 3, 2, 11, 11, 0, 0),
  862. # ('Concurrent_connections', 3, 1, 11, 11, 0, 0),
  863. # ('Connected_time', 3, 2, 11, 11, 0, 0),
  864. # ('Busy_time', 5, 20, 21, 21, 31, 0),
  865. # ('Cpu_time', 5, 20, 21, 21, 31, 0),
  866. # ('Bytes_received', 8, 4, 21, 21, 0, 0),
  867. # ('Bytes_sent', 8, 6, 21, 21, 0, 0),
  868. # ('Binlog_bytes_written', 8, 1, 21, 21, 0, 0),
  869. # ('Rows_read', 8, 1, 21, 21, 0, 0),
  870. # ('Rows_sent', 8, 2, 21, 21, 0, 0),
  871. # ('Rows_deleted', 8, 1, 21, 21, 0, 0),
  872. # ('Rows_inserted', 8, 1, 21, 21, 0, 0),
  873. # ('Rows_updated', 8, 1, 21, 21, 0, 0),
  874. # ('Select_commands', 8, 2, 21, 21, 0, 0),
  875. # ('Update_commands', 8, 1, 21, 21, 0, 0),
  876. # ('Other_commands', 8, 2, 21, 21, 0, 0),
  877. # ('Commit_transactions', 8, 1, 21, 21, 0, 0),
  878. # ('Rollback_transactions', 8, 1, 21, 21, 0, 0),
  879. # ('Denied_connections', 8, 1, 21, 21, 0, 0),
  880. # ('Lost_connections', 8, 1, 21, 21, 0, 0),
  881. # ('Access_denied', 8, 1, 21, 21, 0, 0),
  882. # ('Empty_queries', 8, 2, 21, 21, 0, 0),
  883. # ('Total_ssl_connections', 8, 1, 21, 21, 0, 0),
  884. # ('Max_statement_time_exceeded', 8, 1, 21, 21, 0, 0)
  885. # )
  886. # )
  887. data = dict()
  888. userstats_vars = [e[0] for e in raw_data['user_statistics'][1]]
  889. for i, _ in enumerate(raw_data['user_statistics'][0]):
  890. user_name = raw_data['user_statistics'][0][i][0]
  891. userstats = dict(zip(userstats_vars, raw_data['user_statistics'][0][i]))
  892. if len(self.charts) > 0:
  893. if ('userstats_{0}_Cpu_time'.format(user_name)) not in self.charts['userstats_cpu']:
  894. self.add_userstats_dimensions(user_name)
  895. self.create_new_userstats_charts(user_name)
  896. for key in USER_STATISTICS:
  897. if key in userstats:
  898. data['userstats_{0}_{1}'.format(user_name, key)] = userstats[key]
  899. return data
  900. def add_userstats_dimensions(self, name):
  901. self.charts['userstats_cpu'].add_dimension(['userstats_{0}_Cpu_time'.format(name), name, 'incremental', 100, 1])
  902. def create_new_userstats_charts(self, tube):
  903. self.add_new_charts(userstats_chart_template, tube)
  904. def add_new_charts(self, template, *params):
  905. order, charts = template(*params)
  906. for chart_name in order:
  907. params = [chart_name] + charts[chart_name]['options']
  908. dimensions = charts[chart_name]['lines']
  909. new_chart = self.charts.add_chart(params)
  910. for dimension in dimensions:
  911. new_chart.add_dimension(dimension)