Exemplo n.º 1
0
def get_discover(http_context, app, sessions):
    logger.info('Starting discovery.')
    try:
        sysinfo = SysInfo()
        with app.postgres.connect() as conn:
            pginfo = PgInfo(conn)
            ret = dict(hostname=sysinfo.hostname(
                app.config.temboard['hostname']),
                       cpu=sysinfo.n_cpu(),
                       memory_size=sysinfo.memory_size(),
                       pg_port=pginfo.setting('port'),
                       pg_version=pginfo.version()['full'],
                       pg_version_summary=pginfo.version()['summary'],
                       pg_data=pginfo.setting('data_directory'),
                       plugins=[
                           plugin_name
                           for plugin_name in app.config.temboard['plugins']
                       ])
        logger.info('Discovery done.')
        return ret

    except (error, Exception, HTTPError) as e:
        logger.exception(e)
        logger.info('Discovery failed.')
        if isinstance(e, HTTPError):
            raise e
        else:
            raise HTTPError(500, "Internal error.")
Exemplo n.º 2
0
def api_run_probe(probe_instance, config):
    """
    Run a probe instance.
    """
    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 = []
    sysinfo = SysInfo()
    hostname = sysinfo.hostname(config.temboard['hostname'])
    for conninfo in config.plugins['monitoring']['conninfo']:
        logging.debug("Validate connection information on instance \"%s\"",
                      conninfo['instance'])
        instances.append(instance_info(conninfo, hostname))

    # Set home path
    probe_instance.set_home(config.temboard['home'])
    # Gather the data from probes
    data = run_probes([probe_instance], instances, delta=False)
    return data
Exemplo n.º 3
0
def get_metrics(conn, config, _=None):
    dm = DashboardMetrics(conn)
    sysinfo = SysInfo()
    pginfo = PgInfo(conn)

    cpu_models = [cpu['model_name'] for cpu in sysinfo.cpu_info()['cpus']]
    cpu_models_counter = {}
    for elem in cpu_models:
        cpu_models_counter[elem] = cpu_models_counter.get(elem, 0) + 1

    return {
        'buffers': dm.get_buffers(),
        'hitratio': dm.get_hitratio(),
        'active_backends': dm.get_active_backends(),
        'max_connections': dm.get_max_connections(),
        'cpu': dm.get_cpu_usage(),
        'loadaverage': dm.get_load_average(),
        'memory': dm.get_memory_usage(),
        'hostname': sysinfo.hostname(config.temboard['hostname']),
        'os_version': sysinfo.os_release,
        'linux_distribution': sysinfo.linux_distribution(),
        'cpu_models': cpu_models_counter,
        'databases': dm.get_stat_db(),
        'pg_uptime': dm.get_pg_uptime(),
        'n_cpu': sysinfo.n_cpu(),
        'pg_version': pginfo.version()['full'],
        'pg_data': pginfo.setting('data_directory'),
        'pg_port': pginfo.setting('port'),
        'notifications': dm.get_notifications(config)
    }
Exemplo n.º 4
0
def get_metrics(conn, config):
    dm = DashboardMetrics(conn)
    sysinfo = SysInfo()
    pginfo = PgInfo(conn)

    cpu_models = [cpu['model_name'] for cpu in sysinfo.cpu_info()['cpus']]
    cpu_models_counter = {}
    for elem in cpu_models:
        cpu_models_counter[elem] = cpu_models_counter.get(elem, 0) + 1

    return dict(
        buffers=dm.get_buffers(),
        hitratio=dm.get_hitratio(),
        active_backends=dm.get_active_backends(),
        max_connections=dm.get_max_connections(),
        cpu=dm.get_cpu_usage(),
        loadaverage=dm.get_load_average(),
        memory=dm.get_memory_usage(),
        hostname=sysinfo.hostname(config.temboard.hostname),
        os_version=sysinfo.os_release,
        linux_distribution=sysinfo.linux_distribution(),
        cpu_models=cpu_models_counter,
        databases=dm.get_stat_db(),
        pg_uptime=dm.get_pg_uptime(),
        n_cpu=sysinfo.n_cpu(),
        pg_version=pginfo.version()['full'],
        pg_data=pginfo.setting('data_directory'),
        pg_port=pginfo.setting('port'),
        notifications=dm.get_notifications(config),
    )
Exemplo n.º 5
0
def get_discover(http_context, app, sessions):
    logger.info('Starting discovery.')

    # Optionnal validation of key. For compatibility, we accept unauthenticated
    # /discover. But for better reliability, we validate a key sent by HTTP
    # header. temboard-agent-register sends key to prevent configuration
    # mismatch.
    request_key = http_context['headers'].get('X-Temboard-Agent-Key')
    if request_key and request_key != app.config.temboard['key']:
        raise HTTPError(401, "Invalid key")

    discover = dict(
        hostname=None,
        cpu=None,
        memory_size=None,
        pg_port=app.config.postgresql['port'],
        pg_version=None,
        pg_version_summary=None,
        pg_data=None,
        plugins=[plugin for plugin in app.config.temboard['plugins']],
    )

    try:
        # Gather system informations
        sysinfo = SysInfo()
        hostname = sysinfo.hostname(app.config.temboard['hostname'])
        cpu = sysinfo.n_cpu()
        memory_size = sysinfo.memory_size()

    except (Exception, HTTPError) as e:
        logger.exception(str(e))
        logger.error('System discovery failed.')
        # We stop here if system information has not been collected
        if isinstance(e, HTTPError):
            raise e
        else:
            raise HTTPError(500, "Internal error.")

    discover.update(hostname=hostname, cpu=cpu, memory_size=memory_size)

    try:
        with app.postgres.connect() as conn:
            pginfo = PgInfo(conn)
            discover.update(pg_block_size=int(pginfo.setting('block_size')),
                            pg_version=pginfo.version()['full'],
                            pg_version_summary=pginfo.version()['summary'],
                            pg_data=pginfo.setting('data_directory'))

    except Exception as e:
        logger.exception(str(e))
        logger.error('Postgres discovery failed.')
        # Do not raise HTTPError, just keeping null values for Postgres
        # informations.

    logger.info('Discovery done.')
    logger.debug(discover)
    return discover
Exemplo n.º 6
0
def get_info(conn, config):
    dm = DashboardMetrics(conn)
    sysinfo = SysInfo()
    pginfo = PgInfo(conn)
    return dict(
        hostname=sysinfo.hostname(config.temboard.hostname),
        os_version=' '.join([sysinfo.os, sysinfo.os_release]),
        pg_uptime=dm.get_pg_uptime(),
        pg_version=pginfo.version()['full'],
        pg_data=pginfo.setting('data_directory'),
        pg_port=pginfo.setting('port'),
    )
Exemplo n.º 7
0
def get_discover(http_context, app, sessions):
    logger.info('Starting discovery.')

    discover = dict(
        hostname=None,
        cpu=None,
        memory_size=None,
        pg_port=app.config.postgresql['port'],
        pg_version=None,
        pg_version_summary=None,
        pg_data=None,
        plugins=[plugin for plugin in app.config.temboard['plugins']],
    )

    try:
        # Gather system informations
        sysinfo = SysInfo()
        hostname = sysinfo.hostname(app.config.temboard['hostname'])
        cpu = sysinfo.n_cpu()
        memory_size = sysinfo.memory_size()

    except (Exception, HTTPError) as e:
        logger.exception(str(e))
        logger.error('System discovery failed.')
        # We stop here if system information has not been collected
        if isinstance(e, HTTPError):
            raise e
        else:
            raise HTTPError(500, "Internal error.")

    discover.update(
        hostname=hostname, cpu=cpu, memory_size=memory_size
    )

    try:
        with app.postgres.connect() as conn:
            pginfo = PgInfo(conn)
            discover.update(
                pg_block_size=int(pginfo.setting('block_size')),
                pg_version=pginfo.version()['full'],
                pg_version_summary=pginfo.version()['summary'],
                pg_data=pginfo.setting('data_directory')
            )

    except Exception as e:
        logger.exception(str(e))
        logger.error('Postgres discovery failed.')
        # Do not raise HTTPError, just keeping null values for Postgres
        # informations.

    logger.info('Discovery done.')
    logger.debug(discover)
    return discover
Exemplo n.º 8
0
def get_info(conn, config, _):
    dm = DashboardMetrics(conn)
    sysinfo = SysInfo()
    pginfo = PgInfo(conn)
    return {
        'hostname': sysinfo.hostname(config.temboard['hostname']),
        'os_version': "%s %s" % (sysinfo.os, sysinfo.os_release),
        'pg_uptime': dm.get_pg_uptime(),
        'pg_version': pginfo.version()['full'],
        'pg_data': pginfo.setting('data_directory'),
        'pg_port': pginfo.setting('port'),
    }
Exemplo n.º 9
0
def get_metrics(app):
    res = dict()
    try:
        with app.postgres.connect() as conn:
            dm = DashboardMetrics(conn)
            pginfo = PgInfo(conn)
            res.update(
                dict(
                    buffers=dm.get_buffers(),
                    hitratio=dm.get_hitratio(),
                    active_backends=dm.get_active_backends(),
                    max_connections=dm.get_max_connections(),
                    databases=dm.get_stat_db(),
                    pg_uptime=dm.get_pg_uptime(),
                    pg_version=pginfo.version()['full'],
                    pg_data=pginfo.setting('data_directory'),
                    pg_port=pginfo.setting('port'),
                ))
    except UserError:
        pass

    dm = DashboardMetrics()
    res.update(
        dict(
            cpu=dm.get_cpu_usage(),
            loadaverage=dm.get_load_average(),
            memory=dm.get_memory_usage(),
            notifications=dm.get_notifications(app.config),
        ))

    sysinfo = SysInfo()

    cpu_models = [cpu['model_name'] for cpu in sysinfo.cpu_info()['cpus']]
    cpu_models_counter = {}
    for elem in cpu_models:
        cpu_models_counter[elem] = cpu_models_counter.get(elem, 0) + 1

    res.update(
        dict(hostname=sysinfo.hostname(app.config.temboard.hostname),
             os_version=sysinfo.os_release,
             linux_distribution=sysinfo.linux_distribution(),
             cpu_models=cpu_models_counter,
             n_cpu=sysinfo.n_cpu(),
             timestamp=time.time()))
    return res
Exemplo n.º 10
0
def host_info(hostname_cfg):
    """Gather system information."""
    sinfo = SysInfo()
    _, _, _, _, arch = sinfo.uname()
    hostname = sinfo.hostname(hostname_cfg)

    hostinfo = {
        "hostname": hostname,
        "os": sinfo.os,
        "os_version": sinfo.os_release,
        "cpu_arch": arch
    }
    hostinfo.update(sinfo.cpu_info())
    hostinfo['memory_size'] = sinfo.mem_info()['MemTotal']
    hostinfo['ip_addresses'] = sinfo.ip_addresses()
    hostinfo['filesystems'] = sinfo.file_systems()
    hostinfo['os_flavor'] = sinfo.os_flavor()
    return hostinfo
Exemplo n.º 11
0
def api_run_probe(probe_instance, config):
    """
    Run a probe instance.
    """
    # Validate connection information from the config, and ensure
    # the instance is available
    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,
    )
    sysinfo = SysInfo()
    hostname = sysinfo.hostname(config.temboard.hostname)
    instance = instance_info(conninfo, hostname)
    # Set home path
    probe_instance.set_home(config.temboard.home)
    # Gather the data from probes
    return run_probes([probe_instance], [instance], delta=False)
Exemplo n.º 12
0
def api_run_probe(probe_instance, config):
    """
    Run a probe instance.
    """
    set_logger_name("supervision")
    logger = get_logger(config)
    # TODO: logging methods in supervision_agent code and supervision_agent should be aligned.
    logging.root = logger
    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 = []
    sysinfo = SysInfo()
    hostname = sysinfo.hostname(config.temboard['hostname'])
    for conninfo in config.plugins['supervision']['conninfo']:
        logging.debug("Validate connection information on instance \"%s\"",
                      conninfo['instance'])
        instances.append(instance_info(conninfo, hostname))

    # Gather the data from probes
    data = run_probes([probe_instance], instances, delta=False)
    return data
Exemplo n.º 13
0
def get_discover(http_context, config=None, sessions=None):
    conn = connector(host=config.postgresql['host'],
                     port=config.postgresql['port'],
                     user=config.postgresql['user'],
                     password=config.postgresql['password'],
                     database=config.postgresql['dbname'])
    logger.info('Starting discovery.')
    try:
        conn.connect()
        sysinfo = SysInfo()
        pginfo = PgInfo(conn)
        ret = {
            'hostname': sysinfo.hostname(config.temboard['hostname']),
            'cpu': sysinfo.n_cpu(),
            'memory_size': sysinfo.memory_size(),
            'pg_port': pginfo.setting('port'),
            'pg_version': pginfo.version()['full'],
            'pg_data': pginfo.setting('data_directory'),
            'plugins':
            [plugin_name for plugin_name in config.temboard['plugins']]
        }
        conn.close()
        logger.info('Discovery done.')
        return ret

    except (error, Exception, HTTPError) as e:
        logger.exception(str(e))
        logger.info('Discovery failed.')
        try:
            conn.close()
        except Exception:
            pass
        if isinstance(e, HTTPError):
            raise e
        else:
            raise HTTPError(500, "Internal error.")
Exemplo n.º 14
0
def get_hostname(config):
    sysinfo = SysInfo()
    return dict(hostname=sysinfo.hostname(config.temboard.hostname))
Exemplo n.º 15
0
def get_hostname(config, _):
    sysinfo = SysInfo()
    return {'hostname': sysinfo.hostname(config.temboard['hostname'])}