added option to pass interval with command line parameter
paulfantom committed
Jun 11, 2016 at 13:50 UTC
4918953dbe94d117f6d0bc2ce9aff1b7ffe3d485
1 file changed
+12
-2
plugins.d/python.d.plugin
+12
-2
@@ -212,6 +212,7 @@ def parse_cmdline(directory, *commands):
212
# TODO number -> interval
213
global DEBUG_FLAG, PROGRAM
214
DEBUG_FLAG = False
215
+ interval = None
216
217
mods = []
218
for cmd in commands[1:]:
@@ -223,11 +224,17 @@ def parse_cmdline(directory, *commands):
224
elif os.path.isfile(directory + cmd + ".chart.py") or os.path.isfile(directory + cmd):
225
DEBUG_FLAG = True
226
mods.append(cmd.replace(".chart.py", ""))
227
+ else:
228
+ try:
229
+ interval = int(cmd)
230
+ except ValueError:
231
+ pass
232
233
PROGRAM = commands[0].split('/')[-1].split('.plugin')[0]
234
debug("started from", commands[0], "with options:", *commands[1:])
235
230
- return mods
236
+ return {'interval': interval,
237
+ 'modules': mods}
238
239
240
# if __name__ == '__main__':
@@ -282,7 +289,10 @@ def run():
289
modules_conf += "/"
290
291
# parse passed command line arguments
285
- modules = parse_cmdline(modules_dir, *sys.argv)
292
+ out = parse_cmdline(modules_dir, *sys.argv)
293
+ modules = out['modules']
294
+ if out['interval'] is not None:
295
+ interval = out['interval']
296
297
# run plugins
298
charts = PythonCharts(interval, modules, modules_dir, modules_conf)