feat(python.d): respect NETDATA_INTERNALS_MONITORING (#13793)
Ilya Mashchenko committed
Oct 10, 2022 at 15:01 UTC
49363f50c8d9f8d450cd25b57ccb84f52e8925dd
2 files changed
+20
-12
collectors/python.d.plugin/python_modules/bases/FrameworkServices/SimpleService.py
+8
-5
@@ -4,13 +4,13 @@
4
# Author: Ilya Mashchenko (ilyam8)
5
# SPDX-License-Identifier: GPL-3.0-or-later
6
7
-
8
-from time import sleep, time
7
+import os
8
9
from bases.charts import Charts, ChartError, create_runtime_chart
10
from bases.collection import safe_print
11
from bases.loggers import PythonDLimitedLogger
12
from third_party.monotonic import monotonic
13
+from time import sleep, time
14
15
RUNTIME_CHART_UPDATE = 'BEGIN netdata.runtime_{job_name} {since_last}\n' \
16
'SET run_time = {elapsed}\n' \
@@ -19,6 +19,8 @@ RUNTIME_CHART_UPDATE = 'BEGIN netdata.runtime_{job_name} {since_last}\n' \
19
PENALTY_EVERY = 5
20
MAX_PENALTY = 10 * 60 # 10 minutes
21
22
+ND_INTERNAL_MONITORING_DISABLED = os.getenv("NETDATA_INTERNALS_MONITORING") == "NO"
23
+
24
25
class RuntimeCounters:
26
def __init__(self, configuration):
@@ -209,9 +211,10 @@ class SimpleService(PythonDLimitedLogger, object):
211
job.elapsed = int((monotonic() - job.start_mono) * 1e3)
212
job.prev_update = job.start_real
213
job.retries, job.penalty = 0, 0
212
- safe_print(RUNTIME_CHART_UPDATE.format(job_name=self.name,
213
- since_last=since,
214
- elapsed=job.elapsed))
214
+ if not ND_INTERNAL_MONITORING_DISABLED:
215
+ safe_print(RUNTIME_CHART_UPDATE.format(job_name=self.name,
216
+ since_last=since,
217
+ elapsed=job.elapsed))
218
self.debug('update => [{status}] (elapsed time: {elapsed}, failed retries in a row: {retries})'.format(
219
status='OK' if updated else 'FAILED',
220
elapsed=job.elapsed if updated else '-',
collectors/python.d.plugin/python_modules/bases/charts.py
+12
-7
@@ -3,6 +3,8 @@
3
# Author: Ilya Mashchenko (ilyam8)
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
6
+import os
7
+
8
from bases.collection import safe_print
9
10
CHART_PARAMS = ['type', 'id', 'name', 'title', 'units', 'family', 'context', 'chart_type', 'hidden']
@@ -34,6 +36,8 @@ RUNTIME_CHART_CREATE = "CHART netdata.runtime_{job_name} '' 'Execution time' 'ms
36
"CLABEL_COMMIT\n" \
37
"DIMENSION run_time 'run time' absolute 1 1\n"
38
39
+ND_INTERNAL_MONITORING_DISABLED = os.getenv("NETDATA_INTERNALS_MONITORING") == "NO"
40
+
41
42
def create_runtime_chart(func):
43
"""
@@ -49,13 +53,14 @@ def create_runtime_chart(func):
53
54
def wrapper(*args, **kwargs):
55
self = args[0]
52
- chart = RUNTIME_CHART_CREATE.format(
53
- job_name=self.name,
54
- actual_job_name=self.actual_job_name,
55
- update_every=self._runtime_counters.update_every,
56
- module_name=self.module_name,
57
- )
58
- safe_print(chart)
56
+ if not ND_INTERNAL_MONITORING_DISABLED:
57
+ chart = RUNTIME_CHART_CREATE.format(
58
+ job_name=self.name,
59
+ actual_job_name=self.actual_job_name,
60
+ update_every=self._runtime_counters.update_every,
61
+ module_name=self.module_name,
62
+ )
63
+ safe_print(chart)
64
ok = func(*args, **kwargs)
65
return ok
66