pythond_small_fixes (#4185)
* pyhton.d.plugin: respect update_every in jobs * pyhton.d.plugin: run gc.collect every 300 secs in main thread * pyhton.d.plugin: gc collect work around comment * python.d.plugin: do not run all modules debug * python.d.plugin: make gc.collect runs optional, add options to python.d.conf
Ilya Mashchenko committed
Sep 18, 2018 at 07:54 UTC
6e345ef6544ba452dca7fb6f96ae6bb5b8b37852
2 files changed
+24
-16
conf.d/python.d.conf
+6
@@ -19,6 +19,12 @@ enabled: yes
19
# If "default_run" = "no" the default for all modules is disabled (no).
20
# Setting any of these to "yes" will enable it.
21
22
+# Enable / Disable explicit garbage collection (full collection run). Default is enabled.
23
+gc_run: yes
24
+
25
+# Garbage collection interval in seconds. Default is 300.
26
+gc_interval: 300
27
+
28
# apache_cache has been replaced by web_log
29
apache_cache: no
30
# apache: yes
plugins.d/python.d.plugin
+18
-16
@@ -8,6 +8,7 @@ echo "ERROR python IS NOT AVAILABLE IN THIS SYSTEM")" "$0" "$@" # '''
8
# Author: Ilya Mashchenko (l2isbad)
9
# SPDX-License-Identifier: GPL-3.0+
10
11
+import gc
12
import os
13
import sys
14
import threading
@@ -16,6 +17,8 @@ from re import sub
17
from sys import version_info, argv
18
from time import sleep
19
20
+GC_RUN = True
21
+GC_COLLECT_EVERY = 300
22
23
PY_VERSION = version_info[:2]
24
PLUGIN_CONFIG_DIR = os.getenv('NETDATA_CONFIG_DIR', os.path.dirname(__file__) + '/../../../../etc/netdata') + '/'
@@ -85,7 +88,7 @@ class Job(object):
88
self.recheck_every = self.job.configuration.pop('autodetection_retry')
89
self.checked = False # used in Plugin.check_job()
90
self.created = False # used in Plugin.create_job_charts()
88
- if OVERRIDE_UPDATE_EVERY:
91
+ if self.job.update_every < int(OVERRIDE_UPDATE_EVERY):
92
self.job.update_every = int(OVERRIDE_UPDATE_EVERY)
93
94
def __getattr__(self, item):
@@ -202,6 +205,8 @@ class Plugin(object):
205
self.config, error = self.loader.load_config_from_file(PLUGIN_CONFIG_DIR + 'python.d.conf')
206
if error:
207
Logger.error('"python.d.conf" configuration file not found. Using defaults.')
208
+ self.do_gc = self.config.get("gc_run", GC_RUN)
209
+ self.gc_interval = self.config.get("gc_interval", GC_COLLECT_EVERY)
210
211
if not self.config.get('enabled', True):
212
run_and_exit(Logger.info)('DISABLED in configuration file.')
@@ -230,26 +235,18 @@ class Plugin(object):
235
mod_name = mod[:-len(MODULE_EXTENSION)]
236
mod_path = CHARTS_PY_DIR + mod
237
conf_path = ''.join([CHARTS_PY_CONFIG_DIR, mod_name, '.conf'])
233
-
234
- if DEBUG:
238
+ if any(
239
+ [
240
+ self.config.get('default_run', True) and self.config.get(mod_name, True),
241
+ (not self.config.get('default_run')) and self.config.get(mod_name),
242
+ ]
243
+ ):
244
yield RawModule(
245
name=mod_name,
246
path=mod_path,
247
conf_path=conf_path,
248
+ explicitly_enabled=self.config.get(mod_name),
249
)
240
- else:
241
- if any(
242
- [
243
- self.config.get('default_run', True) and self.config.get(mod_name, True),
244
- (not self.config.get('default_run')) and self.config.get(mod_name),
245
- ]
246
- ):
247
- yield RawModule(
248
- name=mod_name,
249
- path=mod_path,
250
- conf_path=conf_path,
251
- explicitly_enabled=self.config.get(mod_name),
252
- )
250
251
def load_and_initialize_modules(self):
252
for mod in self.enabled_modules():
@@ -368,6 +365,11 @@ class Plugin(object):
365
self.cleanup()
366
self.autodetect_retry()
367
368
+ # FIXME: https://github.com/firehol/netdata/issues/3817
369
+ if self.do_gc and self.runs_counter % self.gc_interval == 0:
370
+ v = gc.collect()
371
+ Logger.debug("GC full collection run result: {0}".format(v))
372
+
373
def cleanup(self):
374
for job in self.dead_jobs:
375
self.delete_job(job)