@cryptotaxi247 / netdata-1 / commits / 8a5e71342

add _collect_job label to python.d/* charts (#13648)

Ilya Mashchenko committed Sep 8, 2022 at 17:35 UTC 8a5e7134281c3e1190667f0996be773ee8720d6a
2 files changed +14 -4
collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py
+3 -2
@@ -7,11 +7,10 @@
7
8 from time import sleep, time
9
10 -from third_party.monotonic import monotonic
11 -
10 from bases.charts import Charts, ChartError, create_runtime_chart
11 from bases.collection import safe_print
12 from bases.loggers import PythonDLimitedLogger
13 +from third_party.monotonic import monotonic
14
15 RUNTIME_CHART_UPDATE = 'BEGIN netdata.runtime_{job_name} {since_last}\n' \
16 'SET run_time = {elapsed}\n' \
@@ -79,11 +78,13 @@ class SimpleService(PythonDLimitedLogger, object):
78
79 self.module_name = clean_module_name(self.__module__)
80 self.job_name = configuration.pop('job_name')
81 + self.actual_job_name = self.job_name or self.module_name
82 self.override_name = configuration.pop('override_name')
83 self.fake_name = None
84
85 self._runtime_counters = RuntimeCounters(configuration=configuration)
86 self.charts = Charts(job_name=self.actual_name,
87 + actual_job_name=self.actual_job_name,
88 priority=configuration.pop('priority'),
89 cleanup=configuration.pop('chart_cleanup'),
90 get_update_every=self.get_update_every,
collectors/python.d.plugin/python_modules/bases/charts.py
+11 -2
@@ -18,6 +18,9 @@ CHART_CREATE = "CHART {type}.{id} '{name}' '{title}' '{units}' '{family}' '{cont
18 CHART_OBSOLETE = "CHART {type}.{id} '{name}' '{title}' '{units}' '{family}' '{context}' " \
19 "{chart_type} {priority} {update_every} '{hidden} obsolete'\n"
20
21 +CLABEL_COLLECT_JOB = "CLABEL '_collect_job' '{actual_job_name}' '0'\n"
22 +CLABEL_COMMIT = "CLABEL_COMMIT\n"
23 +
24 DIMENSION_CREATE = "DIMENSION '{id}' '{name}' {algorithm} {multiplier} {divisor} '{hidden} {obsolete}'\n"
25 DIMENSION_SET = "SET '{id}' = {value}\n"
26
@@ -25,6 +28,8 @@ CHART_VARIABLE_SET = "VARIABLE CHART '{id}' = {value}\n"
28
29 RUNTIME_CHART_CREATE = "CHART netdata.runtime_{job_name} '' 'Execution time' 'ms' 'python.d' " \
30 "netdata.pythond_runtime line 145000 {update_every} '' 'python.d.plugin' '{module_name}'\n" \
31 + "CLABEL '_collect_job' '{actual_job_name}' '0'\n" \
32 + "CLABEL_COMMIT\n" \
33 "DIMENSION run_time 'run time' absolute 1 1\n"
34
35
@@ -44,6 +49,7 @@ def create_runtime_chart(func):
49 self = args[0]
50 chart = RUNTIME_CHART_CREATE.format(
51 job_name=self.name,
52 + actual_job_name=self.actual_job_name,
53 update_every=self._runtime_counters.update_every,
54 module_name=self.module_name,
55 )
@@ -77,13 +83,14 @@ class Charts:
83 Chart is a instance of Chart class.
84 Charts adding must be done using Charts.add_chart() method only"""
85
80 - def __init__(self, job_name, priority, cleanup, get_update_every, module_name):
86 + def __init__(self, job_name, actual_job_name, priority, cleanup, get_update_every, module_name):
87 """
88 :param job_name: <bound method>
89 :param priority: <int>
90 :param get_update_every: <bound method>
91 """
92 self.job_name = job_name
93 + self.actual_job_name = actual_job_name
94 self.priority = priority
95 self.cleanup = cleanup
96 self.get_update_every = get_update_every
@@ -131,6 +138,7 @@ class Charts:
138 new_chart.params['update_every'] = self.get_update_every()
139 new_chart.params['priority'] = self.priority
140 new_chart.params['module_name'] = self.module_name
141 + new_chart.params['actual_job_name'] = self.actual_job_name
142
143 self.priority += 1
144 self.charts[new_chart.id] = new_chart
@@ -230,13 +238,14 @@ class Chart:
238 :return:
239 """
240 chart = CHART_CREATE.format(**self.params)
241 + labels = CLABEL_COLLECT_JOB.format(**self.params) + CLABEL_COMMIT
242 dimensions = ''.join([dimension.create() for dimension in self.dimensions])
243 variables = ''.join([var.set(var.value) for var in self.variables if var])
244
245 self.flags.push = False
246 self.flags.created = True
247
239 - safe_print(chart + dimensions + variables)
248 + safe_print(chart + labels + dimensions + variables)
249
250 def can_be_updated(self, data):
251 for dim in self.dimensions: