use SimpleService in mysql service
paulfantom committed
Jul 2, 2016 at 19:25 UTC
d1786059c9947bdbe522b18dc3a53c64baac7ee8
1 file changed
+337
-364
python.d/mysql.chart.py
+337
-364
@@ -3,8 +3,8 @@
3
# Author: Pawel Krupa (paulfantom)
4
5
import os
6
-import sys
7
-from base import BaseService
6
+from base import SimpleService
7
+import msg
8
9
NAME = os.path.basename(__file__).replace(".chart.py", "")
10
@@ -13,15 +13,15 @@ try:
13
import MySQLdb
14
15
# https://github.com/PyMySQL/mysqlclient-python
16
- sys.stderr.write(NAME + ": using MySQLdb\n")
16
+ msg.info("using MySQLdb")
17
except ImportError:
18
try:
19
import pymysql as MySQLdb
20
21
# https://github.com/PyMySQL/PyMySQL
22
- sys.stderr.write(NAME + ": using pymysql\n")
22
+ msg.info("using pymysql")
23
except ImportError:
24
- sys.stderr.write(NAME + ": You need to install MySQLdb or PyMySQL module to use mysql.chart.py plugin\n")
24
+ msg.error("MySQLdb or PyMySQL module is needed to use mysql.chart.py plugin")
25
raise ImportError
26
27
# default module values (can be overridden per job in `config`)
@@ -44,303 +44,275 @@ config = {
44
# query executed on MySQL server
45
QUERY = "SHOW GLOBAL STATUS"
46
47
-# charts order (can be overridden if you want less charts, or different order)
47
ORDER = ['net',
48
'queries',
49
'handlers',
50
'table_locks',
52
- 'join_issues',
53
- 'sort_issues',
51
+ 'join_issues', 'sort_issues',
52
'tmp',
55
- 'connections',
56
- 'binlog_cache',
57
- 'threads',
58
- 'thread_cache_misses',
59
- 'innodb_io',
60
- 'innodb_io_ops',
61
- 'innodb_io_pending_ops',
62
- 'innodb_log',
63
- 'innodb_os_log',
64
- 'innodb_os_log_io',
65
- 'innodb_cur_row_lock',
66
- 'innodb_rows',
67
- 'innodb_buffer_pool_pages',
68
- 'innodb_buffer_pool_bytes',
69
- 'innodb_buffer_pool_read_ahead',
70
- 'innodb_buffer_pool_reqs',
71
- 'innodb_buffer_pool_ops',
72
- 'qcache_ops',
73
- 'qcache',
74
- 'qcache_freemem',
75
- 'qcache_memblocks',
76
- 'key_blocks',
77
- 'key_requests',
78
- 'key_disk_ops',
79
- 'files',
80
- 'files_rate',
81
- 'binlog_stmt_cache',
82
- 'connection_errors']
83
-
84
-# charts definitions in format:
85
-# CHARTS = {
86
-# 'chart_name_in_netdata': (
87
-# "parameters defining chart (passed to CHART statement)",
88
-# [ # dimensions (lines) definitions
89
-# ("dimension_name", "dimension parameters (passed to DIMENSION statement)")
90
-# ])
91
-# }
53
+ 'connections', 'connection_errors',
54
+ 'binlog_cache', 'binlog_stmt_cache',
55
+ 'threads', 'thread_cache_misses',
56
+ 'innodb_io', 'innodb_io_ops', 'innodb_io_pending_ops', 'innodb_log', 'innodb_os_log', 'innodb_os_log_io',
57
+ 'innodb_cur_row_lock', 'innodb_rows', 'innodb_buffer_pool_pages', 'innodb_buffer_pool_bytes',
58
+ 'innodb_buffer_pool_read_ahead', 'innodb_buffer_pool_reqs', 'innodb_buffer_pool_ops',
59
+ 'qcache_ops', 'qcache', 'qcache_freemem', 'qcache_memblocks',
60
+ 'key_blocks', 'key_requests', 'key_disk_ops',
61
+ 'files', 'files_rate']
62
63
CHARTS = {
94
- 'net': (
95
- "'' 'mysql Bandwidth' 'kilobits/s' bandwidth mysql.net area",
96
- [
97
- ("Bytes_received", "in incremental 8 1024"),
98
- ("Bytes_sent", "out incremental -8 1024")
99
- ]),
100
- 'queries': (
101
- "'' 'mysql Queries' 'queries/s' queries mysql.queries line",
102
- [
103
- ("Queries", "queries incremental 1 1"),
104
- ("Questions", "questions incremental 1 1"),
105
- ("Slow_queries", "slow_queries incremental -1 1")
106
- ]),
107
- 'handlers': (
108
- "'' 'mysql Handlers' 'handlers/s' handlers mysql.handlers line",
109
- [
110
- ("Handler_commit", "commit incremental 1 1"),
111
- ("Handler_delete", "delete incremental 1 1"),
112
- ("Handler_prepare", "prepare incremental 1 1"),
113
- ("Handler_read_first", "read_first incremental 1 1"),
114
- ("Handler_read_key", "read_key incremental 1 1"),
115
- ("Handler_read_next", "read_next incremental 1 1"),
116
- ("Handler_read_prev", "read_prev incremental 1 1"),
117
- ("Handler_read_rnd", "read_rnd incremental 1 1"),
118
- ("Handler_read_rnd_next", "read_rnd_next incremental 1 1"),
119
- ("Handler_rollback", "rollback incremental 1 1"),
120
- ("Handler_savepoint", "savepoint incremental 1 1"),
121
- ("Handler_savepoint_rollback", "savepoint_rollback incremental 1 1"),
122
- ("Handler_update", "update incremental 1 1"),
123
- ("Handler_write", "write incremental 1 1")
124
- ]),
125
- 'table_locks': (
126
- "'' 'mysql Tables Locks' 'locks/s' locks mysql.table_locks line",
127
- [
128
- ("Table_locks_immediate", "immediate incremental 1 1"),
129
- ("Table_locks_waited", "waited incremental -1 1")
130
- ]),
131
- 'join_issues': (
132
- "'' 'mysql Select Join Issues' 'joins/s' issues mysql.join_issues line",
133
- [
134
- ("Select_full_join", "full_join incremental 1 1"),
135
- ("Select_full_range_join", "full_range_join incremental 1 1"),
136
- ("Select_range", "range incremental 1 1"),
137
- ("Select_range_check", "range_check incremental 1 1"),
138
- ("Select_scan", "scan incremental 1 1"),
139
- ]),
140
- 'sort_issues': (
141
- "'' 'mysql Sort Issues' 'issues/s' issues mysql.sort.issues line",
142
- [
143
- ("Sort_merge_passes", "merge_passes incremental 1 1"),
144
- ("Sort_range", "range incremental 1 1"),
145
- ("Sort_scan", "scan incremental 1 1"),
146
- ]),
147
- 'tmp': (
148
- "'' 'mysql Tmp Operations' 'counter' temporaries mysql.tmp line",
149
- [
150
- ("Created_tmp_disk_tables", "disk_tables incremental 1 1"),
151
- ("Created_tmp_files", "files incremental 1 1"),
152
- ("Created_tmp_tables", "tables incremental 1 1"),
153
- ]),
154
- 'connections': (
155
- "'' 'mysql Connections' 'connections/s' connections mysql.connections line",
156
- [
157
- ("Connections", "all incremental 1 1"),
158
- ("Aborted_connects", "aborted incremental 1 1"),
159
- ]),
160
- 'binlog_cache': (
161
- "'' 'mysql Binlog Cache' 'transactions/s' binlog mysql.binlog_cache line",
162
- [
163
- ("Binlog_cache_disk_use", "disk incremental 1 1"),
164
- ("Binlog_cache_use", "all incremental 1 1"),
165
- ]),
166
- 'threads': (
167
- "'' 'mysql Threads' 'threads' threads mysql.threads line",
168
- [
169
- ("Threads_connected", "connected absolute 1 1"),
170
- ("Threads_created", "created incremental 1 1"),
171
- ("Threads_cached", "cached absolute -1 1"),
172
- ("Threads_running", "running absolute 1 1"),
173
- ]),
174
- 'thread_cache_misses': (
175
- "'' 'mysql Threads Cache Misses' 'misses' threads mysql.thread_cache_misses area",
176
- [
177
- ("Thread_cache_misses", "misses misses absolute 1 100"),
178
- ]),
179
- 'innodb_io': (
180
- "'' 'mysql InnoDB I/O Bandwidth' 'kilobytes/s' innodb mysql.innodb_io area",
181
- [
182
- ("Innodb_data_read", "read incremental 1 1024"),
183
- ("Innodb_data_written", "write incremental -1 1024"),
184
- ]),
185
- 'innodb_io_ops': (
186
- "'' 'mysql InnoDB I/O Operations' 'operations/s' innodb mysql.innodb_io_ops line",
187
- [
188
- ("Innodb_data_reads", "reads incremental 1 1"),
189
- ("Innodb_data_writes", "writes incremental -1 1"),
190
- ("Innodb_data_fsyncs", "fsyncs incremental 1 1"),
191
- ]),
192
- 'innodb_io_pending_ops': (
193
- "'' 'mysql InnoDB Pending I/O Operations' 'operations' innodb mysql.innodb_io_pending_ops line",
194
- [
195
- ("Innodb_data_pending_reads", "reads absolute 1 1"),
196
- ("Innodb_data_pending_writes", "writes absolute -1 1"),
197
- ("Innodb_data_pending_fsyncs", "fsyncs absolute 1 1"),
198
- ]),
199
- 'innodb_log': (
200
- "'' 'mysql InnoDB Log Operations' 'operations/s' innodb mysql.innodb_log line",
201
- [
202
- ("Innodb_log_waits", "waits incremental 1 1"),
203
- ("Innodb_log_write_requests", "write_requests incremental -1 1"),
204
- ("Innodb_log_writes", "incremental -1 1"),
205
- ]),
206
- 'innodb_os_log': (
207
- "'' 'mysql InnoDB OS Log Operations' 'operations' innodb mysql.innodb_os_log line",
208
- [
209
- ("Innodb_os_log_fsyncs", "fsyncs incremental 1 1"),
210
- ("Innodb_os_log_pending_fsyncs", "pending_fsyncs absolute 1 1"),
211
- ("Innodb_os_log_pending_writes", "pending_writes absolute -1 1"),
212
- ]),
213
- 'innodb_os_log_io': (
214
- "'' 'mysql InnoDB OS Log Bandwidth' 'kilobytes/s' innodb mysql.innodb_os_log_io area",
215
- [
216
- ("Innodb_os_log_written", "write incremental -1 1024"),
217
- ]),
218
- 'innodb_cur_row_lock': (
219
- "'' 'mysql InnoDB Current Row Locks' 'operations' innodb mysql.innodb_cur_row_lock area",
220
- [
221
- ("Innodb_row_lock_current_waits", "current_waits absolute 1 1"),
222
- ]),
223
- 'innodb_rows': (
224
- "'' 'mysql InnoDB Row Operations' 'operations/s' innodb mysql.innodb_rows area",
225
- [
226
- ("Innodb_rows_inserted", "read incremental 1 1"),
227
- ("Innodb_rows_read", "deleted incremental -1 1"),
228
- ("Innodb_rows_updated", "inserted incremental 1 1"),
229
- ("Innodb_rows_deleted", "updated incremental -1 1"),
230
- ]),
231
- 'innodb_buffer_pool_pages': (
232
- "'' 'mysql InnoDB Buffer Pool Pages' 'pages' innodb mysql.innodb_buffer_pool_pages line",
233
- [
234
- ("Innodb_buffer_pool_pages_data", "data absolute 1 1"),
235
- ("Innodb_buffer_pool_pages_dirty", "dirty absolute -1 1"),
236
- ("Innodb_buffer_pool_pages_free", "free absolute 1 1"),
237
- ("Innodb_buffer_pool_pages_flushed", "flushed incremental -1 1"),
238
- ("Innodb_buffer_pool_pages_misc", "misc absolute -1 1"),
239
- ("Innodb_buffer_pool_pages_total", "total absolute 1 1"),
240
- ]),
241
- 'innodb_buffer_pool_bytes': (
242
- "'' 'mysql InnoDB Buffer Pool Bytes' 'MB' innodb mysql.innodb_buffer_pool_bytes area",
243
- [
244
- ("Innodb_buffer_pool_bytes_data", "data absolute 1"),
245
- ("Innodb_buffer_pool_bytes_dirty", "dirty absolute -1"),
246
- ]),
247
- 'innodb_buffer_pool_read_ahead': (
248
- "'' 'mysql InnoDB Buffer Pool Read Ahead' 'operations/s' innodb mysql.innodb_buffer_pool_read_ahead area",
249
- [
250
- ("Innodb_buffer_pool_read_ahead", "all incremental 1 1"),
251
- ("Innodb_buffer_pool_read_ahead_evicted", "evicted incremental -1 1"),
252
- ("Innodb_buffer_pool_read_ahead_rnd", "random incremental 1 1"),
253
- ]),
254
- 'innodb_buffer_pool_reqs': (
255
- "'' 'mysql InnoDB Buffer Pool Requests' 'requests/s' innodb mysql.innodb_buffer_pool_reqs area",
256
- [
257
- ("Innodb_buffer_pool_read_requests", "reads incremental 1 1"),
258
- ("Innodb_buffer_pool_write_requests", "writes incremental -1 1"),
259
- ]),
260
- 'innodb_buffer_pool_ops': (
261
- "'' 'mysql InnoDB Buffer Pool Operations' 'operations/s' innodb mysql.innodb_buffer_pool_ops area",
262
- [
263
- ("Innodb_buffer_pool_reads", "'disk reads' incremental 1 1"),
264
- ("Innodb_buffer_pool_wait_free", "'wait free' incremental -1 1"),
265
- ]),
266
- 'qcache_ops': (
267
- "'' 'mysql QCache Operations' 'queries/s' qcache mysql.qcache_ops line",
268
- [
269
- ("Qcache_hits", "hits incremental 1 1"),
270
- ("Qcache_lowmem_prunes", "'lowmem prunes' incremental -1 1"),
271
- ("Qcache_inserts", "inserts incremental 1 1"),
272
- ("Qcache_not_cached", "'not cached' incremental -1 1"),
273
- ]),
274
- 'qcache': (
275
- "'' 'mysql QCache Queries in Cache' 'queries' qcache mysql.qcache line",
276
- [
277
- ("Qcache_queries_in_cache", "queries absolute 1 1"),
278
- ]),
279
- 'qcache_freemem': (
280
- "'' 'mysql QCache Free Memory' 'MB' qcache mysql.qcache_freemem area",
281
- [
282
- ("Qcache_free_memory", "free absolute 1"),
283
- ]),
284
- 'qcache_memblocks': (
285
- "'' 'mysql QCache Memory Blocks' 'blocks' qcache mysql.qcache_memblocks line",
286
- [
287
- ("Qcache_free_blocks", "free absolute 1"),
288
- ("Qcache_total_blocks", "total absolute 1 1"),
289
- ]),
290
- 'key_blocks': (
291
- "'' 'mysql MyISAM Key Cache Blocks' 'blocks' myisam mysql.key_blocks line",
292
- [
293
- ("Key_blocks_unused", "unused absolute 1 1"),
294
- ("Key_blocks_used", "used absolute -1 1"),
295
- ("Key_blocks_not_flushed", "'not flushed' absolute 1 1"),
296
- ]),
297
- 'key_requests': (
298
- "'' 'mysql MyISAM Key Cache Requests' 'requests/s' myisam mysql.key_requests area",
299
- [
300
- ("Key_read_requests", "reads incremental 1 1"),
301
- ("Key_write_requests", "writes incremental -1 1"),
302
- ]),
303
- 'key_disk_ops': (
304
- "'' 'mysql MyISAM Key Cache Disk Operations' 'operations/s' myisam mysql.key_disk_ops area",
305
- [
306
- ("Key_reads", "reads incremental 1 1"),
307
- ("Key_writes", "writes incremental -1 1"),
308
- ]),
309
- 'files': (
310
- "'' 'mysql Open Files' 'files' files mysql.files line",
311
- [
312
- ("Open_files", "files absolute 1 1"),
313
- ]),
314
- 'files_rate': (
315
- "'' 'mysql Opened Files Rate' 'files/s' files mysql.files_rate line",
316
- [
317
- ("Opened_files", "files incremental 1 1"),
318
- ]),
319
- 'binlog_stmt_cache': (
320
- "'' 'mysql Binlog Statement Cache' 'statements/s' binlog mysql.binlog_stmt_cache line",
321
- [
322
- ("Binlog_stmt_cache_disk_use", "disk incremental 1 1"),
323
- ("Binlog_stmt_cache_use", "all incremental 1 1"),
324
- ]),
325
- 'connection_errors': (
326
- "'' 'mysql Connection Errors' 'connections/s' connections mysql.connection_errors line",
327
- [
328
- ("Connection_errors_accept", "accept incremental 1 1"),
329
- ("Connection_errors_internal", "internal incremental 1 1"),
330
- ("Connection_errors_max_connections", "max incremental 1 1"),
331
- ("Connection_errors_peer_address", "peer_addr incremental 1 1"),
332
- ("Connection_errors_select", "select incremental 1 1"),
333
- ("Connection_errors_tcpwrap", "tcpwrap incremental 1 1")
334
- ])
64
+ 'net': {
65
+ 'options': [None, 'mysql Bandwidth', 'kilobits/s', 'bandwidth', 'mysql.net', 'area'],
66
+ 'lines': [
67
+ ["Bytes_received", "in", "incremental", 8, 1024],
68
+ ["Bytes_sent", "out", "incremental", -8, 1024]
69
+ ]},
70
+ 'queries': {
71
+ 'options': [None, 'mysql Queries', 'queries/s', 'queries', 'mysql.queries', 'line'],
72
+ 'lines': [
73
+ ["Queries", "queries"],
74
+ ["Questions", "questions"],
75
+ ["Slow_queries", "slow_queries"]
76
+ ]},
77
+ 'handlers': {
78
+ 'options': [None, 'mysql Handlers', 'handlers/s', 'handlers', 'mysql.handlers', 'line'],
79
+ 'lines': [
80
+ ["Handler_commit", "commit"],
81
+ ["Handler_delete", "delete"],
82
+ ["Handler_prepare", "prepare"],
83
+ ["Handler_read_first", "read_first"],
84
+ ["Handler_read_key", "read_key"],
85
+ ["Handler_read_next", "read_next"],
86
+ ["Handler_read_prev", "read_prev"],
87
+ ["Handler_read_rnd", "read_rnd"],
88
+ ["Handler_read_rnd_next", "read_rnd_next"],
89
+ ["Handler_rollback", "rollback"],
90
+ ["Handler_savepoint", "savepoint"],
91
+ ["Handler_savepoint_rollback", "savepoint_rollback"],
92
+ ["Handler_update", "update"],
93
+ ["Handler_write", "write"]
94
+ ]},
95
+ 'table_locks': {
96
+ 'options': [None, 'mysql Tables Locks', 'locks/s', 'locks', 'mysql.table_locks', 'line'],
97
+ 'lines': [
98
+ ["Table_locks_immediate", "immediate"],
99
+ ["Table_locks_waited", "waited", "incremental", -1, 1]
100
+ ]},
101
+ 'join_issues': {
102
+ 'options': [None, 'mysql Select Join Issues', 'joins/s', 'issues', 'mysql.join_issues', 'line'],
103
+ 'lines': [
104
+ ["Select_full_join", "full_join"],
105
+ ["Select_full_range_join", "full_range_join"],
106
+ ["Select_range", "range"],
107
+ ["Select_range_check", "range_check"],
108
+ ["Select_scan", "scan"]
109
+ ]},
110
+ 'sort_issues': {
111
+ 'options': [None, 'mysql Sort Issues', 'issues/s', 'issues', 'mysql.sort.issues', 'line'],
112
+ 'lines': [
113
+ ["Sort_merge_passes", "merge_passes"],
114
+ ["Sort_range", "range"],
115
+ ["Sort_scan", "scan"]
116
+ ]},
117
+ 'tmp': {
118
+ 'options': [None, 'mysql Tmp Operations', 'counter', 'temporaries', 'mysql.tmp', 'line'],
119
+ 'lines': [
120
+ ["Created_tmp_disk_tables", "disk_tables"],
121
+ ["Created_tmp_files", "files"],
122
+ ["Created_tmp_tables", "tables"]
123
+ ]},
124
+ 'connections': {
125
+ 'options': [None, 'mysql Connections', 'connections/s', 'connections', 'mysql.connections', 'line'],
126
+ 'lines': [
127
+ ["Connections", "all"],
128
+ ["Aborted_connects", "aborted"]
129
+ ]},
130
+ 'binlog_cache': {
131
+ 'options': [None, 'mysql Binlog Cache', 'transactions/s', 'binlog', 'mysql.binlog_cache', 'line'],
132
+ 'lines': [
133
+ ["Binlog_cache_disk_use", "disk"],
134
+ ["Binlog_cache_use", "all"]
135
+ ]},
136
+ 'threads': {
137
+ 'options': [None, 'mysql Threads', 'threads', 'threads', 'mysql.threads', 'line'],
138
+ 'lines': [
139
+ ["Threads_connected", "connected", "absolute"],
140
+ ["Threads_created", "created"],
141
+ ["Threads_cached", "cached", "absolute", -1, 1],
142
+ ["Threads_running", "running", "absolute"],
143
+ ]},
144
+ 'thread_cache_misses': {
145
+ 'options': [None, 'mysql Threads Cache Misses', 'misses', 'threads', 'mysql.thread_cache_misses', 'area'],
146
+ 'lines': [
147
+ ["Thread_cache_misses", "misses", "misses", "absolute", 1, 100]
148
+ ]},
149
+ 'innodb_io': {
150
+ 'options': [None, 'mysql InnoDB I/O Bandwidth', 'kilobytes/s', 'innodb', 'mysql.innodb_io', 'area'],
151
+ 'lines': [
152
+ ["Innodb_data_read", "read", "incremental", 1, 1024],
153
+ ["Innodb_data_written", "write", "incremental", -1, 1024]
154
+ ]},
155
+ 'innodb_io_ops': {
156
+ 'lines': [None, 'mysql InnoDB I/O Operations', 'operations/s', 'innodb', 'mysql.innodb_io_ops', 'line'],
157
+ 'options': [
158
+ ["Innodb_data_reads", "reads"],
159
+ ["Innodb_data_writes", "writes", "incremental", -1, 1],
160
+ ["Innodb_data_fsyncs", "fsyncs"]
161
+ ]},
162
+ 'innodb_io_pending_ops': {
163
+ 'options': [None, 'mysql InnoDB Pending I/O Operations', 'operations', 'innodb', 'mysql.innodb_io_pending_ops', 'line'],
164
+ 'lines': [
165
+ ["Innodb_data_pending_reads", "reads", "absolute"],
166
+ ["Innodb_data_pending_writes", "writes", "absolute", -1, 1],
167
+ ["Innodb_data_pending_fsyncs", "fsyncs"]
168
+ ]},
169
+ 'innodb_log': {
170
+ 'options': [None, 'mysql InnoDB Log Operations', 'operations/s', 'innodb', 'mysql.innodb_log', 'line'],
171
+ 'lines': [
172
+ ["Innodb_log_waits", "waits"],
173
+ ["Innodb_log_write_requests", "write_requests", "incremental", -1, 1],
174
+ ["Innodb_log_writes", "incremental", -1, 1],
175
+ ]},
176
+ 'innodb_os_log': {
177
+ 'options': [None, 'mysql InnoDB OS Log Operations', 'operations', 'innodb', 'mysql.innodb_os_log', 'line'],
178
+ 'lines': [
179
+ ["Innodb_os_log_fsyncs", "fsyncs"],
180
+ ["Innodb_os_log_pending_fsyncs", "pending_fsyncs", "absolute"],
181
+ ["Innodb_os_log_pending_writes", "pending_writes", "absolute", -1, 1],
182
+ ]},
183
+ 'innodb_os_log_io': {
184
+ 'options': [None, 'mysql InnoDB OS Log Bandwidth', 'kilobytes/s', 'innodb', 'mysql.innodb_os_log_io', 'area'],
185
+ 'lines': [
186
+ ["Innodb_os_log_written", "write", "incremental", -1, 1024],
187
+ ]},
188
+ 'innodb_cur_row_lock': {
189
+ 'options': [None, 'mysql InnoDB Current Row Locks', 'operations', 'innodb', 'mysql.innodb_cur_row_lock', 'area'],
190
+ 'lines': [
191
+ ["Innodb_row_lock_current_waits", "current_waits", "absolute"]
192
+ ]},
193
+ 'innodb_rows': {
194
+ 'options': [None, 'mysql InnoDB Row Operations', 'operations/s', 'innodb', 'mysql.innodb_rows', 'area'],
195
+ 'lines': [
196
+ ["Innodb_rows_inserted", "read"],
197
+ ["Innodb_rows_read", "deleted", "incremental", -1, 1],
198
+ ["Innodb_rows_updated", "inserted", "incremental", 1, 1],
199
+ ["Innodb_rows_deleted", "updated", "incremental", -1, 1],
200
+ ]},
201
+ 'innodb_buffer_pool_pages': {
202
+ 'options': [None, 'mysql InnoDB Buffer Pool Pages', 'pages', 'innodb', 'mysql.innodb_buffer_pool_pages', 'line'],
203
+ 'lines': [
204
+ ["Innodb_buffer_pool_pages_data", "data", "absolute"],
205
+ ["Innodb_buffer_pool_pages_dirty", "dirty", "absolute", -1, 1],
206
+ ["Innodb_buffer_pool_pages_free", "free", "absolute"],
207
+ ["Innodb_buffer_pool_pages_flushed", "flushed", "incremental", -1, 1],
208
+ ["Innodb_buffer_pool_pages_misc", "misc", "absolute", -1, 1],
209
+ ["Innodb_buffer_pool_pages_total", "total", "absolute"]
210
+ ]},
211
+ 'innodb_buffer_pool_bytes': {
212
+ 'options': [None, 'mysql InnoDB Buffer Pool Bytes', 'MB', 'innodb', 'mysql.innodb_buffer_pool_bytes', 'area'],
213
+ 'lines': [
214
+ ["Innodb_buffer_pool_bytes_data", "data", "absolute"],
215
+ ["Innodb_buffer_pool_bytes_dirty", "dirty", "absolute", -1, 1]
216
+ ]},
217
+ 'innodb_buffer_pool_read_ahead': {
218
+ 'options': [None, 'mysql InnoDB Buffer Pool Read Ahead', 'operations/s', 'innodb', 'mysql.innodb_buffer_pool_read_ahead', 'area'],
219
+ 'lines': [
220
+ ["Innodb_buffer_pool_read_ahead", "all"],
221
+ ["Innodb_buffer_pool_read_ahead_evicted", "evicted", "incremental", -1, 1],
222
+ ["Innodb_buffer_pool_read_ahead_rnd", "random"]
223
+ ]},
224
+ 'innodb_buffer_pool_reqs': {
225
+ 'options': [None, 'mysql InnoDB Buffer Pool Requests', 'requests/s', 'innodb', 'mysql.innodb_buffer_pool_reqs', 'area'],
226
+ 'lines': [
227
+ ["Innodb_buffer_pool_read_requests", "reads"],
228
+ ["Innodb_buffer_pool_write_requests", "writes", "incremental", -1, 1]
229
+ ]},
230
+ 'innodb_buffer_pool_ops': {
231
+ 'options': [None, 'mysql InnoDB Buffer Pool Operations', 'operations/s', 'innodb', 'mysql.innodb_buffer_pool_ops', 'area'],
232
+ 'lines': [
233
+ ["Innodb_buffer_pool_reads", "disk reads"],
234
+ ["Innodb_buffer_pool_wait_free", "wait free", "incremental", -1, 1]
235
+ ]},
236
+ 'qcache_ops': {
237
+ 'options': [None, 'mysql QCache Operations', 'queries/s', 'qcache', 'mysql.qcache_ops', 'line'],
238
+ 'lines': [
239
+ ["Qcache_hits", "hits"],
240
+ ["Qcache_lowmem_prunes", "lowmem prunes", "incremental", -1, 1],
241
+ ["Qcache_inserts", "inserts"],
242
+ ["Qcache_not_cached", "not cached", "incremental", -1, 1]
243
+ ]},
244
+ 'qcache': {
245
+ 'options': [None, 'mysql QCache Queries in Cache', 'queries', 'qcache', 'mysql.qcache', 'line'],
246
+ 'lines': [
247
+ ["Qcache_queries_in_cache", "queries", "absolute"]
248
+ ]},
249
+ 'qcache_freemem': {
250
+ 'options': [None, 'mysql QCache Free Memory', 'MB', 'qcache', 'mysql.qcache_freemem', 'area'],
251
+ 'lines': [
252
+ ["Qcache_free_memory", "free", "absolute"]
253
+ ]},
254
+ 'qcache_memblocks': {
255
+ 'options': [None, 'mysql QCache Memory Blocks', 'blocks', 'qcache', 'mysql.qcache_memblocks', 'line'],
256
+ 'lines': [
257
+ ["Qcache_free_blocks", "free", "absolute"],
258
+ ["Qcache_total_blocks", "total", "absolute"]
259
+ ]},
260
+ 'key_blocks': {
261
+ 'options': [None, 'mysql MyISAM Key Cache Blocks', 'blocks', 'myisam', 'mysql.key_blocks', 'line'],
262
+ 'lines': [
263
+ ["Key_blocks_unused", "unused", "absolute"],
264
+ ["Key_blocks_used", "used", "absolute", -1, 1],
265
+ ["Key_blocks_not_flushed", "not flushed", "absolute"]
266
+ ]},
267
+ 'key_requests': {
268
+ 'options': [None, 'mysql MyISAM Key Cache Requests', 'requests/s', 'myisam', 'mysql.key_requests', 'area'],
269
+ 'lines': [
270
+ ["Key_read_requests", "reads"],
271
+ ["Key_write_requests", "writes", "incremental", -1, 1]
272
+ ]},
273
+ 'key_disk_ops': {
274
+ 'options': [None, 'mysql MyISAM Key Cache Disk Operations', 'operations/s', 'myisam', 'mysql.key_disk_ops', 'area'],
275
+ 'lines': [
276
+ ["Key_reads", "reads"],
277
+ ["Key_writes", "writes", "incremental", -1, 1]
278
+ ]},
279
+ 'files': {
280
+ 'options': [None, 'mysql Open Files', 'files', 'files', 'mysql.files', 'line'],
281
+ 'lines': [
282
+ ["Open_files", "files", "absolute"]
283
+ ]},
284
+ 'files_rate': {
285
+ 'options': [None, 'mysql Opened Files Rate', 'files/s', 'files', 'mysql.files_rate', 'line'],
286
+ 'lines': [
287
+ ["Opened_files", "files"]
288
+ ]},
289
+ 'binlog_stmt_cache': {
290
+ 'options': [None, 'mysql Binlog Statement Cache', 'statements/s', 'binlog', 'mysql.binlog_stmt_cache', 'line'],
291
+ 'lines': [
292
+ ["Binlog_stmt_cache_disk_use", "disk"],
293
+ ["Binlog_stmt_cache_use", "all"]
294
+ ]},
295
+ 'connection_errors': {
296
+ 'options': [None, 'mysql Connection Errors', 'connections/s', 'connections', 'mysql.connection_errors', 'line'],
297
+ 'lines': [
298
+ ["Connection_errors_accept", "accept"],
299
+ ["Connection_errors_internal", "internal"],
300
+ ["Connection_errors_max_connections", "max"],
301
+ ["Connection_errors_peer_address", "peer_addr"],
302
+ ["Connection_errors_select", "select"],
303
+ ["Connection_errors_tcpwrap", "tcpwrap"]
304
+ ]}
305
+
306
}
307
308
338
-class Service(BaseService):
309
+class Service(SimpleService):
310
def __init__(self, configuration=None, name=None):
340
- super(self.__class__, self).__init__(configuration=configuration, name=name)
341
- self.configuration = self._parse_config(configuration)
311
+ SimpleService.__init__(self, configuration=configuration, name=name)
312
+ self._parse_config(configuration)
313
+ self.order = ORDER
314
+ self.definitions = CHARTS
315
self.connection = None
343
- self.defs = {}
316
317
def _parse_config(self, configuration):
318
"""
@@ -351,26 +323,24 @@ class Service(BaseService):
323
if self.name is None:
324
self.name = 'local'
325
if 'user' not in configuration:
354
- configuration['user'] = 'root'
326
+ self.configuration['user'] = 'root'
327
if 'password' not in configuration:
356
- configuration['password'] = ''
328
+ self.configuration['password'] = ''
329
if 'my.cnf' in configuration:
358
- configuration['socket'] = ''
359
- configuration['host'] = ''
360
- configuration['port'] = 0
330
+ self.configuration['socket'] = ''
331
+ self.configuration['host'] = ''
332
+ self.configuration['port'] = 0
333
elif 'socket' in configuration:
362
- configuration['my.cnf'] = ''
363
- configuration['host'] = ''
364
- configuration['port'] = 0
334
+ self.configuration['my.cnf'] = ''
335
+ self.configuration['host'] = ''
336
+ self.configuration['port'] = 0
337
elif 'host' in configuration:
366
- configuration['my.cnf'] = ''
367
- configuration['socket'] = ''
338
+ self.configuration['my.cnf'] = ''
339
+ self.configuration['socket'] = ''
340
if 'port' in configuration:
369
- configuration['port'] = int(configuration['port'])
341
+ self.configuration['port'] = int(configuration['port'])
342
else:
371
- configuration['port'] = 3306
372
-
373
- return configuration
343
+ self.configuration['port'] = 3306
344
345
def _connect(self):
346
"""
@@ -410,6 +380,9 @@ class Service(BaseService):
380
381
return dict(raw_data)
382
383
+ def _formatted_data(self):
384
+ return self._get_data()
385
+
386
def check(self):
387
"""
388
Check if service is able to connect to server
@@ -422,63 +395,63 @@ class Service(BaseService):
395
self.connection = None
396
return False
397
425
- def create(self):
426
- """
427
- Create graphs
428
- :return: boolean
429
- """
430
- for name in ORDER:
431
- self.defs[name] = []
432
- for line in CHARTS[name][1]:
433
- self.defs[name].append(line[0])
434
-
435
- idx = 0
436
- data = self._get_data()
437
- if data is None:
438
- return False
439
- for name in ORDER:
440
- header = "CHART mysql_" + \
441
- str(self.name) + "." + \
442
- name + " " + \
443
- CHARTS[name][0] + " " + \
444
- str(self.priority + idx) + " " + \
445
- str(self.update_every)
446
- content = ""
447
- # check if server has this data point
448
- for line in CHARTS[name][1]:
449
- if line[0] in data:
450
- content += "DIMENSION " + line[0] + " " + line[1] + "\n"
451
- if len(content) > 0:
452
- print(header)
453
- print(content)
454
- idx += 1
455
-
456
- if idx == 0:
457
- return False
458
- return True
459
-
460
- def update(self, interval):
461
- """
462
- Update data on graphs
463
- :param interval: int
464
- :return: boolean
465
- """
466
- data = self._get_data()
467
- if data is None:
468
- return False
469
- try:
470
- data['Thread cache misses'] = int(int(data['Threads_created']) * 10000 / int(data['Connections']))
471
- except Exception:
472
- pass
473
- for chart, dimensions in self.defs.items():
474
- header = "BEGIN mysql_" + str(self.name) + "." + chart + " " + str(interval) + '\n'
475
- lines = ""
476
- for d in dimensions:
477
- try:
478
- lines += "SET " + d + " = " + data[d] + '\n'
479
- except KeyError:
480
- pass
481
- if len(lines) > 0:
482
- print(header + lines + "END")
483
-
484
- return True
398
+ # def create(self):
399
+ # """
400
+ # Create graphs
401
+ # :return: boolean
402
+ # """
403
+ # for name in ORDER:
404
+ # self.defs[name] = []
405
+ # for line in CHARTS[name][1]:
406
+ # self.defs[name].append(line[0])
407
+ #
408
+ # idx = 0
409
+ # data = self._get_data()
410
+ # if data is None:
411
+ # return False
412
+ # for name in ORDER:
413
+ # header = "CHART mysql_" + \
414
+ # str(self.name) + "." + \
415
+ # name + " " + \
416
+ # CHARTS[name][0] + " " + \
417
+ # str(self.priority + idx) + " " + \
418
+ # str(self.update_every)
419
+ # content = ""
420
+ # # check if server has this data point
421
+ # for line in CHARTS[name][1]:
422
+ # if line[0] in data:
423
+ # content += "DIMENSION " + line[0] + " " + line[1] + "\n"
424
+ # if len(content) > 0:
425
+ # print(header)
426
+ # print(content)
427
+ # idx += 1
428
+ #
429
+ # if idx == 0:
430
+ # return False
431
+ # return True
432
+ #
433
+ # def update(self, interval):
434
+ # """
435
+ # Update data on graphs
436
+ # :param interval: int
437
+ # :return: boolean
438
+ # """
439
+ # data = self._get_data()
440
+ # if data is None:
441
+ # return False
442
+ # try:
443
+ # data['Thread cache misses'] = int(int(data['Threads_created']) * 10000 / int(data['Connections']))
444
+ # except Exception:
445
+ # pass
446
+ # for chart, dimensions in self.defs.items():
447
+ # header = "BEGIN mysql_" + str(self.name) + "." + chart + " " + str(interval) + '\n'
448
+ # lines = ""
449
+ # for d in dimensions:
450
+ # try:
451
+ # lines += "SET " + d + " = " + data[d] + '\n'
452
+ # except KeyError:
453
+ # pass
454
+ # if len(lines) > 0:
455
+ # print(header + lines + "END")
456
+ #
457
+ # return True