Пример #1
0
def _watcher_parser_v2(conf, logname):
    logger = get_logger(logname)
    result = []

    dps = {}
    for faucet_file in conf['faucet_configs']:
        dp_list = dp_parser(faucet_file, logname)
        for dp in dp_list:
            dps[dp.name] = dp

    dbs = conf.pop('dbs')

    for name, dictionary in conf['watchers'].iteritems():
        for dp_name in dictionary['dps']:
            if dp_name not in dps:
                errormsg = "dp: {0} metered but not configured".format(
                    dp_name
                    )
                logger.error(errormsg)
                continue

            dp = dps[dp_name]

            watcher = WatcherConf(name, dictionary)
            watcher.add_db(dbs[watcher.db])
            watcher.add_dp(dp)
            result.append(watcher)

    return result
Пример #2
0
def _watcher_parser_v1(config_file, logname):
    logger = get_logger(logname)
    result = []

    INFLUX_KEYS = [
        'influx_db',
        'influx_host',
        'influx_port',
        'influx_user',
        'influx_pwd',
        'influx_timeout',
    ]

    dps = []
    with open(config_file, 'r') as conf:
        for line in conf:
            dps.append(dp_parser(line.strip(), logname)[0])

    for dp in dps:
        if dp.influxdb_stats:
            w_type = 'port_state'
            port_state_conf = {'type': w_type, 'db_type': 'influx'}
            for key in INFLUX_KEYS:
                port_state_conf[key] = dp.__dict__.get(key, None)
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, port_state_conf)
            result.append(watcher)

        if dp.monitor_ports:
            w_type = 'port_stats'
            port_stats_conf = {'type': w_type}
            port_stats_conf['interval'] = dp.monitor_ports_interval
            if dp.influxdb_stats:
                port_stats_conf['db_type'] = 'influx'
                for key in INFLUX_KEYS:
                    port_stats_conf[key] = dp.__dict__.get(key, None)
            else:
                port_stats_conf['db_type'] = 'text'
                port_stats_conf['file'] = dp.monitor_ports_file
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, port_stats_conf)
            result.append(watcher)

        if dp.monitor_flow_table:
            w_type = 'flow_table'
            flow_table_conf = {'type': w_type}
            flow_table_conf['interval'] = dp.monitor_flow_table_interval
            flow_table_conf['file'] = dp.monitor_flow_table_file
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, flow_table_conf)
            result.append(watcher)

    return result
Пример #3
0
def _watcher_parser_v2(conf, logname):
    logger = get_logger(logname)
    result = []

    dps = {}
    for faucet_file in conf['faucet_configs']:
        _, dp_list = dp_parser(faucet_file, logname)
        for dp in dp_list:
            dps[dp.name] = dp

    dbs = conf.pop('dbs')

    for name, dictionary in conf['watchers'].iteritems():
        for dp_name in dictionary['dps']:
            if dp_name not in dps:
                errormsg = "dp: {0} metered but not configured".format(dp_name)
                logger.error(errormsg)
                continue

            dp = dps[dp_name]

            watcher = WatcherConf(name, dictionary)
            watcher.add_db(dbs[watcher.db])
            watcher.add_dp(dp)
            result.append(watcher)

    return result
Пример #4
0
def _watcher_parser_v2(conf, logname, prom_client):
    logger = config_parser_util.get_logger(logname)
    result = []

    dps = {}
    for faucet_file in conf['faucet_configs']:
        _, dp_list = dp_parser(faucet_file, logname)
        if dp_list:
            for dp in dp_list:
                dps[dp.name] = dp

    dbs = conf.pop('dbs')

    for name, dictionary in list(conf['watchers'].items()):
        for dp_name in dictionary['dps']:
            if dp_name not in dps:
                logger.error('dp %s metered but not configured', dp_name)
                continue
            dp = dps[dp_name]
            watcher = WatcherConf(name, dictionary, prom_client)
            watcher.add_db(dbs[watcher.db])
            watcher.add_dp(dp)
            result.append(watcher)

    return result
Пример #5
0
def _watcher_parser_v1(config_file, logname):
    result = []

    INFLUX_KEYS = [
        'influx_db',
        'influx_host',
        'influx_port',
        'influx_user',
        'influx_pwd',
        'influx_timeout',
    ]

    GAUGEDB_KEYS = [
        'gdb_type',
        'nosql_db',
        'db_username',
        'db_password',
        'db_ip',
        'db_fqdn',
        'db_port',
        'driver',
        'views',
        'switches_doc',
        'flows_doc',
    ]

    dps = []
    with open(config_file, 'r') as conf:
        for line in conf:
            dps.append(dp_parser(line.strip(), logname)[1][0])

    for dp in dps:
        if dp.influxdb_stats:
            w_type = 'port_state'
            port_state_conf = {'type': w_type, 'db_type': 'influx'}
            for key in INFLUX_KEYS:
                port_state_conf[key] = dp.__dict__.get(key, None)
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, port_state_conf)
            # add dp to watcher. prevents the dp_id attribute error in gauge.
            watcher.add_dp(dp)
            result.append(watcher)

        if dp.monitor_ports:
            w_type = 'port_stats'
            port_stats_conf = {'type': w_type}
            port_stats_conf['interval'] = dp.monitor_ports_interval
            if dp.influxdb_stats:
                port_stats_conf['db_type'] = 'influx'
                for key in INFLUX_KEYS:
                    port_stats_conf[key] = dp.__dict__.get(key, None)
            else:
                port_stats_conf['db_type'] = 'text'
                port_stats_conf['file'] = dp.monitor_ports_file
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, port_stats_conf)
            # add dp to watcher. prevents the dp_id attribute error in gauge.
            watcher.add_dp(dp)
            result.append(watcher)

        if dp.monitor_flow_table:
            w_type = 'flow_table'
            flow_table_conf = {'type': w_type}
            flow_table_conf['interval'] = dp.monitor_flow_table_interval
            flow_table_conf['file'] = dp.monitor_flow_table_file
            name = dp.name + '-' + w_type
            watcher = WatcherConf(name, flow_table_conf)
            # add dp to watcher. prevents the dp_id attribute error in gauge.
            watcher.add_dp(dp)
            result.append(watcher)

        if dp.gaugedb_updates:
            w_type = 'flow_table'
            flow_table_conf = {'type': w_type}
            flow_table_conf['db_type'] = 'gaugedb'
            flow_table_conf['interval'] = dp.monitor_flow_table_interval
            flow_table_conf['db_update_counter'] = dp.gaugedb_update_counter
            name = dp.name + '-' + w_type
            for key in GAUGEDB_KEYS:
                flow_table_conf[key] = dp.__dict__.get('gaugedb').get(
                    key, None)
            watcher = WatcherConf(name, flow_table_conf)
            watcher.add_dp(dp)
            result.append(watcher)

    return result