@cryptotaxi247 / netdata-1 / commits / ae972dbd7

beanstalk module: connection stats() charts added

lgz committed Nov 3, 2017 at 01:56 UTC ae972dbd71fb0ca60daddfd2be35e8affff78774
1 file changed +98 -7
python.d/beanstalk.chart.py
+98 -7
@@ -25,8 +25,97 @@ from bases.FrameworkServices.SimpleService import SimpleService
25 priority = 60000
26 retries = 60
27
28 +ORDER = ['cpu_usage', 'jobs_rate', 'connections_rate', 'commands_rate', 'current_tubes', 'current_jobs',
29 + 'current_connections', 'binlog', 'uptime']
30 +
31 +CHARTS = {
32 + 'cpu_usage': {
33 + 'options': [None, 'Cpu Usage', 'cpu time', 'statistics', 'beanstalk.cpu_usage', 'area'],
34 + 'lines': [
35 + ['rusage-utime', 'user', 'incremental'],
36 + ['rusage-stime', 'system', 'incremental']
37 + ]
38 + },
39 + 'jobs_rate': {
40 + 'options': [None, 'Jobs Rate', 'jobs/s', 'statistics', 'beanstalk.jobs_rate', 'line'],
41 + 'lines': [
42 + ['total-jobs', 'total', 'incremental'],
43 + ['job-timeouts', 'timeouts', 'incremental']
44 + ]
45 + },
46 + 'connections_rate': {
47 + 'options': [None, 'Connections Rate', 'connections/s', 'statistics', 'beanstalk.connections_rate', 'area'],
48 + 'lines': [
49 + ['total-connections', 'connections', 'incremental']
50 + ]
51 + },
52 + 'commands_rate': {
53 + 'options': [None, 'Commands Rate', 'command/s', 'statistics', 'beanstalk.commands_rate', 'stacked'],
54 + 'lines': [
55 + ['cmd-put', 'put', 'incremental'],
56 + ['cmd-peek', 'peek', 'incremental'],
57 + ['cmd-peek-ready', 'peek-ready', 'incremental'],
58 + ['cmd-peek-delayed', 'peek-delayed', 'incremental'],
59 + ['cmd-peek-buried', 'peek-buried', 'incremental'],
60 + ['cmd-reserve', 'reserve', 'incremental'],
61 + ['cmd-use', 'use', 'incremental'],
62 + ['cmd-watch', 'watch', 'incremental'],
63 + ['cmd-ignore', 'ignore', 'incremental'],
64 + ['cmd-delete', 'delete', 'incremental'],
65 + ['cmd-release', 'release', 'incremental'],
66 + ['cmd-bury', 'bury', 'incremental'],
67 + ['cmd-kick', 'kick', 'incremental'],
68 + ['cmd-stats', 'stats', 'incremental'],
69 + ['cmd-stats-job', 'stats-job', 'incremental'],
70 + ['cmd-stats-tube', 'stats-tube', 'incremental'],
71 + ['cmd-list-tubes', 'list-tubes', 'incremental'],
72 + ['cmd-list-tube-used', 'list-tube-used', 'incremental'],
73 + ['cmd-list-tubes-watched', 'list-tubes-watched', 'incremental'],
74 + ['cmd-pause-tube', 'pause-tube', 'incremental']
75 + ]
76 + },
77 + 'current_tubes': {
78 + 'options': [None, 'Current Tubes', 'tubes', 'statistics', 'beanstalk.current_tubes', 'area'],
79 + 'lines': [
80 + ['current-tubes', 'tubes']
81 + ]
82 + },
83 + 'current_jobs': {
84 + 'options': [None, 'Current Jobs', 'jobs', 'statistics', 'beanstalk.current_jobs', 'stacked'],
85 + 'lines': [
86 + ['current-jobs-urgent', 'urgent'],
87 + ['current-jobs-ready', 'ready'],
88 + ['current-jobs-reserved', 'reserved'],
89 + ['current-jobs-delayed', 'delayed'],
90 + ['current-jobs-buried', 'buried']
91 + ]
92 + },
93 + 'current_connections': {
94 + 'options': [None, 'Current Connections', 'connections', 'statistics', 'beanstalk.current_connections', 'line'],
95 + 'lines': [
96 + ['current-connections', 'written'],
97 + ['current-producers', 'producers'],
98 + ['current-workers', 'workers'],
99 + ['current-waiting', 'waiting']
100 + ]
101 + },
102 + 'binlog': {
103 + 'options': [None, 'Binlog', 'records/s', 'statistics', 'beanstalk.binlog', 'line'],
104 + 'lines': [
105 + ['binlog-records-written', 'written', 'incremental'],
106 + ['binlog-records-migrated', 'migrated', 'incremental']
107 + ]
108 + },
109 + 'uptime': {
110 + 'options': [None, 'Uptime', 'seconds', 'statistics', 'beanstalk.uptime', 'line'],
111 + 'lines': [
112 + ['uptime'],
113 + ]
114 + }
115 +}
116 +
117
29 -def chart_template(name):
118 +def tube_chart_template(name):
119 order = ['{0}_jobs_rate'.format(name),
120 '{0}_jobs'.format(name),
121 '{0}_connections'.format(name),
@@ -80,8 +169,8 @@ class Service(SimpleService):
169 SimpleService.__init__(self, configuration=configuration, name=name)
170 self.configuration = configuration
171 self.conn = self.connect()
83 - self.order = list()
84 - self.definitions = dict()
172 + self.order = ORDER[:]
173 + self.definitions = dict(CHARTS)
174 self.alive = True
175
176 def check(self):
@@ -93,7 +182,7 @@ class Service(SimpleService):
182 return False
183
184 for tube in self.conn.tubes():
96 - order, charts = chart_template(tube)
185 + order, charts = tube_chart_template(tube)
186 self.order.extend(order)
187 self.definitions.update(charts)
188
@@ -106,16 +195,17 @@ class Service(SimpleService):
195 """
196 if not self.is_alive():
197 return None
109 - else:
110 - self.alive = True
198
199 tubes_stats, data = defaultdict(dict), dict()
200 try:
201 + data.update(self.conn.stats())
202 +
203 for tube in self.conn.tubes():
204 stats = self.conn.stats_tube(tube)
205 for stat in stats:
206 dimension, value = '_'.join([tube, stat]), stats[stat]
207 tubes_stats[tube][dimension] = value
208 +
209 except beanstalkc.SocketError:
210 self.alive = False
211 return None
@@ -129,7 +219,7 @@ class Service(SimpleService):
219 return data or None
220
221 def create_new_tube_charts(self, tube):
132 - order, charts = chart_template(tube)
222 + order, charts = tube_chart_template(tube)
223
224 for chart_name in order:
225 params = [chart_name] + charts[chart_name]['options']
@@ -152,6 +242,7 @@ class Service(SimpleService):
242 def reconnect(self):
243 try:
244 self.conn.reconnect()
245 + self.alive = True
246 return True
247 except beanstalkc.SocketError:
248 return False