1 # -*- coding: utf-8 -*-
2 # Description: MySQL netdata python.d module
3 # Author: Pawel Krupa (paulfantom)
5 from base import MySQLService
7 # default module values (can be overridden per job in `config`)
12 # query executed on MySQL server
13 QUERY_GLOBAL = 'SHOW GLOBAL STATUS;'
14 QUERY_SLAVE = 'SHOW SLAVE STATUS;'
30 'Handler_read_rnd_next',
33 'Handler_savepoint_rollback',
36 'Table_locks_immediate',
39 'Select_full_range_join',
46 'Created_tmp_disk_tables',
51 'Binlog_cache_disk_use',
57 'Thread_cache_misses',
59 'Innodb_data_written',
63 'Innodb_data_pending_reads',
64 'Innodb_data_pending_writes',
65 'Innodb_data_pending_fsyncs',
67 'Innodb_log_write_requests',
69 'Innodb_os_log_fsyncs',
70 'Innodb_os_log_pending_fsyncs',
71 'Innodb_os_log_pending_writes',
72 'Innodb_os_log_written',
73 'Innodb_row_lock_current_waits',
74 'Innodb_rows_inserted',
76 'Innodb_rows_updated',
77 'Innodb_rows_deleted',
78 'Innodb_buffer_pool_pages_data',
79 'Innodb_buffer_pool_pages_dirty',
80 'Innodb_buffer_pool_pages_free',
81 'Innodb_buffer_pool_pages_flushed',
82 'Innodb_buffer_pool_pages_misc',
83 'Innodb_buffer_pool_pages_total',
84 'Innodb_buffer_pool_bytes_data',
85 'Innodb_buffer_pool_bytes_dirty',
86 'Innodb_buffer_pool_read_ahead',
87 'Innodb_buffer_pool_read_ahead_evicted',
88 'Innodb_buffer_pool_read_ahead_rnd',
89 'Innodb_buffer_pool_read_requests',
90 'Innodb_buffer_pool_write_requests',
91 'Innodb_buffer_pool_reads',
92 'Innodb_buffer_pool_wait_free',
94 'Qcache_lowmem_prunes',
97 'Qcache_queries_in_cache',
100 'Qcache_total_blocks',
103 'Key_blocks_not_flushed',
105 'Key_write_requests',
110 'Binlog_stmt_cache_disk_use',
111 'Binlog_stmt_cache_use',
112 'Connection_errors_accept',
113 'Connection_errors_internal',
114 'Connection_errors_max_connections',
115 'Connection_errors_peer_address',
116 'Connection_errors_select',
117 'Connection_errors_tcpwrap']
119 def slave_seconds(value):
120 return value if value else -1
122 def slave_running(value):
123 return 1 if value == 'Yes' else -1
127 ('Seconds_Behind_Master', slave_seconds),
128 ('Slave_SQL_Running', slave_running),
129 ('Slave_IO_Running', slave_running)
136 'join_issues', 'sort_issues',
138 'connections', 'connection_errors',
139 'binlog_cache', 'binlog_stmt_cache',
140 'threads', 'thread_cache_misses',
141 'innodb_io', 'innodb_io_ops', 'innodb_io_pending_ops', 'innodb_log', 'innodb_os_log', 'innodb_os_log_io',
142 'innodb_cur_row_lock', 'innodb_rows', 'innodb_buffer_pool_pages', 'innodb_buffer_pool_bytes',
143 'innodb_buffer_pool_read_ahead', 'innodb_buffer_pool_reqs', 'innodb_buffer_pool_ops',
144 'qcache_ops', 'qcache', 'qcache_freemem', 'qcache_memblocks',
145 'key_blocks', 'key_requests', 'key_disk_ops',
146 'files', 'files_rate', 'slave_behind', 'slave_status']
150 'options': [None, 'mysql Bandwidth', 'kilobits/s', 'bandwidth', 'mysql.net', 'area'],
152 ['Bytes_received', 'in', 'incremental', 8, 1024],
153 ['Bytes_sent', 'out', 'incremental', -8, 1024]
156 'options': [None, 'mysql Queries', 'queries/s', 'queries', 'mysql.queries', 'line'],
158 ['Queries', 'queries', 'incremental'],
159 ['Questions', 'questions', 'incremental'],
160 ['Slow_queries', 'slow_queries', 'incremental']
163 'options': [None, 'mysql Handlers', 'handlers/s', 'handlers', 'mysql.handlers', 'line'],
165 ['Handler_commit', 'commit', 'incremental'],
166 ['Handler_delete', 'delete', 'incremental'],
167 ['Handler_prepare', 'prepare', 'incremental'],
168 ['Handler_read_first', 'read_first', 'incremental'],
169 ['Handler_read_key', 'read_key', 'incremental'],
170 ['Handler_read_next', 'read_next', 'incremental'],
171 ['Handler_read_prev', 'read_prev', 'incremental'],
172 ['Handler_read_rnd', 'read_rnd', 'incremental'],
173 ['Handler_read_rnd_next', 'read_rnd_next', 'incremental'],
174 ['Handler_rollback', 'rollback', 'incremental'],
175 ['Handler_savepoint', 'savepoint', 'incremental'],
176 ['Handler_savepoint_rollback', 'savepoint_rollback', 'incremental'],
177 ['Handler_update', 'update', 'incremental'],
178 ['Handler_write', 'write', 'incremental']
181 'options': [None, 'mysql Tables Locks', 'locks/s', 'locks', 'mysql.table_locks', 'line'],
183 ['Table_locks_immediate', 'immediate', 'incremental'],
184 ['Table_locks_waited', 'waited', 'incremental', -1, 1]
187 'options': [None, 'mysql Select Join Issues', 'joins/s', 'issues', 'mysql.join_issues', 'line'],
189 ['Select_full_join', 'full_join', 'incremental'],
190 ['Select_full_range_join', 'full_range_join', 'incremental'],
191 ['Select_range', 'range', 'incremental'],
192 ['Select_range_check', 'range_check', 'incremental'],
193 ['Select_scan', 'scan', 'incremental']
196 'options': [None, 'mysql Sort Issues', 'issues/s', 'issues', 'mysql.sort_issues', 'line'],
198 ['Sort_merge_passes', 'merge_passes', 'incremental'],
199 ['Sort_range', 'range', 'incremental'],
200 ['Sort_scan', 'scan', 'incremental']
203 'options': [None, 'mysql Tmp Operations', 'counter', 'temporaries', 'mysql.tmp', 'line'],
205 ['Created_tmp_disk_tables', 'disk_tables', 'incremental'],
206 ['Created_tmp_files', 'files', 'incremental'],
207 ['Created_tmp_tables', 'tables', 'incremental']
210 'options': [None, 'mysql Connections', 'connections/s', 'connections', 'mysql.connections', 'line'],
212 ['Connections', 'all', 'incremental'],
213 ['Aborted_connects', 'aborted', 'incremental']
216 'options': [None, 'mysql Binlog Cache', 'transactions/s', 'binlog', 'mysql.binlog_cache', 'line'],
218 ['Binlog_cache_disk_use', 'disk', 'incremental'],
219 ['Binlog_cache_use', 'all', 'incremental']
222 'options': [None, 'mysql Threads', 'threads', 'threads', 'mysql.threads', 'line'],
224 ['Threads_connected', 'connected', 'absolute'],
225 ['Threads_created', 'created', 'incremental'],
226 ['Threads_cached', 'cached', 'absolute', -1, 1],
227 ['Threads_running', 'running', 'absolute'],
229 'thread_cache_misses': {
230 'options': [None, 'mysql Threads Cache Misses', 'misses', 'threads', 'mysql.thread_cache_misses', 'area'],
232 ['Thread_cache_misses', 'misses', 'absolute', 1, 100]
235 'options': [None, 'mysql InnoDB I/O Bandwidth', 'kilobytes/s', 'innodb', 'mysql.innodb_io', 'area'],
237 ['Innodb_data_read', 'read', 'incremental', 1, 1024],
238 ['Innodb_data_written', 'write', 'incremental', -1, 1024]
241 'options': [None, 'mysql InnoDB I/O Operations', 'operations/s', 'innodb', 'mysql.innodb_io_ops', 'line'],
243 ['Innodb_data_reads', 'reads', 'incremental'],
244 ['Innodb_data_writes', 'writes', 'incremental', -1, 1],
245 ['Innodb_data_fsyncs', 'fsyncs', 'incremental']
247 'innodb_io_pending_ops': {
248 'options': [None, 'mysql InnoDB Pending I/O Operations', 'operations', 'innodb', 'mysql.innodb_io_pending_ops', 'line'],
250 ['Innodb_data_pending_reads', 'reads', 'absolute'],
251 ['Innodb_data_pending_writes', 'writes', 'absolute', -1, 1],
252 ['Innodb_data_pending_fsyncs', 'fsyncs', 'absolute']
255 'options': [None, 'mysql InnoDB Log Operations', 'operations/s', 'innodb', 'mysql.innodb_log', 'line'],
257 ['Innodb_log_waits', 'waits', 'incremental'],
258 ['Innodb_log_write_requests', 'write_requests', 'incremental', -1, 1],
259 ['Innodb_log_writes', 'writes', 'incremental', -1, 1],
262 'options': [None, 'mysql InnoDB OS Log Operations', 'operations', 'innodb', 'mysql.innodb_os_log', 'line'],
264 ['Innodb_os_log_fsyncs', 'fsyncs', 'incremental'],
265 ['Innodb_os_log_pending_fsyncs', 'pending_fsyncs', 'absolute'],
266 ['Innodb_os_log_pending_writes', 'pending_writes', 'absolute', -1, 1],
268 'innodb_os_log_io': {
269 'options': [None, 'mysql InnoDB OS Log Bandwidth', 'kilobytes/s', 'innodb', 'mysql.innodb_os_log_io', 'area'],
271 ['Innodb_os_log_written', 'write', 'incremental', -1, 1024],
273 'innodb_cur_row_lock': {
274 'options': [None, 'mysql InnoDB Current Row Locks', 'operations', 'innodb', 'mysql.innodb_cur_row_lock', 'area'],
276 ['Innodb_row_lock_current_waits', 'current_waits', 'absolute']
279 'options': [None, 'mysql InnoDB Row Operations', 'operations/s', 'innodb', 'mysql.innodb_rows', 'area'],
281 ['Innodb_rows_inserted', 'read', 'incremental'],
282 ['Innodb_rows_read', 'deleted', 'incremental', -1, 1],
283 ['Innodb_rows_updated', 'inserted', 'incremental', 1, 1],
284 ['Innodb_rows_deleted', 'updated', 'incremental', -1, 1],
286 'innodb_buffer_pool_pages': {
287 'options': [None, 'mysql InnoDB Buffer Pool Pages', 'pages', 'innodb', 'mysql.innodb_buffer_pool_pages', 'line'],
289 ['Innodb_buffer_pool_pages_data', 'data', 'absolute'],
290 ['Innodb_buffer_pool_pages_dirty', 'dirty', 'absolute', -1, 1],
291 ['Innodb_buffer_pool_pages_free', 'free', 'absolute'],
292 ['Innodb_buffer_pool_pages_flushed', 'flushed', 'incremental', -1, 1],
293 ['Innodb_buffer_pool_pages_misc', 'misc', 'absolute', -1, 1],
294 ['Innodb_buffer_pool_pages_total', 'total', 'absolute']
296 'innodb_buffer_pool_bytes': {
297 'options': [None, 'mysql InnoDB Buffer Pool Bytes', 'MB', 'innodb', 'mysql.innodb_buffer_pool_bytes', 'area'],
299 ['Innodb_buffer_pool_bytes_data', 'data', 'absolute', 1, 1024 * 1024],
300 ['Innodb_buffer_pool_bytes_dirty', 'dirty', 'absolute', -1, 1024 * 1024]
302 'innodb_buffer_pool_read_ahead': {
303 'options': [None, 'mysql InnoDB Buffer Pool Read Ahead', 'operations/s', 'innodb', 'mysql.innodb_buffer_pool_read_ahead', 'area'],
305 ['Innodb_buffer_pool_read_ahead', 'all', 'incremental'],
306 ['Innodb_buffer_pool_read_ahead_evicted', 'evicted', 'incremental', -1, 1],
307 ['Innodb_buffer_pool_read_ahead_rnd', 'random', 'incremental']
309 'innodb_buffer_pool_reqs': {
310 'options': [None, 'mysql InnoDB Buffer Pool Requests', 'requests/s', 'innodb', 'mysql.innodb_buffer_pool_reqs', 'area'],
312 ['Innodb_buffer_pool_read_requests', 'reads', 'incremental'],
313 ['Innodb_buffer_pool_write_requests', 'writes', 'incremental', -1, 1]
315 'innodb_buffer_pool_ops': {
316 'options': [None, 'mysql InnoDB Buffer Pool Operations', 'operations/s', 'innodb', 'mysql.innodb_buffer_pool_ops', 'area'],
318 ['Innodb_buffer_pool_reads', 'disk reads', 'incremental'],
319 ['Innodb_buffer_pool_wait_free', 'wait free', 'incremental', -1, 1]
322 'options': [None, 'mysql QCache Operations', 'queries/s', 'qcache', 'mysql.qcache_ops', 'line'],
324 ['Qcache_hits', 'hits', 'incremental'],
325 ['Qcache_lowmem_prunes', 'lowmem prunes', 'incremental', -1, 1],
326 ['Qcache_inserts', 'inserts', 'incremental'],
327 ['Qcache_not_cached', 'not cached', 'incremental', -1, 1]
330 'options': [None, 'mysql QCache Queries in Cache', 'queries', 'qcache', 'mysql.qcache', 'line'],
332 ['Qcache_queries_in_cache', 'queries', 'absolute']
335 'options': [None, 'mysql QCache Free Memory', 'MB', 'qcache', 'mysql.qcache_freemem', 'area'],
337 ['Qcache_free_memory', 'free', 'absolute', 1, 1024 * 1024]
339 'qcache_memblocks': {
340 'options': [None, 'mysql QCache Memory Blocks', 'blocks', 'qcache', 'mysql.qcache_memblocks', 'line'],
342 ['Qcache_free_blocks', 'free', 'absolute'],
343 ['Qcache_total_blocks', 'total', 'absolute']
346 'options': [None, 'mysql MyISAM Key Cache Blocks', 'blocks', 'myisam', 'mysql.key_blocks', 'line'],
348 ['Key_blocks_unused', 'unused', 'absolute'],
349 ['Key_blocks_used', 'used', 'absolute', -1, 1],
350 ['Key_blocks_not_flushed', 'not flushed', 'absolute']
353 'options': [None, 'mysql MyISAM Key Cache Requests', 'requests/s', 'myisam', 'mysql.key_requests', 'area'],
355 ['Key_read_requests', 'reads', 'incremental'],
356 ['Key_write_requests', 'writes', 'incremental', -1, 1]
359 'options': [None, 'mysql MyISAM Key Cache Disk Operations', 'operations/s', 'myisam', 'mysql.key_disk_ops', 'area'],
361 ['Key_reads', 'reads', 'incremental'],
362 ['Key_writes', 'writes', 'incremental', -1, 1]
365 'options': [None, 'mysql Open Files', 'files', 'files', 'mysql.files', 'line'],
367 ['Open_files', 'files', 'absolute']
370 'options': [None, 'mysql Opened Files Rate', 'files/s', 'files', 'mysql.files_rate', 'line'],
372 ['Opened_files', 'files', 'incremental']
374 'binlog_stmt_cache': {
375 'options': [None, 'mysql Binlog Statement Cache', 'statements/s', 'binlog', 'mysql.binlog_stmt_cache', 'line'],
377 ['Binlog_stmt_cache_disk_use', 'disk', 'incremental'],
378 ['Binlog_stmt_cache_use', 'all', 'incremental']
380 'connection_errors': {
381 'options': [None, 'mysql Connection Errors', 'connections/s', 'connections', 'mysql.connection_errors', 'line'],
383 ['Connection_errors_accept', 'accept', 'incremental'],
384 ['Connection_errors_internal', 'internal', 'incremental'],
385 ['Connection_errors_max_connections', 'max', 'incremental'],
386 ['Connection_errors_peer_address', 'peer_addr', 'incremental'],
387 ['Connection_errors_select', 'select', 'incremental'],
388 ['Connection_errors_tcpwrap', 'tcpwrap', 'incremental']
391 'options': [None, 'Slave Behind Seconds', 'seconds', 'slave', 'mysql.slave_behind', 'line'],
393 ['Seconds_Behind_Master', 'seconds', 'absolute']
396 'options': [None, 'Slave Status', 'status', 'slave', 'mysql.slave_status', 'line'],
398 ['Slave_SQL_Running', 'sql_running', 'absolute'],
399 ['Slave_IO_Running', 'io_running', 'absolute']
404 class Service(MySQLService):
405 def __init__(self, configuration=None, name=None):
406 MySQLService.__init__(self, configuration=configuration, name=name)
408 self.definitions = CHARTS
409 self.queries = dict(global_status=QUERY_GLOBAL, slave_status=QUERY_SLAVE)
413 raw_data = self._get_raw_data(description=True)
420 if 'global_status' in raw_data:
421 global_status = dict(raw_data['global_status'][0])
422 for key in GLOBAL_STATS:
423 if key in global_status:
424 to_netdata[key] = global_status[key]
425 if 'Threads_created' in to_netdata and 'Connections' in to_netdata:
426 to_netdata['Thread_cache_misses'] = round(int(to_netdata['Threads_created']) / float(to_netdata['Connections']) * 10000)
428 if 'slave_status' in raw_data:
429 if raw_data['slave_status'][0]:
430 slave_raw_data = dict(zip([e[0] for e in raw_data['slave_status'][1]], raw_data['slave_status'][0][0]))
431 for key, function in SLAVE_STATS:
432 if key in slave_raw_data:
433 to_netdata[key] = function(slave_raw_data[key])
435 self.queries.pop('slave_status')
437 return to_netdata or None