From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 6A7EC6CB5 for ; Mon, 27 Feb 2017 15:16:28 +0100 (CET) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Feb 2017 06:16:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,214,1484035200"; d="scan'208";a="69543393" Received: from silpixa00390851.ir.intel.com ([10.237.223.109]) by orsmga005.jf.intel.com with ESMTP; 27 Feb 2017 06:16:26 -0800 From: Roman Korynkevych To: dev@dpdk.org Cc: Roman Korynkevych Date: Mon, 27 Feb 2017 14:16:22 +0000 Message-Id: <1488204982-32291-1-git-send-email-romanx.korynkevych@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1487955140-32598-1-git-send-email-romanx.korynkevych@intel.com> References: <1487955140-32598-1-git-send-email-romanx.korynkevych@intel.com> Subject: [dpdk-dev] [PATCH v2] proc-info: added collectd-format and host-id options. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Feb 2017 14:16:28 -0000 Extended proc-info application to send DPDK port statistics to STDOUT in the format expected by collectd exec plugin. Added HOST ID option to identify the host DPDK process is running on when multiple instance of DPDK are running in parallel. This is needed for the barometer project in OPNFV. Signed-off-by: Roman Korynkevych --- app/proc_info/main.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 5 deletions(-) diff --git a/app/proc_info/main.c b/app/proc_info/main.c index 2c56d10..2bf280d 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include @@ -62,12 +63,20 @@ #define MAX_LONG_OPT_SZ 64 #define RTE_LOGTYPE_APP RTE_LOGTYPE_USER1 +#define MAX_STRING_LEN 256 + /**< mask of enabled ports */ static uint32_t enabled_port_mask; /**< Enable stats. */ static uint32_t enable_stats; /**< Enable xstats. */ static uint32_t enable_xstats; +/**< Enable collectd format*/ +static uint32_t enable_collectd_format; +/**< FD to send collectd format messages to STDOUT*/ +static int stdout_fd; +/**< Host id process is running on */ +static char host_id[MAX_LONG_OPT_SZ]; /**< Enable stats reset. */ static uint32_t reset_stats; /**< Enable xstats reset. */ @@ -86,7 +95,9 @@ proc_info_usage(const char *prgname) " --xstats: to display extended port statistics, disabled by " "default\n" " --stats-reset: to reset port statistics\n" - " --xstats-reset: to reset port extended statistics\n", + " --xstats-reset: to reset port extended statistics\n" + " --collectd-format: to print statistics to STDOUT in expected by collectd format\n" + " --host-id STRING: host id used to identify the system process is running on\n", prgname); } @@ -116,6 +127,35 @@ parse_portmask(const char *portmask) } +static int +proc_info_preparse_args(int argc, char **argv) +{ + char *prgname = argv[0]; + int i; + + for (i = 0; i < argc; i++) { + /* Print stats or xstats to STDOUT in collectd format */ + if (!strncmp(argv[i], "--collectd-format", MAX_LONG_OPT_SZ)) { + enable_collectd_format = 1; + stdout_fd = dup(STDOUT_FILENO); + close(STDOUT_FILENO); + } + if (!strncmp(argv[i], "--host-id", MAX_LONG_OPT_SZ)) { + if ((i + 1) == argc) { + printf("Invalid host id or not specified\n"); + proc_info_usage(prgname); + return -1; + } + strncpy(host_id, argv[i+1], sizeof(host_id)); + } + } + + if (!strlen(host_id)) + strcpy(host_id, "unknown"); + + return 0; +} + /* Parse the argument given in the command line of the application */ static int proc_info_parse_args(int argc, char **argv) @@ -128,6 +168,8 @@ proc_info_parse_args(int argc, char **argv) {"stats-reset", 0, NULL, 0}, {"xstats", 0, NULL, 0}, {"xstats-reset", 0, NULL, 0}, + {"collectd-format", 0, NULL, 0}, + {"host-id", 0, NULL, 0}, {NULL, 0, 0, 0} }; @@ -240,6 +282,60 @@ nic_stats_clear(uint8_t port_id) printf("\n NIC statistics for port %d cleared\n", port_id); } +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_display(uint8_t port_id) { @@ -281,10 +377,23 @@ nic_xstats_display(uint8_t port_id) goto err; } - for (i = 0; i < len; i++) - printf("%s: %"PRIu64"\n", - xstats_names[i].name, - xstats[i].value); + for (i = 0; i < len; i++) { + if (enable_collectd_format) { + char counter_type[MAX_STRING_LEN]; + char buf[MAX_STRING_LEN]; + + collectd_resolve_cnt_type(counter_type, + sizeof(counter_type), + xstats_names[i].name); + sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%" + PRIu64"\n", host_id, port_id, counter_type, + xstats_names[i].name, xstats[i].value); + write(stdout_fd, buf, strlen(buf)); + } else { + printf("%s: %"PRIu64"\n", xstats_names[i].name, + xstats[i].value); + } + } printf("%s############################\n", nic_stats_border); @@ -312,6 +421,13 @@ main(int argc, char **argv) char *argp[argc + 3]; uint8_t nb_ports; + /* preparse app arguments */ + ret = proc_info_preparse_args(argc, argv); + if (ret < 0) { + printf("Failed to parse arguments\n"); + return -1; + } + argp[0] = argv[0]; argp[1] = c_flag; argp[2] = n_flag; -- 2.1.0