some more cleanup around pool management.
TODO: Make pool handling smarter, handle keyboardinterrupt
This commit is contained in:
parent
669cbe6a57
commit
3cba33964c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.pyc
|
@ -11,8 +11,7 @@ import struct
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
LOGGING_FORMAT = "%(asctime)s : %(levelname)s : %(message)s"
|
LOGGING_FORMAT = "%(asctime)s:%(levelname)s:%(message)s"
|
||||||
HOSTLIST = ["localhost", "127.0.0.1"]
|
|
||||||
RE_LEFTRIGHT = re.compile(r"^(?P<left>\S+)\s+(?P<right>\S+)$")
|
RE_LEFTRIGHT = re.compile(r"^(?P<left>\S+)\s+(?P<right>\S+)$")
|
||||||
|
|
||||||
|
|
||||||
@ -162,17 +161,20 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(description="Send Munin statistics to Graphite.")
|
parser = argparse.ArgumentParser(description="Send Munin statistics to Graphite.")
|
||||||
parser.add_argument("--carbon",
|
parser.add_argument("--carbon",
|
||||||
action="store",
|
action="store",
|
||||||
help="Carbon hostport (ex: localhost:2003).")
|
help="Carbon host and Pickle port (ex: localhost:2004).")
|
||||||
parser.add_argument("-n", "--noop",
|
parser.add_argument("--muninhosts",
|
||||||
|
action="store",
|
||||||
|
help="Comma separated list of hosts running Munin to query for stats.")
|
||||||
|
parser.add_argument("--noop",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Don't actually send Munin data to Carbon.")
|
help="Don't actually send Munin data to Carbon.")
|
||||||
parser.add_argument("-v", "--verbose",
|
parser.add_argument("--poolsize", type=int, default=1,
|
||||||
|
help="Pool size of simultaneous connections when polling multiple hosts.")
|
||||||
|
parser.add_argument("--verbose",
|
||||||
choices=[1, 2, 3],
|
choices=[1, 2, 3],
|
||||||
default=2,
|
default=2,
|
||||||
type=int,
|
type=int,
|
||||||
help="Verbosity level. 1:ERROR, 2:INFO/Default, 3:DEBUG.")
|
help="Verbosity level. 1:ERROR, 2:INFO/Default, 3:DEBUG.")
|
||||||
parser.add_argument("--poolsize", type=int, default=1,
|
|
||||||
help="Pool size of simultaneous connections for polling.")
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
@ -186,7 +188,7 @@ def worker_return(retval):
|
|||||||
"""Outputs any return values from each pool iteration."""
|
"""Outputs any return values from each pool iteration."""
|
||||||
logging.debug("Iteration Return Value: %s", retval)
|
logging.debug("Iteration Return Value: %s", retval)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
if args.verbose == 1:
|
if args.verbose == 1:
|
||||||
LOGGING_LEVEL = logging.ERROR
|
LOGGING_LEVEL = logging.ERROR
|
||||||
@ -197,8 +199,11 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
logging.basicConfig(format=LOGGING_FORMAT, level=LOGGING_LEVEL)
|
logging.basicConfig(format=LOGGING_FORMAT, level=LOGGING_LEVEL)
|
||||||
pool = multiprocessing.Pool(args.poolsize)
|
pool = multiprocessing.Pool(args.poolsize)
|
||||||
for host in HOSTLIST:
|
muninhosts = args.muninhosts.split(",")
|
||||||
logging.debug("Adding host %s to the pool.", host)
|
for muninhost in muninhosts:
|
||||||
pool.apply_async(worker_bootstrap, args = (host, args,), callback = worker_return)
|
pool.apply_async(worker_bootstrap, args = (muninhost, args,), callback = worker_return)
|
||||||
pool.close()
|
pool.close()
|
||||||
pool.join()
|
pool.join()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user