def dashboard_collector_worker(app): logger.debug("Starting to collect dashboard data") data = metrics.get_metrics(app) # We don't want to store notifications in the history. data.pop('notifications', None) q = Queue(os.path.join(app.config.temboard.home, 'dashboard.q'), max_length=(app.config.dashboard.history_length + 1), overflow_mode='slide') q.push(Message(content=json.dumps(data))) logger.debug(data) logger.debug("End")
def push(self, config, notification): try: # Notifications are stored in a "sliding" queue. q = Queue(file_path='%s/notifications.q' % ( config.temboard['home']), max_size=10 * 1024 * 1024, # 10MB overflow_mode='slide') # Push the notification in the queue. q.push(Message(content=json.dumps({ 'date': notification.date, 'username': notification.username, 'message': notification.message}))) except (Exception) as e: raise NotificationError('Can not push new notification: %s' % e.message)
def delta(self, key, current_values): """ Compute a delta between measures of two runs. Args: key (str): identify the values current_values (dict): mapping of latest measures Returns: a tuple of the time interval of the delta in seconds and a dict a delta with the same keys as the input. """ current_time = time.time() store_key = self.get_name() + key last_measure = self.get_last_measure(store_key) delta = (None, None) delta_value = None # Compute deltas and update last_* variables try: if last_measure: delta_time = current_time - last_measure['measure_time'] delta_values = {} for k in current_values.keys(): delta_value = current_values[k] - \ last_measure['measure'][k] if delta_value < 0: raise Exception('Negative delta value.') delta_values[k] = delta_value delta = (delta_time, delta_values) except Exception as e: delta = (None, None) try: q = Queue("%s/%s.q" % (self.home, store_key), max_length=1, overflow_mode='slide') q.push( Message(content=json.dumps({ 'measure_time': current_time, 'measure': dict(current_values) }))) except Exception as e: logger.error(str(e)) return delta
def dashboard_collector_worker(config): try: signal.signal(signal.SIGTERM, dashboard_worker_sigterm_handler) logger.debug("Collecting data") conn = connector( host=config['postgresql']['host'], port=config['postgresql']['port'], user=config['postgresql']['user'], password=config['postgresql']['password'], database=config['postgresql']['dbname'] ) conn.connect() # convert config dict to namedtuple config_nt = collections.namedtuple( '__config', ['temboard', 'plugins', 'postgresql', 'logging'] )( temboard=config['temboard'], plugins=config['plugins'], postgresql=config['postgresql'], logging=config['logging'] ) # Collect data data = metrics.get_metrics(conn, config_nt) conn.close() # We don't want to store notifications in the history. data.pop('notifications', None) q = Queue('%s/dashboard.q' % (config['temboard']['home']), max_length=(config['plugins']['dashboard']['history_length'] +1), overflow_mode='slide' ) q.push(Message(content=json.dumps(data))) logger.debug(data) logger.debug("End") except (error, Exception) as e: logger.error("Could not collect data") logger.exception(e) try: conn.close() except Exception: pass sys.exit(1)
def dashboard_collector_worker(commands, command, config): try: signal.signal(signal.SIGTERM, dashboard_worker_sigterm_handler) start_time = time.time() * 1000 set_logger_name("dashboard_collector") logger = get_logger(config) logger.debug("Starting with pid=%s" % (getpid())) logger.debug("commandid=%s" % (command.commandid)) command.state = COMMAND_START command.time = time.time() command.pid = getpid() commands.update(command) conn = connector(host=config.postgresql['host'], port=config.postgresql['port'], user=config.postgresql['user'], password=config.postgresql['password'], database=config.postgresql['dbname']) conn.connect() db_metrics = metrics.get_metrics(conn, config) # We don't want to store notifications in the history. db_metrics.pop('notifications', None) conn.close() q = Queue('%s/dashboard.q' % (config.temboard['home']), max_length=(config.plugins['dashboard']['history_length'] + 1), overflow_mode='slide') q.push(Message(content=json.dumps(db_metrics))) logger.debug("Duration: %s." % (str(time.time() * 1000 - start_time))) logger.debug("Done.") except (error, Exception) as e: logger.traceback(get_tb()) logger.error(str(e)) logger.debug("Failed.") try: conn.close() except Exception: pass sys.exit(1)
def monitoring_collector_worker(app): """ Run probes and push collected metrics in a queue. """ logger.debug("Starting monitoring collector") config = app.config conninfo = dict( host=config.postgresql.host, port=config.postgresql.port, user=config.postgresql.user, database=config.postgresql.dbname, password=config.postgresql.password, dbnames=config.monitoring.dbnames, instance=config.postgresql.instance, ) system_info = host_info(config.temboard.hostname) # Load the probes to run probes = load_probes(config.monitoring, config.temboard.home) instance = instance_info(conninfo, system_info['hostname']) logger.debug("Running probes") # Gather the data from probes data = run_probes(probes, [instance]) # Prepare and send output output = dict( datetime=now(), hostinfo=system_info, instances=remove_passwords([instance]), data=data, version=__VERSION__, ) logger.debug(output) q = Queue(os.path.join(config.temboard.home, 'metrics.q'), max_size=1024 * 1024 * 10, overflow_mode='slide') q.push(Message(content=json.dumps(output))) logger.debug("Done")
def supervision_collector_worker(commands, command, config): """ Run probes and push collected metrics in a queue. """ signal.signal(signal.SIGTERM, supervision_worker_sigterm_handler) start_time = time.time() * 1000 set_logger_name("supervision_collector_worker") logger = get_logger(config) # TODO: logging methods in supervision plugin must be aligned. logging.root = logger logger.info("Start pid=%s id=%s" % ( os.getpid(), command.commandid, )) command.state = COMMAND_START command.time = time.time() command.pid = os.getpid() commands.update(command) try: system_info = host_info(config.plugins['supervision']) except ValueError as e: logger.error( "supervision_collector_worker - unable to get system information: %s\n" % str(e)) sys.exit(1) # Load the probes to run probes = load_probes(config.plugins['supervision'], config.temboard['home']) config.plugins['supervision']['conninfo'] = [{ 'host': config.postgresql['host'], 'port': config.postgresql['port'], 'user': config.postgresql['user'], 'database': config.postgresql['dbname'], 'password': config.postgresql['password'], 'dbnames': config.plugins['supervision']['dbnames'], 'instance': config.postgresql['instance'] }] # Validate connection information from the config, and ensure # the instance is available instances = [] for conninfo in config.plugins['supervision']['conninfo']: logging.debug("Validate connection information on instance \"%s\"", conninfo['instance']) instances.append(instance_info(conninfo, system_info['hostname'])) # Gather the data from probes data = run_probes(probes, system_info['hostname'], instances) # Prepare and send output output = { 'datetime': now(), 'hostinfo': system_info, 'instances': remove_passwords(instances), 'data': data, 'version': __VERSION__ } q = Queue('%s/metrics.q' % (config.temboard['home']), max_size=1024 * 1024 * 10, overflow_mode='slide') q.push(Message(content=json.dumps(output))) logger.info("End. Duration: %s." % (str(time.time() * 1000 - start_time)))
def monitoring_collector_worker(config): """ Run probes and push collected metrics in a queue. """ signal.signal(signal.SIGTERM, monitoring_worker_sigterm_handler) # convert config dict to namedtuple config = collections.namedtuple( '__config', ['temboard', 'plugins', 'postgresql', 'logging'])( temboard=config['temboard'], plugins=config['plugins'], postgresql=config['postgresql'], logging=config['logging']) logger.debug("Starting collector") try: system_info = host_info(config.temboard['hostname']) except (ValueError, Exception) as e: logger.exception(e) logger.debug("Failed") sys.exit(1) # Load the probes to run try: probes = load_probes(config.plugins['monitoring'], config.temboard['home']) config.plugins['monitoring']['conninfo'] = [{ 'host': config.postgresql['host'], 'port': config.postgresql['port'], 'user': config.postgresql['user'], 'database': config.postgresql['dbname'], 'password': config.postgresql['password'], 'dbnames': config.plugins['monitoring']['dbnames'], 'instance': config.postgresql['instance'] }] # Validate connection information from the config, and ensure # the instance is available instances = [] for conninfo in config.plugins['monitoring']['conninfo']: instances.append(instance_info(conninfo, system_info['hostname'])) logger.debug("Running probes") # Gather the data from probes data = run_probes(probes, instances) # Prepare and send output output = { 'datetime': now(), 'hostinfo': system_info, 'instances': remove_passwords(instances), 'data': data, 'version': __VERSION__ } logger.debug(output) q = Queue('%s/metrics.q' % (config.temboard['home']), max_size=1024 * 1024 * 10, overflow_mode='slide') q.push(Message(content=json.dumps(output))) logger.debug("Done") except Exception as e: logger.exception(e) logger.error("Could not collect data") sys.exit(1)