|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
__author__ = 'Kenny Freeman' |
|
4
|
|
|
__email__ = '[email protected]' |
|
5
|
|
|
__license__ = "ISCL" |
|
6
|
|
|
__docformat__ = 'reStructuredText' |
|
7
|
|
|
|
|
8
|
|
|
import time |
|
9
|
|
|
from collections import deque |
|
10
|
|
|
|
|
11
|
|
|
import pymysql # not listed in setup.py requirements - you must install this |
|
12
|
|
|
|
|
13
|
|
|
import plumd |
|
14
|
|
|
import plumd.plugins |
|
15
|
|
|
from plumd.calc import Differential |
|
16
|
|
|
from plumd.util import Filter |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
""" |
|
20
|
|
|
KEY_CACHES |
|
21
|
|
|
INFORMATION_SCHEMA |
|
22
|
|
|
TABLES # or show table status - not accurate for innodb |
|
23
|
|
|
INNODB_TRX |
|
24
|
|
|
INNODB_BUFFER_POOL_STATS |
|
25
|
|
|
TP_THREAD_STATE # thread_handling=pool-of-threads in /etc/my.cnf |
|
26
|
|
|
""" |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
class MySql(plumd.plugins.Reader): |
|
30
|
|
|
"""Plugin to measure various MySQL metrics.""" |
|
31
|
|
|
defaults = { |
|
32
|
|
|
'poll.interval': 10, |
|
33
|
|
|
'mysql_hosts': { |
|
34
|
|
|
'local': { |
|
35
|
|
|
'host': '127.0.0.1', |
|
36
|
|
|
'port': 3306, |
|
37
|
|
|
'user': 'monitor', |
|
38
|
|
|
'pass': 'monitor', |
|
39
|
|
|
'dbs': ['mysql'] |
|
40
|
|
|
} |
|
41
|
|
|
}, |
|
42
|
|
|
'mysql_gauges': {}, |
|
43
|
|
|
'mysql_rates': {} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
View Code Duplication |
def __init__(self, log, config): |
|
|
|
|
|
|
47
|
|
|
"""Plugin to measure various MySQL metrics. |
|
48
|
|
|
|
|
49
|
|
|
:param log: A logger |
|
50
|
|
|
:type log: logging.RootLogger |
|
51
|
|
|
:param config: a plumd.config.Conf configuration helper instance. |
|
52
|
|
|
:type config: plumd.config.Conf |
|
53
|
|
|
""" |
|
54
|
|
|
super(MySql, self).__init__(log, config) |
|
55
|
|
|
self.config.defaults(MySql.defaults) |
|
56
|
|
|
self.calc = Differential() |
|
57
|
|
|
self.hosts = self.config.get('mysql_hosts') |
|
58
|
|
|
self.filter = Filter() |
|
59
|
|
|
self.gauges = self.config.get('mysql_gauges') |
|
60
|
|
|
self.rates = self.config.get('mysql_rates') |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
def poll(self): |
|
64
|
|
|
"""Poll for MySQL metrics. |
|
65
|
|
|
|
|
66
|
|
|
:rtype: ResultSet |
|
67
|
|
|
""" |
|
68
|
|
|
result = plumd.Result("mysql") |
|
69
|
|
|
|
|
70
|
|
|
# iterate through each configured host |
|
71
|
|
|
for hname, hconf in self.hosts.items(): |
|
72
|
|
|
# show status for general metrics |
|
73
|
|
|
pass |
|
74
|
|
|
|
|
75
|
|
|
return [result] |
|
76
|
|
|
|