0
0
Fork 0
mirror of https://github.com/netdata/netdata.git synced 2025-05-18 15:11:22 +00:00

beanstalk module: remove defaultdict, remove chart creating on check()

This commit is contained in:
lgz 2017-11-05 15:28:09 +09:00
parent 038f276e78
commit 6931479c38

View file

@ -2,8 +2,6 @@
# Description: beanstalk netdata python.d module # Description: beanstalk netdata python.d module
# Author: l2isbad # Author: l2isbad
from collections import defaultdict
try: try:
import beanstalkc import beanstalkc
BEANSTALKC = True BEANSTALKC = True
@ -168,9 +166,9 @@ class Service(SimpleService):
def __init__(self, configuration=None, name=None): def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name) SimpleService.__init__(self, configuration=configuration, name=name)
self.configuration = configuration self.configuration = configuration
self.conn = None self.order = list(ORDER)
self.order = ORDER[:]
self.definitions = dict(CHARTS) self.definitions = dict(CHARTS)
self.conn = None
self.alive = True self.alive = True
def check(self): def check(self):
@ -184,15 +182,7 @@ class Service(SimpleService):
self.conn = self.connect() self.conn = self.connect()
if not self.conn: return True if self.conn else False
return False
for tube in self.conn.tubes():
order, charts = tube_chart_template(tube)
self.order.extend(order)
self.definitions.update(charts)
return bool(self.order)
def get_data(self): def get_data(self):
""" """
@ -202,27 +192,25 @@ class Service(SimpleService):
if not self.is_alive(): if not self.is_alive():
return None return None
tubes_stats, data = defaultdict(dict), dict() active_charts = self.charts.active_charts()
data = dict()
try: try:
data.update(self.conn.stats()) data.update(self.conn.stats())
for tube in self.conn.tubes(): for tube in self.conn.tubes():
stats = self.conn.stats_tube(tube) stats = self.conn.stats_tube(tube)
if tube + '_jobs_rate' not in active_charts:
self.create_new_tube_charts(tube)
for stat in stats: for stat in stats:
dimension, value = '_'.join([tube, stat]), stats[stat] data['_'.join([tube, stat])] = stats[stat]
tubes_stats[tube][dimension] = value
except beanstalkc.SocketError: except beanstalkc.SocketError:
self.alive = False self.alive = False
return None return None
active_charts = self.charts.active_charts()
for tube in tubes_stats:
if tube + '_jobs_rate' not in active_charts:
self.create_new_tube_charts(tube)
data.update(tubes_stats[tube])
return data or None return data or None
def create_new_tube_charts(self, tube): def create_new_tube_charts(self, tube):