X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fovs_stats.c;h=85269afef4065028f5356308905fcb45476a41bd;hb=a96c8f697e2e0b2376984957574e28e9d702d177;hp=9b958d83fd84295591172234a750064e22fd9fc6;hpb=2f238520a1917c007d30c1b87163d98a6e67bd8a;p=collectd.git diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 9b958d83..85269afe 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -232,10 +232,10 @@ static void ovs_stats_submit_two(const char *dev, const char *type, plugin_dispatch_values(&vl); } -static void ovs_stats_submit_interfaces(bridge_list_t *bridge, - port_list_t *port) { +static void ovs_stats_submit_interfaces(port_list_t *port) { char devname[PORT_NAME_SIZE_MAX * 2]; + bridge_list_t *bridge = port->br; for (interface_list_t *iface = port->iface; iface != NULL; iface = iface->next) { meta_data_t *meta = meta_data_create(); @@ -322,7 +322,7 @@ static int ovs_stats_get_port_stat_value(port_list_t *port, return value; } -static void ovs_stats_submit_port(bridge_list_t *bridge, port_list_t *port) { +static void ovs_stats_submit_port(port_list_t *port) { char devname[PORT_NAME_SIZE_MAX * 2]; meta_data_t *meta = meta_data_create(); @@ -348,6 +348,7 @@ static void ovs_stats_submit_port(bridge_list_t *bridge, port_list_t *port) { i++; } } + bridge_list_t *bridge = port->br; snprintf(devname, sizeof(devname), "%s.%s", bridge->name, port->name); ovs_stats_submit_one(devname, "if_collisions", NULL, ovs_stats_get_port_stat_value(port, collisions), meta); @@ -533,6 +534,19 @@ static bridge_list_t *ovs_stats_get_bridge(bridge_list_t *head, return NULL; } +/* Check if bridge is configured to be monitored in config file */ +static int ovs_stats_is_monitored_bridge(const char *br_name) { + /* if no bridges are configured, return true */ + if (g_monitored_bridge_list_head == NULL) + return 1; + + /* check if given bridge exists */ + if (ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name) != NULL) + return 1; + + return 0; +} + /* Delete bridge */ static int ovs_stats_del_bridge(yajl_val bridge) { const char *old[] = {"old", NULL}; @@ -585,6 +599,9 @@ static int ovs_stats_update_bridge(yajl_val bridge) { if (!br_name || !YAJL_IS_STRING(br_name)) return 0; + if (!ovs_stats_is_monitored_bridge(YAJL_GET_STRING(br_name))) + return 0; + bridge_list_t *br = ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name)); if (br == NULL) { @@ -873,20 +890,21 @@ static int ovs_stats_update_iface_stats(interface_list_t *iface, static int ovs_stats_update_iface_ext_ids(interface_list_t *iface, yajl_val ext_ids) { - if (ext_ids && YAJL_IS_ARRAY(ext_ids)) { - for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) { - yajl_val ext_id = YAJL_GET_ARRAY(ext_ids)->values[i]; - if (!YAJL_IS_ARRAY(ext_id)) - return -1; + if (!ext_ids || !YAJL_IS_ARRAY(ext_ids)) + return 0; - char *key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]); - char *value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]); - if (key && value) { - if (strncmp(key, "iface-id", strlen(key)) == 0) { - sstrncpy(iface->ex_iface_id, value, sizeof(iface->ex_iface_id)); - } else if (strncmp(key, "vm-uuid", strlen(key)) == 0) { - sstrncpy(iface->ex_vm_id, value, sizeof(iface->ex_vm_id)); - } + for (size_t i = 0; i < YAJL_GET_ARRAY(ext_ids)->len; i++) { + yajl_val ext_id = YAJL_GET_ARRAY(ext_ids)->values[i]; + if (!YAJL_IS_ARRAY(ext_id)) + return -1; + + char *key = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[0]); + char *value = YAJL_GET_STRING(YAJL_GET_ARRAY(ext_id)->values[1]); + if (key && value) { + if (strncmp(key, "iface-id", strlen(key)) == 0) { + sstrncpy(iface->ex_iface_id, value, sizeof(iface->ex_iface_id)); + } else if (strncmp(key, "vm-uuid", strlen(key)) == 0) { + sstrncpy(iface->ex_vm_id, value, sizeof(iface->ex_vm_id)); } } } @@ -1121,19 +1139,6 @@ static void ovs_stats_initialize(ovs_db_t *pdb) { OVS_DB_TABLE_CB_FLAG_DELETE); } -/* Check if bridge is configured to be monitored in config file */ -static int ovs_stats_is_monitored_bridge(const char *br_name) { - /* if no bridges are configured, return true */ - if (g_monitored_bridge_list_head == NULL) - return 1; - - /* check if given bridge exists */ - if (ovs_stats_get_bridge(g_monitored_bridge_list_head, br_name) != NULL) - return 1; - - return 0; -} - /* Delete all ports from port list */ static void ovs_stats_free_port_list(port_list_t *head) { for (port_list_t *i = head; i != NULL;) { @@ -1274,29 +1279,22 @@ static int ovs_stats_plugin_init(void) { /* OvS stats read callback. Read bridge/port information and submit it*/ static int ovs_stats_plugin_read(__attribute__((unused)) user_data_t *ud) { - bridge_list_t *bridge; - port_list_t *port; - pthread_mutex_lock(&g_stats_lock); - for (bridge = g_bridge_list_head; bridge != NULL; bridge = bridge->next) { - if (!ovs_stats_is_monitored_bridge(bridge->name)) + for (port_list_t *port = g_port_list_head; port != NULL; port = port->next) { + if (strlen(port->name) == 0) + /* Skip port w/o name. This is possible when read callback + * is called after Interface Table update callback but before + * Port table Update callback. Will add this port on next read */ continue; - for (port = g_port_list_head; port != NULL; port = port->next) { - if (port->br != bridge) - continue; - - if (strlen(port->name) == 0) - /* Skip port w/o name. This is possible when read callback - * is called after Interface Table update callback but before - * Port table Update callback. Will add this port on next read */ - continue; + /* Skip port if it has no bridge */ + if (!port->br) + continue; - ovs_stats_submit_port(bridge, port); + ovs_stats_submit_port(port); - if (interface_stats) - ovs_stats_submit_interfaces(bridge, port); - } + if (interface_stats) + ovs_stats_submit_interfaces(port); } pthread_mutex_unlock(&g_stats_lock); return 0;