def run_long_running_ffwd()

in postgresql_metrics/metrics_logic.py [0:0]


def run_long_running_ffwd(conf):
    db_connections = get_db_connections_with_conf(conf)
    ffwd_address = (DEFAULT_FFWD_HOST, DEFAULT_FFWD_PORT)
    if conf and conf.get('ffwd'):
        ffwd_address = (conf['ffwd'].get('host', DEFAULT_FFWD_HOST),
                        int(conf['ffwd'].get('port', DEFAULT_FFWD_PORT)))
    try:
        LOG.info("starting a long running statistics polling loop with {} database(s)",
                 len(db_connections))
        while True:
            try:
                # Notice that the scheduling is separate from this few second sleep,
                # but as the granularity is in tens of seconds, few seconds interval is enough.
                time.sleep(5.0)
                db_connections = confirm_connections_work(conf, db_connections)
                metrics = get_all_metrics_scheduled(db_connections, conf)
                if metrics:
                    LOG.info("sending {} metrics to ffwd...", len(metrics))
                    push_to_ffwd(metrics, ffwd_address)
            except (KeyboardInterrupt, SystemExit):
                LOG.warn('*** keyboard interrupt / system exit ***')
                raise
            except Exception:
                LOG.exception('metrics check failed')
    finally:
        for db_connection in db_connections:
            if not db_connection.closed:
                db_connection.close()