Skip to content

Commit 3385fd6

Browse files
Filip ChabikJan Kunzmann
authored andcommitted
1 parent 3cb14e6 commit 3385fd6

File tree

1 file changed

+30
-51
lines changed

1 file changed

+30
-51
lines changed

mysql.py

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@
99
# Configuration:
1010
# Import mysql
1111
# <Module mysql>
12-
# Host localhost
13-
# Port 3306 (optional)
14-
# User root
15-
# Password xxxx
16-
# HeartbeatTable percona.heartbeat (optional, if using pt-heartbeat)
12+
# Host localhost
13+
# Port 3306 (optional)
14+
# User root
15+
# Password xxxx
16+
# HeartbeatTable percona.heartbeat (optional, if using pt-heartbeat)
1717
# Verbose true (optional, to enable debugging)
1818
# </Module>
1919
#
2020
# Requires "MySQLdb" for Python
2121
#
2222
# Author: Chris Boulton <chris@chrisboulton.com>
23+
# Added metrics for Grafana Dashboards by Matej Zerovnik <matej@zunaj.si>
2324
# License: MIT (http://www.opensource.org/licenses/mit-license.php)
2425
#
2526

@@ -47,11 +48,14 @@
4748
'Created_tmp_disk_tables': 'counter',
4849
'Created_tmp_files': 'counter',
4950
'Created_tmp_tables': 'counter',
51+
'Innodb_buffer_pool_bytes_data': 'gauge',
52+
'Innodb_buffer_pool_bytes_dirty': 'gauge',
5053
'Innodb_buffer_pool_pages_data': 'gauge',
5154
'Innodb_buffer_pool_pages_dirty': 'gauge',
5255
'Innodb_buffer_pool_pages_free': 'gauge',
5356
'Innodb_buffer_pool_pages_total': 'gauge',
5457
'Innodb_buffer_pool_read_requests': 'counter',
58+
'Innodb_buffer_pool_write_requests': 'counter',
5559
'Innodb_buffer_pool_reads': 'counter',
5660
'Innodb_checkpoint_age': 'gauge',
5761
'Innodb_checkpoint_max_age': 'gauge',
@@ -74,6 +78,7 @@
7478
'Innodb_ibuf_size': 'gauge',
7579
'Innodb_lsn_current': 'counter',
7680
'Innodb_lsn_flushed': 'counter',
81+
'Innodb_log_writes': 'counter',
7782
'Innodb_max_trx_id': 'counter',
7883
'Innodb_mem_adaptive_hash': 'gauge',
7984
'Innodb_mem_dictionary': 'gauge',
@@ -82,9 +87,11 @@
8287
'Innodb_mutex_spin_rounds': 'counter',
8388
'Innodb_mutex_spin_waits': 'counter',
8489
'Innodb_os_log_pending_fsyncs': 'gauge',
90+
'Innodb_os_log_written': 'counter',
8591
'Innodb_pages_created': 'counter',
8692
'Innodb_pages_read': 'counter',
8793
'Innodb_pages_written': 'counter',
94+
'Innodb_page_size': 'gauge',
8895
'Innodb_row_lock_time': 'counter',
8996
'Innodb_row_lock_time_avg': 'gauge',
9097
'Innodb_row_lock_time_max': 'gauge',
@@ -124,6 +131,7 @@
124131
'Qcache_not_cached': 'counter',
125132
'Qcache_queries_in_cache': 'counter',
126133
'Qcache_total_blocks': 'counter',
134+
'Queries': 'counter',
127135
'Questions': 'counter',
128136
'Select_full_join': 'counter',
129137
'Select_full_range_join': 'counter',
@@ -150,41 +158,6 @@
150158
'Threads_created': 'counter',
151159
'Threads_running': 'gauge',
152160
'Uptime': 'gauge',
153-
'wsrep_apply_oooe': 'gauge',
154-
'wsrep_apply_oool': 'gauge',
155-
'wsrep_apply_window': 'gauge',
156-
'wsrep_causal_reads': 'gauge',
157-
'wsrep_cert_deps_distance': 'gauge',
158-
'wsrep_cert_index_size': 'gauge',
159-
'wsrep_cert_interval': 'gauge',
160-
'wsrep_cluster_size': 'gauge',
161-
'wsrep_commit_oooe': 'gauge',
162-
'wsrep_commit_oool': 'gauge',
163-
'wsrep_commit_window': 'gauge',
164-
'wsrep_flow_control_paused': 'gauge',
165-
'wsrep_flow_control_paused_ns': 'counter',
166-
'wsrep_flow_control_recv': 'counter',
167-
'wsrep_flow_control_sent': 'counter',
168-
'wsrep_local_bf_aborts': 'counter',
169-
'wsrep_local_cert_failures': 'counter',
170-
'wsrep_local_commits': 'counter',
171-
'wsrep_local_recv_queue': 'gauge',
172-
'wsrep_local_recv_queue_avg': 'gauge',
173-
'wsrep_local_recv_queue_max': 'gauge',
174-
'wsrep_local_recv_queue_min': 'gauge',
175-
'wsrep_local_replays': 'gauge',
176-
'wsrep_local_send_queue': 'gauge',
177-
'wsrep_local_send_queue_avg': 'gauge',
178-
'wsrep_local_send_queue_max': 'gauge',
179-
'wsrep_local_send_queue_min': 'gauge',
180-
'wsrep_received': 'counter',
181-
'wsrep_received_bytes': 'counter',
182-
'wsrep_repl_data_bytes': 'counter',
183-
'wsrep_repl_keys': 'counter',
184-
'wsrep_repl_keys_bytes': 'counter',
185-
'wsrep_repl_other_bytes': 'counter',
186-
'wsrep_replicated': 'counter',
187-
'wsrep_replicated_bytes': 'counter',
188161
}
189162

190163
MYSQL_VARS = [
@@ -195,15 +168,20 @@
195168
'innodb_io_capacity',
196169
'innodb_log_buffer_size',
197170
'innodb_log_file_size',
171+
'innodb_log_files_in_group',
172+
'innodb_max_purge_lag',
198173
'innodb_open_files',
199174
'innodb_open_files',
200175
'join_buffer_size',
176+
'key_buffer_size',
177+
'key_cache_block_size',
201178
'max_connections',
202179
'open_files_limit',
203180
'query_cache_limit',
204181
'query_cache_size',
205182
'query_cache_size',
206183
'read_buffer_size',
184+
'read_only',
207185
'table_cache',
208186
'table_definition_cache',
209187
'table_open_cache',
@@ -293,11 +271,11 @@
293271
'Page hash ': {
294272
'page_hash_memory': 2,
295273
},
296-
# File system 657820264 (812272 + 657007992)
274+
# File system 657820264 (812272 + 657007992)
297275
'File system ': {
298276
'file_system_memory': 2,
299277
},
300-
# Lock system 143820296 (143819576 + 720)
278+
# Lock system 143820296 (143819576 + 720)
301279
'Lock system ': {
302280
'lock_system_memory': 2,
303281
},
@@ -309,7 +287,7 @@
309287
# --Thread 139954487744256 has waited at dict0dict.cc line 472 for 0.0000 seconds the semaphore:
310288
'seconds the semaphore': {
311289
'innodb_sem_waits': lambda row, stats: stats['innodb_sem_waits'] + 1,
312-
'innodb_sem_wait_time_ms': lambda row, stats: int(float(row[9]) * 1000),
290+
'innodb_sem_wait_time_ms': lambda row, stats: float(row[9]) * 1000,
313291
},
314292
# mysql tables in use 1, locked 1
315293
'mysql tables in use': {
@@ -376,6 +354,7 @@ def fetch_mysql_slave_stats(conn):
376354

377355
status = {
378356
'relay_log_space': slave_row['Relay_Log_Space'],
357+
'last_errno': slave_row['Last_Errno'],
379358
'slave_lag': slave_row['Seconds_Behind_Master'] if slave_row['Seconds_Behind_Master'] != None else 0,
380359
}
381360

@@ -390,8 +369,8 @@ def fetch_mysql_slave_stats(conn):
390369
if 'delay' in row and row['delay'] != None:
391370
status['slave_lag'] = row['delay']
392371

393-
status['slave_running'] = 1 if slave_row['Slave_SQL_Running'] == 'Yes' else 0
394-
status['slave_stopped'] = 1 if slave_row['Slave_SQL_Running'] != 'Yes' else 0
372+
status['slave_sql_running'] = 1 if slave_row['Slave_SQL_Running'] == 'Yes' else 0
373+
status['slave_io_running'] = 1 if slave_row['Slave_IO_Running'] == 'Yes' else 0
395374
return status
396375

397376
def fetch_mysql_process_states(conn):
@@ -414,7 +393,10 @@ def fetch_mysql_variables(conn):
414393
variables = {}
415394
for row in result.fetchall():
416395
if row['Variable_name'] in MYSQL_VARS:
417-
variables[row['Variable_name']] = row['Value']
396+
if row['Variable_name'] == 'read_only':
397+
variables[row['Variable_name']] = 1 if row['Value'] == 'ON' else 0
398+
else:
399+
variables[row['Variable_name']] = row['Value']
418400

419401
return variables
420402

@@ -494,12 +476,9 @@ def dispatch_value(prefix, key, value, type, type_instance=None):
494476
type_instance = key
495477

496478
log_verbose('Sending value: %s/%s=%s' % (prefix, type_instance, value))
497-
if not value:
479+
if value is None:
498480
return
499-
try:
500-
value = int(value)
501-
except ValueError:
502-
value = float(value)
481+
value = int(value) # safety check
503482

504483
val = collectd.Values(plugin='mysql', plugin_instance=prefix)
505484
val.type = type

0 commit comments

Comments
 (0)