class DiamondThread(threading.Thread): def __init__(self, config): threading.Thread.__init__(self) self.server = Server(config) def run(self): self.server.run() def stop(self): self.server.stop() self.server.scheduler.stop()
def test_BaseCollectorEnabled(self): config = configobj.ConfigObj() config['server'] = {} config['server']['collectors_config_path'] = '' config['collectors'] = {} config['collectors']['BaseCollector'] = { 'enabled': 'True', } config['collectors']['CPUCollector'] = { 'enabled': 'False', } config['collectors']['DiskSpaceCollector'] = { 'enabled': 'True', } config['collectors']['DiskUsageCollector'] = { 'enabled': 'True', } config['collectors']['LoadAverageCollector'] = { 'enabled': 'True', } config['collectors']['MemoryCollector'] = { 'enabled': 'True', } config['collectors']['VMStatCollector'] = { 'enabled': 'True', } config['collectors']['NetworkCollector'] = { 'enabled': 'True', } server = Server(None) server.manage_base_collectors(config) self.assertEqual(len(config['collectors']), 8) self.assertEqual(config['collectors']['BaseCollector']['enabled'], 'True') self.assertEqual(config['collectors']['CPUCollector']['enabled'], 'False') self.assertEqual(config['collectors']['DiskSpaceCollector']['enabled'], 'False') self.assertEqual(config['collectors']['DiskUsageCollector']['enabled'], 'False') self.assertEqual(config['collectors']['LoadAverageCollector']['enabled'], 'False') self.assertEqual(config['collectors']['MemoryCollector']['enabled'], 'False') self.assertEqual(config['collectors']['VMStatCollector']['enabled'], 'False') self.assertEqual(config['collectors']['NetworkCollector']['enabled'], 'False')
# Finish Initialize PID file if not options.foreground and not options.collector: # Write pid file pid = str(os.getpid()) try: pf = file(options.pidfile, 'w+') except IOError, e: log.error("Failed to write child PID file: %s" % (e)) sys.exit(1) pf.write("%s\n" % pid) pf.close() # Log log.debug("Wrote child PID file: %s" % (options.pidfile)) # Initialize Server server = Server(config) def sigint_handler(signum, frame): # Log log.debug("Signal Received: %d" % (signum)) # Stop Server server.stop() # Delete Pidfile if not options.skip_pidfile and os.path.exists(options.pidfile): os.remove(options.pidfile) # Log log.debug("Removed PID file: %s" % (options.pidfile)) # Set the signal handlers signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGTERM, sigint_handler)
def __init__(self, config): threading.Thread.__init__(self) self.server = Server(config)
# Finish Initialize PID file if not options.foreground and not options.collector: # Write pid file pid = str(os.getpid()) try: pf = file(options.pidfile, 'w+') except IOError, e: log.error("Failed to write child PID file: %s" % (e)) sys.exit(1) pf.write("%s\n" % pid) pf.close() # Log log.debug("Wrote child PID file: %s" % (options.pidfile)) # Initialize Server server = Server(configfile=options.configfile) def sigint_handler(signum, frame): log.info("Signal Received: %d" % (signum)) # Delete Pidfile if not options.skip_pidfile and os.path.exists(options.pidfile): os.remove(options.pidfile) # Log log.debug("Removed PID file: %s" % (options.pidfile)) for child in multiprocessing.active_children(): child.terminate() sys.exit(0) # Set the signal handlers signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGTERM, sigint_handler)