+static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len,
+ const char *cnt_name) {
+ char *type_end = strrchr(cnt_name, '_');
+
+ if ((type_end != NULL) &&
+ (strncmp(cnt_name, "rx_", strlen("rx_")) == 0)) {
+ if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
+ strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
+ strncpy(cnt_type, "if_rx_dropped", cnt_type_len);
+ else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
+ strncpy(cnt_type, "if_rx_octets", cnt_type_len);
+ else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
+ strncpy(cnt_type, "if_rx_packets", cnt_type_len);
+ else if (strncmp(type_end, "_placement",
+ strlen("_placement")) == 0)
+ strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ else if (strncmp(type_end, "_buff", strlen("_buff")) == 0)
+ strncpy(cnt_type, "if_rx_errors", cnt_type_len);
+ else
+ /* Does not fit obvious type: use a more generic one */
+ strncpy(cnt_type, "derive", cnt_type_len);
+ } else if ((type_end != NULL) &&
+ (strncmp(cnt_name, "tx_", strlen("tx_"))) == 0) {
+ if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
+ strncpy(cnt_type, "if_tx_errors", cnt_type_len);
+ else if (strncmp(type_end, "_dropped", strlen("_dropped")) == 0)
+ strncpy(cnt_type, "if_tx_dropped", cnt_type_len);
+ else if (strncmp(type_end, "_bytes", strlen("_bytes")) == 0)
+ strncpy(cnt_type, "if_tx_octets", cnt_type_len);
+ else if (strncmp(type_end, "_packets", strlen("_packets")) == 0)
+ strncpy(cnt_type, "if_tx_packets", cnt_type_len);
+ else
+ /* Does not fit obvious type: use a more generic one */
+ strncpy(cnt_type, "derive", cnt_type_len);
+ } else if ((type_end != NULL) &&
+ (strncmp(cnt_name, "flow_", strlen("flow_"))) == 0) {
+ if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
+ strncpy(cnt_type, "operations", cnt_type_len);
+ else if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
+ strncpy(cnt_type, "errors", cnt_type_len);
+ else if (strncmp(type_end, "_filters", strlen("_filters")) == 0)
+ strncpy(cnt_type, "filter_result", cnt_type_len);
+ } else if ((type_end != NULL) &&
+ (strncmp(cnt_name, "mac_", strlen("mac_"))) == 0) {
+ if (strncmp(type_end, "_errors", strlen("_errors")) == 0)
+ strncpy(cnt_type, "errors", cnt_type_len);
+ } else {
+ /* Does not fit obvious type, or strrchr error: */
+ /* use a more generic type */
+ strncpy(cnt_type, "derive", cnt_type_len);
+ }
+}
+
+static void
+nic_xstats_by_name_display(uint16_t port_id, char *name)
+{
+ uint64_t id;
+
+ printf("###### NIC statistics for port %-2d, statistic name '%s':\n",
+ port_id, name);
+
+ if (rte_eth_xstats_get_id_by_name(port_id, name, &id) == 0)
+ printf("%s: %"PRIu64"\n", name, id);
+ else
+ printf("Statistic not found...\n");
+
+}
+
+static void
+nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len)
+{
+ struct rte_eth_xstat_name *xstats_names;
+ uint64_t *values;
+ int ret, i;
+ static const char *nic_stats_border = "########################";
+
+ values = malloc(sizeof(*values) * len);
+ if (values == NULL) {
+ printf("Cannot allocate memory for xstats\n");
+ return;
+ }
+
+ xstats_names = malloc(sizeof(struct rte_eth_xstat_name) * len);
+ if (xstats_names == NULL) {
+ printf("Cannot allocate memory for xstat names\n");
+ free(values);
+ return;
+ }
+
+ if (len != rte_eth_xstats_get_names_by_id(
+ port_id, xstats_names, len, ids)) {
+ printf("Cannot get xstat names\n");
+ goto err;
+ }
+
+ printf("###### NIC extended statistics for port %-2d #########\n",
+ port_id);
+ printf("%s############################\n", nic_stats_border);
+ ret = rte_eth_xstats_get_by_id(port_id, ids, values, len);
+ if (ret < 0 || ret > len) {
+ printf("Cannot get xstats\n");
+ goto err;
+ }
+
+ for (i = 0; i < len; i++)
+ printf("%s: %"PRIu64"\n",
+ xstats_names[i].name,
+ values[i]);
+
+ printf("%s############################\n", nic_stats_border);
+err:
+ free(values);
+ free(xstats_names);
+}
+