mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Added ability to enable debug output with wrappers (#8830)
Now with optparse (python 2.3+) Does not include your doc updates @laf If I get some time later, I'll add them, feel free to as well. DO NOT DELETE THIS TEXT #### Please note > Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting. - [ ] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/) #### Testers If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
This commit is contained in:
committed by
Neil Lathwood
parent
69a6098d43
commit
a1aaafa6ff
@@ -30,6 +30,7 @@ try:
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from optparse import OptionParser
|
||||
|
||||
except:
|
||||
print "ERROR: missing one or more of the following python modules:"
|
||||
@@ -75,6 +76,7 @@ except:
|
||||
sys.exit(2)
|
||||
|
||||
poller_path = config['install_dir'] + '/poller.php'
|
||||
log_dir = config['log_dir']
|
||||
db_username = config['db_user']
|
||||
db_password = config['db_pass']
|
||||
db_port = int(config['db_port'])
|
||||
@@ -194,12 +196,17 @@ polled_devices = 0
|
||||
Take the amount of threads we want to run in parallel from the commandline
|
||||
if None are given or the argument was garbage, fall back to default of 16
|
||||
"""
|
||||
usage = "usage: %prog [options] <workers> (Default: 16 (Do not set too high)"
|
||||
description = "Spawn multiple poller.php processes in parallel."
|
||||
parser = OptionParser(usage=usage, description=description)
|
||||
parser.add_option('-d', '--debug', action='store_true', default=False,
|
||||
help="Enable debug output. WARNING: Leaving this enabled will consume a lot of disk space.")
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
debug = options.debug
|
||||
try:
|
||||
amount_of_workers = int(sys.argv[1])
|
||||
if amount_of_workers == 0:
|
||||
print "ERROR: 0 threads is not a valid value"
|
||||
sys.exit(2)
|
||||
except:
|
||||
amount_of_workers = int(args[0])
|
||||
except (IndexError, ValueError):
|
||||
amount_of_workers = 16
|
||||
|
||||
devices_list = []
|
||||
@@ -310,8 +317,11 @@ def poll_worker():
|
||||
# EOC5
|
||||
try:
|
||||
start_time = time.time()
|
||||
command = "/usr/bin/env php %s -h %s >> /dev/null 2>&1" % (poller_path, device_id)
|
||||
|
||||
output = "-d >> %s/poll_device_%s.log" % (log_dir, device_id) if debug else ">> /dev/null"
|
||||
command = "/usr/bin/env php %s -h %s %s 2>&1" % (poller_path, device_id, output)
|
||||
subprocess.check_call(command, shell=True)
|
||||
|
||||
elapsed_time = int(time.time() - start_time)
|
||||
print_queue.put([threading.current_thread().name, device_id, elapsed_time])
|
||||
except (KeyboardInterrupt, SystemExit):
|
||||
|
Reference in New Issue
Block a user