X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fovs_stats.c;h=c8efdaddab29649b597b4de3da4f570d074ec108;hb=b478f85d30f17cdb7c40bff2bb50d0f721d3b6fd;hp=28e46d917dbe5bcbc693137876babceb9f8b6b87;hpb=a2895f1b676a8d18250f90e989766a0391409cd0;p=collectd.git diff --git a/src/ovs_stats.c b/src/ovs_stats.c index 28e46d91..c8efdadd 100644 --- a/src/ovs_stats.c +++ b/src/ovs_stats.c @@ -63,6 +63,7 @@ typedef enum iface_counter { tx_512_to_1023_packets, tx_1024_to_1522_packets, tx_1523_to_max_packets, + rx_multicast_packets, tx_multicast_packets, rx_broadcast_packets, tx_broadcast_packets, @@ -70,6 +71,21 @@ typedef enum iface_counter { rx_oversize_errors, rx_fragmented_errors, rx_jabber_errors, + rx_error_bytes, + rx_l3_l4_xsum_error, + rx_management_dropped, + rx_mbuf_allocation_errors, + rx_total_bytes, + rx_total_missed_packets, + rx_undersize_errors, + rx_management_packets, + tx_management_packets, + rx_good_bytes, + tx_good_bytes, + rx_good_packets, + tx_good_packets, + rx_total_packets, + tx_total_packets, __iface_counter_max } iface_counter; @@ -129,6 +145,7 @@ static const char *const iface_counter_table[IFACE_COUNTER_COUNT] = { cnt_str(tx_512_to_1023_packets), cnt_str(tx_1024_to_1522_packets), cnt_str(tx_1523_to_max_packets), + cnt_str(rx_multicast_packets), cnt_str(tx_multicast_packets), cnt_str(rx_broadcast_packets), cnt_str(tx_broadcast_packets), @@ -136,6 +153,21 @@ static const char *const iface_counter_table[IFACE_COUNTER_COUNT] = { cnt_str(rx_oversize_errors), cnt_str(rx_fragmented_errors), cnt_str(rx_jabber_errors), + cnt_str(rx_error_bytes), + cnt_str(rx_l3_l4_xsum_error), + cnt_str(rx_management_dropped), + cnt_str(rx_mbuf_allocation_errors), + cnt_str(rx_total_bytes), + cnt_str(rx_total_missed_packets), + cnt_str(rx_undersize_errors), + cnt_str(rx_management_packets), + cnt_str(tx_management_packets), + cnt_str(rx_good_bytes), + cnt_str(tx_good_bytes), + cnt_str(rx_good_packets), + cnt_str(tx_good_packets), + cnt_str(rx_total_packets), + cnt_str(tx_total_packets), }; #undef cnt_str @@ -232,10 +264,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(); @@ -292,8 +324,6 @@ static void ovs_stats_submit_interfaces(bridge_list_t *bridge, ovs_stats_submit_two(devname, "if_packets", "broadcast_packets", iface->stats[rx_broadcast_packets], iface->stats[tx_broadcast_packets], meta); - ovs_stats_submit_one(devname, "if_multicast", "tx_multicast_packets", - iface->stats[tx_multicast_packets], meta); ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersized_errors", iface->stats[rx_undersized_errors], meta); ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors", @@ -302,6 +332,35 @@ static void ovs_stats_submit_interfaces(bridge_list_t *bridge, iface->stats[rx_fragmented_errors], meta); ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors", iface->stats[rx_jabber_errors], meta); + ovs_stats_submit_one(devname, "if_rx_octets", "rx_error_bytes", + iface->stats[rx_error_bytes], meta); + ovs_stats_submit_one(devname, "if_errors", "rx_l3_l4_xsum_error", + iface->stats[rx_l3_l4_xsum_error], meta); + ovs_stats_submit_one(devname, "if_dropped", "rx_management_dropped", + iface->stats[rx_management_dropped], meta); + ovs_stats_submit_one(devname, "if_errors", "rx_mbuf_allocation_errors", + iface->stats[rx_mbuf_allocation_errors], meta); + ovs_stats_submit_one(devname, "if_octets", "rx_total_bytes", + iface->stats[rx_total_bytes], meta); + ovs_stats_submit_one(devname, "if_packets", "rx_total_missed_packets", + iface->stats[rx_total_missed_packets], meta); + ovs_stats_submit_one(devname, "if_rx_errors", "rx_undersize_errors", + iface->stats[rx_undersize_errors], meta); + ovs_stats_submit_two(devname, "if_packets", "management_packets", + iface->stats[rx_management_packets], + iface->stats[tx_management_packets], meta); + ovs_stats_submit_two(devname, "if_packets", "multicast_packets", + iface->stats[rx_multicast_packets], + iface->stats[tx_multicast_packets], meta); + ovs_stats_submit_two(devname, "if_octets", "good_bytes", + iface->stats[rx_good_bytes], + iface->stats[tx_good_bytes], meta); + ovs_stats_submit_two(devname, "if_packets", "good_packets", + iface->stats[rx_good_packets], + iface->stats[tx_good_packets], meta); + ovs_stats_submit_two(devname, "if_packets", "total_packets", + iface->stats[rx_total_packets], + iface->stats[tx_total_packets], meta); meta_data_destroy(meta); } @@ -322,7 +381,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 +407,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); @@ -403,9 +463,6 @@ static void ovs_stats_submit_port(bridge_list_t *bridge, port_list_t *port) { ovs_stats_get_port_stat_value(port, rx_broadcast_packets), ovs_stats_get_port_stat_value(port, tx_broadcast_packets), meta); ovs_stats_submit_one( - devname, "if_multicast", "tx_multicast_packets", - ovs_stats_get_port_stat_value(port, tx_multicast_packets), meta); - ovs_stats_submit_one( devname, "if_rx_errors", "rx_undersized_errors", ovs_stats_get_port_stat_value(port, rx_undersized_errors), meta); ovs_stats_submit_one(devname, "if_rx_errors", "rx_oversize_errors", @@ -417,6 +474,47 @@ static void ovs_stats_submit_port(bridge_list_t *bridge, port_list_t *port) { ovs_stats_submit_one(devname, "if_rx_errors", "rx_jabber_errors", ovs_stats_get_port_stat_value(port, rx_jabber_errors), meta); + ovs_stats_submit_one( + devname, "if_rx_octets", "rx_error_bytes", + ovs_stats_get_port_stat_value(port, rx_error_bytes), meta); + ovs_stats_submit_one( + devname, "if_errors", "rx_l3_l4_xsum_error", + ovs_stats_get_port_stat_value(port, rx_l3_l4_xsum_error), meta); + ovs_stats_submit_one( + devname, "if_dropped", "rx_management_dropped", + ovs_stats_get_port_stat_value(port, rx_management_dropped), meta); + ovs_stats_submit_one( + devname, "if_errors", "rx_mbuf_allocation_errors", + ovs_stats_get_port_stat_value(port, rx_mbuf_allocation_errors), meta); + ovs_stats_submit_one( + devname, "if_octets", "rx_total_bytes", + ovs_stats_get_port_stat_value(port, rx_total_bytes), meta); + ovs_stats_submit_one( + devname, "if_packets", "rx_total_missed_packets", + ovs_stats_get_port_stat_value(port, rx_total_missed_packets), meta); + ovs_stats_submit_one( + devname, "if_rx_errors", "rx_undersize_errors", + ovs_stats_get_port_stat_value(port, rx_undersize_errors), meta); + ovs_stats_submit_two( + devname, "if_packets", "management_packets", + ovs_stats_get_port_stat_value(port, rx_management_packets), + ovs_stats_get_port_stat_value(port, tx_management_packets), meta); + ovs_stats_submit_two( + devname, "if_packets", "multicast_packets", + ovs_stats_get_port_stat_value(port, rx_multicast_packets), + ovs_stats_get_port_stat_value(port, tx_multicast_packets), meta); + ovs_stats_submit_two( + devname, "if_octets", "good_bytes", + ovs_stats_get_port_stat_value(port, rx_good_bytes), + ovs_stats_get_port_stat_value(port, tx_good_bytes), meta); + ovs_stats_submit_two( + devname, "if_packets", "good_packets", + ovs_stats_get_port_stat_value(port, rx_good_packets), + ovs_stats_get_port_stat_value(port, tx_good_packets), meta); + ovs_stats_submit_two( + devname, "if_packets", "total_packets", + ovs_stats_get_port_stat_value(port, rx_total_packets), + ovs_stats_get_port_stat_value(port, tx_total_packets), meta); meta_data_destroy(meta); } @@ -488,11 +586,9 @@ static interface_list_t *ovs_stats_new_port_interface(port_list_t *port, } memset(iface->stats, -1, sizeof(int64_t[IFACE_COUNTER_COUNT])); sstrncpy(iface->iface_uuid, uuid, sizeof(iface->iface_uuid)); - pthread_mutex_lock(&g_stats_lock); interface_list_t *iface_head = port->iface; iface->next = iface_head; port->iface = iface; - pthread_mutex_unlock(&g_stats_lock); } return iface; } @@ -512,15 +608,11 @@ static port_list_t *ovs_stats_new_port(bridge_list_t *bridge, return NULL; } sstrncpy(port->port_uuid, uuid, sizeof(port->port_uuid)); - pthread_mutex_lock(&g_stats_lock); port->next = g_port_list_head; g_port_list_head = port; - pthread_mutex_unlock(&g_stats_lock); } if (bridge != NULL) { - pthread_mutex_lock(&g_stats_lock); port->br = bridge; - pthread_mutex_unlock(&g_stats_lock); } return port; } @@ -539,6 +631,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}; @@ -579,7 +684,6 @@ static int ovs_stats_update_bridge(yajl_val bridge) { const char *new[] = {"new", NULL}; const char *name[] = {"name", NULL}; const char *ports[] = {"ports", NULL}; - bridge_list_t *br = NULL; if (!bridge || !YAJL_IS_OBJECT(bridge)) goto failure; @@ -589,32 +693,33 @@ static int ovs_stats_update_bridge(yajl_val bridge) { return 0; yajl_val br_name = yajl_tree_get(row, name, yajl_t_string); - if (br_name && YAJL_IS_STRING(br_name)) { - br = ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name)); - pthread_mutex_lock(&g_stats_lock); - if (br == NULL) { - br = calloc(1, sizeof(*br)); - if (!br) { - pthread_mutex_unlock(&g_stats_lock); - ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br)); - return -1; - } + if (!br_name || !YAJL_IS_STRING(br_name)) + return 0; - char *tmp = YAJL_GET_STRING(br_name); - if (tmp != NULL) - br->name = strdup(tmp); + if (!ovs_stats_is_monitored_bridge(YAJL_GET_STRING(br_name))) + return 0; - if (br->name == NULL) { - sfree(br); - pthread_mutex_unlock(&g_stats_lock); - ERROR("%s: strdup failed.", plugin_name); - return -1; - } + bridge_list_t *br = + ovs_stats_get_bridge(g_bridge_list_head, YAJL_GET_STRING(br_name)); + if (br == NULL) { + br = calloc(1, sizeof(*br)); + if (!br) { + ERROR("%s: calloc(%zu) failed.", plugin_name, sizeof(*br)); + return -1; + } + + char *tmp = YAJL_GET_STRING(br_name); + if (tmp != NULL) + br->name = strdup(tmp); - br->next = g_bridge_list_head; - g_bridge_list_head = br; + if (br->name == NULL) { + sfree(br); + ERROR("%s: strdup failed.", plugin_name); + return -1; } - pthread_mutex_unlock(&g_stats_lock); + + br->next = g_bridge_list_head; + g_bridge_list_head = br; } yajl_val br_ports = yajl_tree_get(row, ports, yajl_t_array); @@ -682,10 +787,12 @@ static void ovs_stats_bridge_table_change_cb(yajl_val jupdates) { if (!bridges || !YAJL_IS_OBJECT(bridges)) return; + pthread_mutex_lock(&g_stats_lock); for (size_t i = 0; i < YAJL_GET_OBJECT(bridges)->len; i++) { yajl_val bridge = YAJL_GET_OBJECT(bridges)->values[i]; ovs_stats_update_bridge(bridge); } + pthread_mutex_unlock(&g_stats_lock); } /* Handle Bridge Table delete event */ @@ -736,10 +843,8 @@ static int ovs_stats_update_port(const char *uuid, yajl_val port) { if (!portentry) return 0; - pthread_mutex_lock(&g_stats_lock); sstrncpy(portentry->name, YAJL_GET_STRING(port_name), sizeof(portentry->name)); - pthread_mutex_unlock(&g_stats_lock); yajl_val ifaces_root = ovs_utils_get_value_by_key(row, "interfaces"); char *ifaces_root_key = @@ -821,10 +926,12 @@ static void ovs_stats_port_table_change_cb(yajl_val jupdates) { if (!ports || !YAJL_IS_OBJECT(ports)) return; + pthread_mutex_lock(&g_stats_lock); for (size_t i = 0; i < YAJL_GET_OBJECT(ports)->len; i++) { yajl_val port = YAJL_GET_OBJECT(ports)->values[i]; ovs_stats_update_port(YAJL_GET_OBJECT(ports)->keys[i], port); } + pthread_mutex_unlock(&g_stats_lock); return; } @@ -880,20 +987,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)); } } } @@ -1128,19 +1236,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;) { @@ -1281,29 +1376,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;