From 738d9e22108a8e472458fad42509fd8d96994d6c Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 6 Oct 2015 15:21:56 +0200 Subject: stats: Add vty_out_stat_item_group This functions dumps a whole stat item group to the VTY. Sponsored-by: On-Waves ehf --- src/vty/utils.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/vty') diff --git a/src/vty/utils.c b/src/vty/utils.c index d0ad431d..e190337c 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,27 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, }; } +/*! \brief print a stat item group to given VTY + * \param[in] vty The VTY to which it should be printed + * \param[in] prefix Any additional log prefix ahead of each line + * \param[in] statg Stat item group to be printed + */ +void vty_out_stat_item_group(struct vty *vty, const char *prefix, + struct stat_item_group *statg) +{ + unsigned int i; + + vty_out(vty, "%s%s:%s", prefix, statg->desc->group_description, + VTY_NEWLINE); + for (i = 0; i < statg->desc->num_items; i++) { + struct stat_item *item = statg->items[i]; + vty_out(vty, " %s%s: %8" PRIi32 " %s%s", + prefix, item->desc->description, + stat_item_get_last(item), + item->desc->unit, VTY_NEWLINE); + }; +} + /*! \brief Generate a VTY command string from value_string */ char *vty_cmd_string_from_valstr(void *ctx, const struct value_string *vals, const char *prefix, const char *sep, -- cgit v1.2.3 From aec583f68786f91c3f0d76a8f8706c85aaca07a8 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 19 Oct 2015 15:06:01 +0200 Subject: stat/vty: Use the iterator algorithms to show ctrg and statg Currently the groups for stat_items and counter are iterated manually. This commit makes use of the new iterator functions to access the single elements via handlers. Sponsored-by: On-Waves ehf --- src/vty/utils.c | 63 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 20 deletions(-) (limited to 'src/vty') diff --git a/src/vty/utils.c b/src/vty/utils.c index e190337c..93e9ef48 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -40,6 +40,30 @@ * @{ */ +struct vty_out_context { + struct vty *vty; + const char *prefix; +}; + +static int rate_ctr_handler( + struct rate_ctr_group *ctrg, struct rate_ctr *ctr, + const struct rate_ctr_desc *desc, void *vctx_) +{ + struct vty_out_context *vctx = vctx_; + struct vty *vty = vctx->vty; + + vty_out(vty, " %s%s: %8" PRIu64 " " + "(%" PRIu64 "/s %" PRIu64 "/m %" PRIu64 "/h %" PRIu64 "/d)%s", + vctx->prefix, desc->description, ctr->current, + ctr->intv[RATE_CTR_INTV_SEC].rate, + ctr->intv[RATE_CTR_INTV_MIN].rate, + ctr->intv[RATE_CTR_INTV_HOUR].rate, + ctr->intv[RATE_CTR_INTV_DAY].rate, + VTY_NEWLINE); + + return 0; +} + /*! \brief print a rate counter group to given VTY * \param[in] vty The VTY to which it should be printed * \param[in] prefix Any additional log prefix ahead of each line @@ -48,20 +72,25 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, struct rate_ctr_group *ctrg) { - unsigned int i; + struct vty_out_context vctx = {vty, prefix}; vty_out(vty, "%s%s:%s", prefix, ctrg->desc->group_description, VTY_NEWLINE); - for (i = 0; i < ctrg->desc->num_ctr; i++) { - struct rate_ctr *ctr = &ctrg->ctr[i]; - vty_out(vty, " %s%s: %8" PRIu64 " " - "(%" PRIu64 "/s %" PRIu64 "/m %" PRIu64 "/h %" PRIu64 "/d)%s", - prefix, ctrg->desc->ctr_desc[i].description, ctr->current, - ctr->intv[RATE_CTR_INTV_SEC].rate, - ctr->intv[RATE_CTR_INTV_MIN].rate, - ctr->intv[RATE_CTR_INTV_HOUR].rate, - ctr->intv[RATE_CTR_INTV_DAY].rate, - VTY_NEWLINE); - }; + + rate_ctr_for_each_counter(ctrg, rate_ctr_handler, &vctx); +} + +static int stat_item_handler( + struct stat_item_group *statg, struct stat_item *item, void *vctx_) +{ + struct vty_out_context *vctx = vctx_; + struct vty *vty = vctx->vty; + + vty_out(vty, " %s%s: %8" PRIi32 " %s%s", + vctx->prefix, item->desc->description, + stat_item_get_last(item), + item->desc->unit, VTY_NEWLINE); + + return 0; } /*! \brief print a stat item group to given VTY @@ -72,17 +101,11 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, void vty_out_stat_item_group(struct vty *vty, const char *prefix, struct stat_item_group *statg) { - unsigned int i; + struct vty_out_context vctx = {vty, prefix}; vty_out(vty, "%s%s:%s", prefix, statg->desc->group_description, VTY_NEWLINE); - for (i = 0; i < statg->desc->num_items; i++) { - struct stat_item *item = statg->items[i]; - vty_out(vty, " %s%s: %8" PRIi32 " %s%s", - prefix, item->desc->description, - stat_item_get_last(item), - item->desc->unit, VTY_NEWLINE); - }; + stat_item_for_each_item(statg, stat_item_handler, &vctx); } /*! \brief Generate a VTY command string from value_string */ -- cgit v1.2.3 From 7211fe157e1107d4a9c04a0ecf494a7b9633c400 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 19 Oct 2015 15:11:50 +0200 Subject: stat/vty: Add vty_out_statistics_full to show all statistics This functions shows the state of all osmo_counters, stat_item groups, and counter groups. Sponsored-by: On-Waves ehf --- src/vty/utils.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'src/vty') diff --git a/src/vty/utils.c b/src/vty/utils.c index 93e9ef48..474a25ef 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -108,6 +109,63 @@ void vty_out_stat_item_group(struct vty *vty, const char *prefix, stat_item_for_each_item(statg, stat_item_handler, &vctx); } +static int stat_item_group_handler(struct stat_item_group *statg, void *vctx_) +{ + struct vty_out_context *vctx = vctx_; + struct vty *vty = vctx->vty; + + if (statg->idx) + vty_out(vty, "%s%s (%d):%s", vctx->prefix, + statg->desc->group_description, statg->idx, + VTY_NEWLINE); + else + vty_out(vty, "%s%s:%s", vctx->prefix, + statg->desc->group_description, VTY_NEWLINE); + + stat_item_for_each_item(statg, stat_item_handler, vctx); + + return 0; +} + +static int rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *vctx_) +{ + struct vty_out_context *vctx = vctx_; + struct vty *vty = vctx->vty; + + if (ctrg->idx) + vty_out(vty, "%s%s (%d):%s", vctx->prefix, + ctrg->desc->group_description, ctrg->idx, VTY_NEWLINE); + else + vty_out(vty, "%s%s:%s", vctx->prefix, + ctrg->desc->group_description, VTY_NEWLINE); + + rate_ctr_for_each_counter(ctrg, rate_ctr_handler, vctx); + + return 0; +} + +static int handle_counter(struct osmo_counter *counter, void *vctx_) +{ + struct vty_out_context *vctx = vctx_; + struct vty *vty = vctx->vty; + + vty_out(vty, " %s%s: %8lu%s", + vctx->prefix, counter->description, + osmo_counter_get(counter), VTY_NEWLINE); + + return 0; +} + +void vty_out_statistics_full(struct vty *vty, const char *prefix) +{ + struct vty_out_context vctx = {vty, prefix}; + + vty_out(vty, "%sUngrouped counters:%s", prefix, VTY_NEWLINE); + osmo_counters_for_each(handle_counter, &vctx); + rate_ctr_for_each_group(rate_ctr_group_handler, &vctx); + stat_item_for_each_group(stat_item_group_handler, &vctx); +} + /*! \brief Generate a VTY command string from value_string */ char *vty_cmd_string_from_valstr(void *ctx, const struct value_string *vals, const char *prefix, const char *sep, -- cgit v1.2.3 From 45513e6040195f5494d40a2750de4dac7037593f Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 19 Oct 2015 15:14:13 +0200 Subject: stats/vty: Add stats_vty.c This file will contain the VTY code related to statistics. This commit adds a minimal file with just as single VTY command: - show stats This command shows all statistical values To enable this and future commands, the main program needs to call stats_vty_add_cmds(). Sponsored-by: On-Waves ehf --- src/vty/Makefile.am | 2 +- src/vty/stats_vty.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/vty/stats_vty.c (limited to 'src/vty') diff --git a/src/vty/Makefile.am b/src/vty/Makefile.am index 4225d27d..7c549d91 100644 --- a/src/vty/Makefile.am +++ b/src/vty/Makefile.am @@ -9,7 +9,7 @@ if ENABLE_VTY lib_LTLIBRARIES = libosmovty.la libosmovty_la_SOURCES = buffer.c command.c vty.c vector.c utils.c \ - telnet_interface.c logging_vty.c + telnet_interface.c logging_vty.c stats_vty.c libosmovty_la_LDFLAGS = -version-info $(LIBVERSION) -no-undefined libosmovty_la_LIBADD = $(top_builddir)/src/libosmocore.la endif diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c new file mode 100644 index 00000000..c19b2259 --- /dev/null +++ b/src/vty/stats_vty.c @@ -0,0 +1,52 @@ +/* OpenBSC stats helper for the VTY */ +/* (C) 2009-2010 by Harald Welte + * (C) 2009-2014 by Holger Hans Peter Freyther + * (C) 2015 by Sysmocom s.f.m.c. GmbH + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#include +#include + +#include "../../config.h" + +#include +#include +#include +#include +#include + +#define CFG_STATS_STR "Configure stats sub-system\n" +#define CFG_REPORTER_STR "Configure a stats reporter\n" + +#define SHOW_STATS_STR "Show statistical values\n" + +DEFUN(show_stats, + show_stats_cmd, + "show stats", + SHOW_STR SHOW_STATS_STR) +{ + vty_out_statistics_full(vty, ""); + + return CMD_SUCCESS; +} + +void stats_vty_add_cmds(const struct log_info *cat) +{ + install_element_ve(&show_stats_cmd); +} -- cgit v1.2.3 From adc900e0e38373193c8451c0310fe742d62c2c8e Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 20 Oct 2015 19:05:52 +0200 Subject: stats/vty: Add stats configuration This commit provides stats configuration similar to the log configuration. The following vty commands are added to the config node: stats reporter statsd Create/Modify a statsd reporter no stats reporter statsd Remove a statsd reporter To actually configure a reporter, the config-stats node is entered when the "stats reporter" command has succeeded. The following new vty commands are available there: local-ip ADDR Set the IP address to which we bind locally no local-ip Do not bind to a certain IP address remote-ip ADDR Set the remote IP address to which we connect remote-port <1-65535> Set the remote port to which we connect prefix PREFIX Set the item/counter name prefix no prefix Do not use a prefix enable Enable the reporter disable Disable the reporter Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 260 insertions(+), 1 deletion(-) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index c19b2259..954f3581 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -29,13 +29,209 @@ #include #include #include +#include #include +#include + #define CFG_STATS_STR "Configure stats sub-system\n" #define CFG_REPORTER_STR "Configure a stats reporter\n" #define SHOW_STATS_STR "Show statistical values\n" +struct cmd_node cfg_stats_node = { + CFG_STATS_NODE, + "%s(config-stats)# ", + 1 +}; + +static struct stats_reporter *osmo_stats_vty2srep(struct vty *vty) +{ + if (vty->node == CFG_STATS_NODE) + return vty->index; + + return NULL; +} + +static int set_srep_parameter_str(struct vty *vty, + int (*fun)(struct stats_reporter *, const char *), + const char *val, const char *param_name) +{ + int rc; + struct stats_reporter *srep = osmo_stats_vty2srep(vty); + OSMO_ASSERT(srep); + + rc = fun(srep, val); + if (rc < 0) { + vty_out(vty, "%% Unable to set %s: %s%s", + param_name, strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +static int set_srep_parameter_int(struct vty *vty, + int (*fun)(struct stats_reporter *, int), + const char *val, const char *param_name) +{ + int rc; + int int_val; + struct stats_reporter *srep = osmo_stats_vty2srep(vty); + OSMO_ASSERT(srep); + + int_val = atoi(val); + + rc = fun(srep, int_val); + if (rc < 0) { + vty_out(vty, "%% Unable to set %s: %s%s", + param_name, strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd, + "local-ip ADDR", + "Set the IP address to which we bind locally\n" + "IP Address\n") +{ + return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + argv[0], "local address"); +} + +DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd, + "no local-ip", + NO_STR + "Set the IP address to which we bind locally\n") +{ + return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + NULL, "local address"); +} + +DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd, + "remote-ip ADDR", + "Set the remote IP address to which we connect\n" + "IP Address\n") +{ + return set_srep_parameter_str(vty, stats_reporter_set_remote_addr, + argv[0], "remote address"); +} + +DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, + "remote-port <1-65535>", + "Set the remote port to which we connect\n" + "Remote port number\n") +{ + return set_srep_parameter_int(vty, stats_reporter_set_remote_port, + argv[0], "remote port"); +} + +DEFUN(cfg_stats_reporter_interval, cfg_stats_reporter_interval_cmd, + "interval <1-65535>", + "Set the reporting interval\n" + "Interval in seconds\n") +{ + return set_srep_parameter_int(vty, stats_reporter_set_interval, + argv[0], "reporting interval"); +} + +DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, + "prefix PREFIX", + "Set the item name prefix\n" + "The prefix string\n") +{ + return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + argv[0], "prefix string"); +} + +DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, + "no prefix", + NO_STR + "Set the item name prefix\n") +{ + return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + "", "prefix string"); +} + +DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, + "enable", + "Enable the reporter\n") +{ + int rc; + struct stats_reporter *srep = osmo_stats_vty2srep(vty); + OSMO_ASSERT(srep); + + rc = stats_reporter_enable(srep); + if (rc < 0) { + vty_out(vty, "%% Unable to enable the reporter: %s%s", + strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd, + "disable", + "Disable the reporter\n") +{ + int rc; + struct stats_reporter *srep = osmo_stats_vty2srep(vty); + OSMO_ASSERT(srep); + + rc = stats_reporter_disable(srep); + if (rc < 0) { + vty_out(vty, "%% Unable to disable the reporter: %s%s", + strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + +DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, + "stats reporter statsd", + CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") +{ + struct stats_reporter *srep; + + srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + if (!srep) { + srep = stats_reporter_create_statsd(NULL); + if (!srep) { + vty_out(vty, "%% Unable to create statsd reporter%s", + VTY_NEWLINE); + return CMD_WARNING; + } + /* TODO: if needed, add stats_add_reporter(srep); */ + } + + vty->index = srep; + vty->node = CFG_STATS_NODE; + + return CMD_SUCCESS; +} + +DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, + "no stats reporter statsd", + NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") +{ + struct stats_reporter *srep; + + srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + if (!srep) { + vty_out(vty, "%% No statsd logging active%s", + VTY_NEWLINE); + return CMD_WARNING; + } + + stats_reporter_free(srep); + + return CMD_SUCCESS; +} + DEFUN(show_stats, show_stats_cmd, "show stats", @@ -46,7 +242,70 @@ DEFUN(show_stats, return CMD_SUCCESS; } -void stats_vty_add_cmds(const struct log_info *cat) +static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *srep) +{ + if (srep == NULL) + return 0; + + switch (srep->type) { + case STATS_REPORTER_STATSD: + vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); + break; + } + + vty_out(vty, " disable%s", VTY_NEWLINE); + + if (srep->dest_addr_str) + vty_out(vty, " remote-ip %s%s", + srep->dest_addr_str, VTY_NEWLINE); + if (srep->dest_port) + vty_out(vty, " remote-port %d%s", + srep->dest_port, VTY_NEWLINE); + if (srep->bind_addr_str) + vty_out(vty, " local-ip %s%s", + srep->bind_addr_str, VTY_NEWLINE); + if (srep->interval) + vty_out(vty, " interval %d%s", + srep->interval, VTY_NEWLINE); + if (srep->name_prefix && *srep->name_prefix) + vty_out(vty, " prefix %s%s", + srep->name_prefix, VTY_NEWLINE); + else + vty_out(vty, " no prefix%s", VTY_NEWLINE); + + if (srep->enabled) + vty_out(vty, " enable%s", VTY_NEWLINE); + + return 1; +} + +static int config_write_stats(struct vty *vty) +{ + struct stats_reporter *srep; + + srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + config_write_stats_reporter(vty, srep); + + return 1; +} + +void stats_vty_add_cmds() { install_element_ve(&show_stats_cmd); + + install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd); + install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd); + + install_node(&cfg_stats_node, config_write_stats); + vty_install_default(CFG_STATS_NODE); + + install_element(CFG_STATS_NODE, &cfg_stats_reporter_local_ip_cmd); + install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_interval_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); + install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd); } -- cgit v1.2.3 From b1dbfb4c4179a62cd4b761ebdc7a3c2de5bdc0d9 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 26 Oct 2015 11:58:38 +0100 Subject: stats: Implement timer based reporting This calls stats_flush in regular intervals which polls the statistical values and calls the active reporters when values have changed. Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 954f3581..a4fd7b05 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -128,15 +128,6 @@ DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, argv[0], "remote port"); } -DEFUN(cfg_stats_reporter_interval, cfg_stats_reporter_interval_cmd, - "interval <1-65535>", - "Set the reporting interval\n" - "Interval in seconds\n") -{ - return set_srep_parameter_int(vty, stats_reporter_set_interval, - argv[0], "reporting interval"); -} - DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, "prefix PREFIX", "Set the item name prefix\n" @@ -214,6 +205,24 @@ DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, return CMD_SUCCESS; } +DEFUN(cfg_stats_interval, cfg_stats_interval_cmd, + "stats interval <1-65535>", + CFG_STATS_STR "Set the reporting interval\n" + "Interval in seconds\n") +{ + int rc; + int interval = atoi(argv[0]); + rc = stats_set_interval(interval); + if (rc < 0) { + vty_out(vty, "%% Unable to set interval: %s%s", + strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return CMD_SUCCESS; +} + + DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, "no stats reporter statsd", NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") @@ -264,9 +273,6 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s if (srep->bind_addr_str) vty_out(vty, " local-ip %s%s", srep->bind_addr_str, VTY_NEWLINE); - if (srep->interval) - vty_out(vty, " interval %d%s", - srep->interval, VTY_NEWLINE); if (srep->name_prefix && *srep->name_prefix) vty_out(vty, " prefix %s%s", srep->name_prefix, VTY_NEWLINE); @@ -286,6 +292,8 @@ static int config_write_stats(struct vty *vty) srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); config_write_stats_reporter(vty, srep); + vty_out(vty, "stats interval %d%s", stats_config->interval, VTY_NEWLINE); + return 1; } @@ -295,6 +303,7 @@ void stats_vty_add_cmds() install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd); install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd); + install_element(CONFIG_NODE, &cfg_stats_interval_cmd); install_node(&cfg_stats_node, config_write_stats); vty_install_default(CFG_STATS_NODE); @@ -303,7 +312,6 @@ void stats_vty_add_cmds() install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd); - install_element(CFG_STATS_NODE, &cfg_stats_reporter_interval_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); -- cgit v1.2.3 From d01acfcc75a6c5798a95a8ccca9be18eba65a0bf Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 26 Oct 2015 16:22:45 +0100 Subject: stats: Support statsd Multi-Metric Packets If the MTU is given, combine several messages into a single UDP packet until the limit is reached. Flush all reporters after the values have been scanned. New vty commands (node config-stats): mtu <100-65535> Enable multi-metric packets and set the maximum packet size (in byte) no mtu Disable multi-metric packets Note that single messages that are longer than the given MTU (minus 28 octets protocol overhead) will be dropped. Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index a4fd7b05..775184c9 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -128,6 +128,23 @@ DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, argv[0], "remote port"); } +DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd, + "mtu <100-65535>", + "Set the maximum packet size\n" + "Size in byte\n") +{ + return set_srep_parameter_int(vty, stats_reporter_set_mtu, + argv[0], "mtu"); +} + +DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, + "no mtu", + NO_STR "Set the maximum packet size\n") +{ + return set_srep_parameter_int(vty, stats_reporter_set_mtu, + 0, "mtu"); +} + DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, "prefix PREFIX", "Set the item name prefix\n" @@ -312,6 +329,8 @@ void stats_vty_add_cmds() install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_local_ip_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_ip_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_remote_port_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_mtu_cmd); + install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); -- cgit v1.2.3 From 4aa11770622ae9009074d68cc8c340821b19adf3 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 27 Oct 2015 11:55:20 +0100 Subject: stats: Add missing mtu command to 'write' output Currently the config_write_stats_reporter function does not output the mtu value, which is fixed by this commit. Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 775184c9..0911fbb8 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -290,6 +290,9 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s if (srep->bind_addr_str) vty_out(vty, " local-ip %s%s", srep->bind_addr_str, VTY_NEWLINE); + if (srep->mtu) + vty_out(vty, " mtu %d%s", + srep->mtu, VTY_NEWLINE); if (srep->name_prefix && *srep->name_prefix) vty_out(vty, " prefix %s%s", srep->name_prefix, VTY_NEWLINE); -- cgit v1.2.3 From ed197fd4f923512fca5b93b90c2132845896fa59 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Tue, 27 Oct 2015 14:43:24 +0100 Subject: stats: Make net config optional To support reporters without network configuration, this commit introduces the have_net_config flag to provide corresponding error messages. Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 0911fbb8..18ad2835 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -281,18 +281,21 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s vty_out(vty, " disable%s", VTY_NEWLINE); - if (srep->dest_addr_str) - vty_out(vty, " remote-ip %s%s", - srep->dest_addr_str, VTY_NEWLINE); - if (srep->dest_port) - vty_out(vty, " remote-port %d%s", - srep->dest_port, VTY_NEWLINE); - if (srep->bind_addr_str) - vty_out(vty, " local-ip %s%s", - srep->bind_addr_str, VTY_NEWLINE); - if (srep->mtu) - vty_out(vty, " mtu %d%s", - srep->mtu, VTY_NEWLINE); + if (srep->have_net_config) { + if (srep->dest_addr_str) + vty_out(vty, " remote-ip %s%s", + srep->dest_addr_str, VTY_NEWLINE); + if (srep->dest_port) + vty_out(vty, " remote-port %d%s", + srep->dest_port, VTY_NEWLINE); + if (srep->bind_addr_str) + vty_out(vty, " local-ip %s%s", + srep->bind_addr_str, VTY_NEWLINE); + if (srep->mtu) + vty_out(vty, " mtu %d%s", + srep->mtu, VTY_NEWLINE); + } + if (srep->name_prefix && *srep->name_prefix) vty_out(vty, " prefix %s%s", srep->name_prefix, VTY_NEWLINE); -- cgit v1.2.3 From bc4f7ae512b32fa4b569dfc5242d0b7a5da3f81b Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Wed, 28 Oct 2015 21:47:45 +0100 Subject: stats: Add log reporter This reporter passes the measurement values to the logging subsystem as DSTATS (which is currently DLGLOBAL) level INFO messages. Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 18ad2835..839dc829 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -258,6 +258,47 @@ DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, return CMD_SUCCESS; } +DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, + "stats reporter log", + CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") +{ + struct stats_reporter *srep; + + srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + if (!srep) { + srep = stats_reporter_create_log(NULL); + if (!srep) { + vty_out(vty, "%% Unable to create log reporter%s", + VTY_NEWLINE); + return CMD_WARNING; + } + /* TODO: if needed, add stats_add_reporter(srep); */ + } + + vty->index = srep; + vty->node = CFG_STATS_NODE; + + return CMD_SUCCESS; +} + +DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd, + "no stats reporter log", + NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") +{ + struct stats_reporter *srep; + + srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + if (!srep) { + vty_out(vty, "%% No log reporting active%s", + VTY_NEWLINE); + return CMD_WARNING; + } + + stats_reporter_free(srep); + + return CMD_SUCCESS; +} + DEFUN(show_stats, show_stats_cmd, "show stats", @@ -277,6 +318,9 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s case STATS_REPORTER_STATSD: vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); break; + case STATS_REPORTER_LOG: + vty_out(vty, "stats reporter log%s", VTY_NEWLINE); + break; } vty_out(vty, " disable%s", VTY_NEWLINE); @@ -312,8 +356,11 @@ static int config_write_stats(struct vty *vty) { struct stats_reporter *srep; + /* TODO: loop through all reporters */ srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); config_write_stats_reporter(vty, srep); + srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + config_write_stats_reporter(vty, srep); vty_out(vty, "stats interval %d%s", stats_config->interval, VTY_NEWLINE); @@ -326,6 +373,8 @@ void stats_vty_add_cmds() install_element(CONFIG_NODE, &cfg_stats_reporter_statsd_cmd); install_element(CONFIG_NODE, &cfg_no_stats_reporter_statsd_cmd); + install_element(CONFIG_NODE, &cfg_stats_reporter_log_cmd); + install_element(CONFIG_NODE, &cfg_no_stats_reporter_log_cmd); install_element(CONFIG_NODE, &cfg_stats_interval_cmd); install_node(&cfg_stats_node, config_write_stats); -- cgit v1.2.3 From fc9533d6c4bde795dc0e18f02f91f54ab92888a2 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Thu, 29 Oct 2015 00:55:58 +0100 Subject: stats: Add osmo_ name prefix to identifiers Since the the stat_item and stats functions and data types are meant to be exported, they get an osmo_ prefix. Sponsored-by: On-Waves ehf [hfreyther: Prepended the enum values too. This was requested by Jacob] --- src/vty/stats_vty.c | 80 ++++++++++++++++++++++++++--------------------------- src/vty/utils.c | 16 +++++------ 2 files changed, 48 insertions(+), 48 deletions(-) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 839dc829..f072b1ba 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -45,7 +45,7 @@ struct cmd_node cfg_stats_node = { 1 }; -static struct stats_reporter *osmo_stats_vty2srep(struct vty *vty) +static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty) { if (vty->node == CFG_STATS_NODE) return vty->index; @@ -54,11 +54,11 @@ static struct stats_reporter *osmo_stats_vty2srep(struct vty *vty) } static int set_srep_parameter_str(struct vty *vty, - int (*fun)(struct stats_reporter *, const char *), + int (*fun)(struct osmo_stats_reporter *, const char *), const char *val, const char *param_name) { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); rc = fun(srep, val); @@ -72,12 +72,12 @@ static int set_srep_parameter_str(struct vty *vty, } static int set_srep_parameter_int(struct vty *vty, - int (*fun)(struct stats_reporter *, int), + int (*fun)(struct osmo_stats_reporter *, int), const char *val, const char *param_name) { int rc; int int_val; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); int_val = atoi(val); @@ -97,7 +97,7 @@ DEFUN(cfg_stats_reporter_local_ip, cfg_stats_reporter_local_ip_cmd, "Set the IP address to which we bind locally\n" "IP Address\n") { - return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, argv[0], "local address"); } @@ -106,7 +106,7 @@ DEFUN(cfg_no_stats_reporter_local_ip, cfg_no_stats_reporter_local_ip_cmd, NO_STR "Set the IP address to which we bind locally\n") { - return set_srep_parameter_str(vty, stats_reporter_set_local_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_local_addr, NULL, "local address"); } @@ -115,7 +115,7 @@ DEFUN(cfg_stats_reporter_remote_ip, cfg_stats_reporter_remote_ip_cmd, "Set the remote IP address to which we connect\n" "IP Address\n") { - return set_srep_parameter_str(vty, stats_reporter_set_remote_addr, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_remote_addr, argv[0], "remote address"); } @@ -124,7 +124,7 @@ DEFUN(cfg_stats_reporter_remote_port, cfg_stats_reporter_remote_port_cmd, "Set the remote port to which we connect\n" "Remote port number\n") { - return set_srep_parameter_int(vty, stats_reporter_set_remote_port, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_remote_port, argv[0], "remote port"); } @@ -133,7 +133,7 @@ DEFUN(cfg_stats_reporter_mtu, cfg_stats_reporter_mtu_cmd, "Set the maximum packet size\n" "Size in byte\n") { - return set_srep_parameter_int(vty, stats_reporter_set_mtu, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, argv[0], "mtu"); } @@ -141,7 +141,7 @@ DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, "no mtu", NO_STR "Set the maximum packet size\n") { - return set_srep_parameter_int(vty, stats_reporter_set_mtu, + return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, 0, "mtu"); } @@ -150,7 +150,7 @@ DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, "Set the item name prefix\n" "The prefix string\n") { - return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, argv[0], "prefix string"); } @@ -159,7 +159,7 @@ DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, NO_STR "Set the item name prefix\n") { - return set_srep_parameter_str(vty, stats_reporter_set_name_prefix, + return set_srep_parameter_str(vty, osmo_stats_reporter_set_name_prefix, "", "prefix string"); } @@ -168,10 +168,10 @@ DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, "Enable the reporter\n") { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); - rc = stats_reporter_enable(srep); + rc = osmo_stats_reporter_enable(srep); if (rc < 0) { vty_out(vty, "%% Unable to enable the reporter: %s%s", strerror(-rc), VTY_NEWLINE); @@ -186,10 +186,10 @@ DEFUN(cfg_stats_reporter_disable, cfg_stats_reporter_disable_cmd, "Disable the reporter\n") { int rc; - struct stats_reporter *srep = osmo_stats_vty2srep(vty); + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); OSMO_ASSERT(srep); - rc = stats_reporter_disable(srep); + rc = osmo_stats_reporter_disable(srep); if (rc < 0) { vty_out(vty, "%% Unable to disable the reporter: %s%s", strerror(-rc), VTY_NEWLINE); @@ -203,17 +203,17 @@ DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, "stats reporter statsd", CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); if (!srep) { - srep = stats_reporter_create_statsd(NULL); + srep = osmo_stats_reporter_create_statsd(NULL); if (!srep) { vty_out(vty, "%% Unable to create statsd reporter%s", VTY_NEWLINE); return CMD_WARNING; } - /* TODO: if needed, add stats_add_reporter(srep); */ + /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } vty->index = srep; @@ -229,7 +229,7 @@ DEFUN(cfg_stats_interval, cfg_stats_interval_cmd, { int rc; int interval = atoi(argv[0]); - rc = stats_set_interval(interval); + rc = osmo_stats_set_interval(interval); if (rc < 0) { vty_out(vty, "%% Unable to set interval: %s%s", strerror(-rc), VTY_NEWLINE); @@ -244,16 +244,16 @@ DEFUN(cfg_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd, "no stats reporter statsd", NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to a STATSD server\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); if (!srep) { vty_out(vty, "%% No statsd logging active%s", VTY_NEWLINE); return CMD_WARNING; } - stats_reporter_free(srep); + osmo_stats_reporter_free(srep); return CMD_SUCCESS; } @@ -262,17 +262,17 @@ DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, "stats reporter log", CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); if (!srep) { - srep = stats_reporter_create_log(NULL); + srep = osmo_stats_reporter_create_log(NULL); if (!srep) { vty_out(vty, "%% Unable to create log reporter%s", VTY_NEWLINE); return CMD_WARNING; } - /* TODO: if needed, add stats_add_reporter(srep); */ + /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } vty->index = srep; @@ -285,16 +285,16 @@ DEFUN(cfg_no_stats_reporter_log, cfg_no_stats_reporter_log_cmd, "no stats reporter log", NO_STR CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); if (!srep) { vty_out(vty, "%% No log reporting active%s", VTY_NEWLINE); return CMD_WARNING; } - stats_reporter_free(srep); + osmo_stats_reporter_free(srep); return CMD_SUCCESS; } @@ -309,16 +309,16 @@ DEFUN(show_stats, return CMD_SUCCESS; } -static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *srep) +static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep) { if (srep == NULL) return 0; switch (srep->type) { - case STATS_REPORTER_STATSD: + case OSMO_STATS_REPORTER_STATSD: vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); break; - case STATS_REPORTER_LOG: + case OSMO_STATS_REPORTER_LOG: vty_out(vty, "stats reporter log%s", VTY_NEWLINE); break; } @@ -354,20 +354,20 @@ static int config_write_stats_reporter(struct vty *vty, struct stats_reporter *s static int config_write_stats(struct vty *vty) { - struct stats_reporter *srep; + struct osmo_stats_reporter *srep; /* TODO: loop through all reporters */ - srep = stats_reporter_find(STATS_REPORTER_STATSD, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); config_write_stats_reporter(vty, srep); - srep = stats_reporter_find(STATS_REPORTER_LOG, NULL); + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); config_write_stats_reporter(vty, srep); - vty_out(vty, "stats interval %d%s", stats_config->interval, VTY_NEWLINE); + vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE); return 1; } -void stats_vty_add_cmds() +void osmo_stats_vty_add_cmds() { install_element_ve(&show_stats_cmd); diff --git a/src/vty/utils.c b/src/vty/utils.c index 474a25ef..8df44ae1 100644 --- a/src/vty/utils.c +++ b/src/vty/utils.c @@ -80,15 +80,15 @@ void vty_out_rate_ctr_group(struct vty *vty, const char *prefix, rate_ctr_for_each_counter(ctrg, rate_ctr_handler, &vctx); } -static int stat_item_handler( - struct stat_item_group *statg, struct stat_item *item, void *vctx_) +static int osmo_stat_item_handler( + struct osmo_stat_item_group *statg, struct osmo_stat_item *item, void *vctx_) { struct vty_out_context *vctx = vctx_; struct vty *vty = vctx->vty; vty_out(vty, " %s%s: %8" PRIi32 " %s%s", vctx->prefix, item->desc->description, - stat_item_get_last(item), + osmo_stat_item_get_last(item), item->desc->unit, VTY_NEWLINE); return 0; @@ -100,16 +100,16 @@ static int stat_item_handler( * \param[in] statg Stat item group to be printed */ void vty_out_stat_item_group(struct vty *vty, const char *prefix, - struct stat_item_group *statg) + struct osmo_stat_item_group *statg) { struct vty_out_context vctx = {vty, prefix}; vty_out(vty, "%s%s:%s", prefix, statg->desc->group_description, VTY_NEWLINE); - stat_item_for_each_item(statg, stat_item_handler, &vctx); + osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, &vctx); } -static int stat_item_group_handler(struct stat_item_group *statg, void *vctx_) +static int osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *vctx_) { struct vty_out_context *vctx = vctx_; struct vty *vty = vctx->vty; @@ -122,7 +122,7 @@ static int stat_item_group_handler(struct stat_item_group *statg, void *vctx_) vty_out(vty, "%s%s:%s", vctx->prefix, statg->desc->group_description, VTY_NEWLINE); - stat_item_for_each_item(statg, stat_item_handler, vctx); + osmo_stat_item_for_each_item(statg, osmo_stat_item_handler, vctx); return 0; } @@ -163,7 +163,7 @@ void vty_out_statistics_full(struct vty *vty, const char *prefix) vty_out(vty, "%sUngrouped counters:%s", prefix, VTY_NEWLINE); osmo_counters_for_each(handle_counter, &vctx); rate_ctr_for_each_group(rate_ctr_group_handler, &vctx); - stat_item_for_each_group(stat_item_group_handler, &vctx); + osmo_stat_item_for_each_group(osmo_stat_item_group_handler, &vctx); } /*! \brief Generate a VTY command string from value_string */ -- cgit v1.2.3 From bc9d9aced8c174bbb5fc265ec746621d31344be0 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Mon, 2 Nov 2015 14:49:35 +0100 Subject: stats: Limit reporting by class id This commit adds class_id fields to the rate_ctr and stat_item group descriptions. The stats reporter code is extended to only process groups whose class_id does not exceed a per reporter max_class level. If the class_id is not set, the code assumes 'global' for groups with idx == 0 and 'subscriber' otherwise. The following vty command is added to config-stats: level (global|peer|subscriber) Set the maximum group level Sponsored-by: On-Waves ehf --- src/vty/stats_vty.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index f072b1ba..0b7ac7ad 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -45,6 +45,13 @@ struct cmd_node cfg_stats_node = { 1 }; +static const struct value_string stats_class_strs[] = { + { OSMO_STATS_CLASS_GLOBAL, "global" }, + { OSMO_STATS_CLASS_PEER, "peer" }, + { OSMO_STATS_CLASS_SUBSCRIBER, "subscriber" }, + { 0, NULL } +}; + static struct osmo_stats_reporter *osmo_stats_vty2srep(struct vty *vty) { if (vty->node == CFG_STATS_NODE) @@ -163,6 +170,28 @@ DEFUN(cfg_no_stats_reporter_prefix, cfg_no_stats_reporter_prefix_cmd, "", "prefix string"); } +DEFUN(cfg_stats_reporter_level, cfg_stats_reporter_level_cmd, + "level (global|peer|subscriber)", + "Set the maximum group level\n" + "Report global groups only\n" + "Report global and network peer related groups\n" + "Report global, peer, and subscriber groups\n") +{ + int level = get_string_value(stats_class_strs, argv[0]); + int rc; + struct osmo_stats_reporter *srep = osmo_stats_vty2srep(vty); + + OSMO_ASSERT(srep); + rc = osmo_stats_reporter_set_max_class(srep, level); + if (rc < 0) { + vty_out(vty, "%% Unable to set level: %s%s", + strerror(-rc), VTY_NEWLINE); + return CMD_WARNING; + } + + return 0; +} + DEFUN(cfg_stats_reporter_enable, cfg_stats_reporter_enable_cmd, "enable", "Enable the reporter\n") @@ -213,6 +242,7 @@ DEFUN(cfg_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd, VTY_NEWLINE); return CMD_WARNING; } + srep->max_class = OSMO_STATS_CLASS_GLOBAL; /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } @@ -272,6 +302,7 @@ DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, VTY_NEWLINE); return CMD_WARNING; } + srep->max_class = OSMO_STATS_CLASS_GLOBAL; /* TODO: if needed, add osmo_stats_add_reporter(srep); */ } @@ -340,6 +371,11 @@ static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_report srep->mtu, VTY_NEWLINE); } + if (srep->max_class) + vty_out(vty, " level %s%s", + get_value_string(stats_class_strs, srep->max_class), + VTY_NEWLINE); + if (srep->name_prefix && *srep->name_prefix) vty_out(vty, " prefix %s%s", srep->name_prefix, VTY_NEWLINE); @@ -388,6 +424,7 @@ void osmo_stats_vty_add_cmds() install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_mtu_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_prefix_cmd); install_element(CFG_STATS_NODE, &cfg_no_stats_reporter_prefix_cmd); + install_element(CFG_STATS_NODE, &cfg_stats_reporter_level_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_enable_cmd); install_element(CFG_STATS_NODE, &cfg_stats_reporter_disable_cmd); } -- cgit v1.2.3 From 8f0374f7521376bdb721e821047e8a6a4a727283 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Mon, 2 Nov 2015 15:53:09 +0100 Subject: stats: Fix handling of the no mtu command For the atoi we need to pass the val as a string. This means we need to write "0" which then gets parsed to 0. [src/vty/stats_vty.c:90]: (error) Possible null pointer dereference: val --- src/vty/stats_vty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/vty') diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 0b7ac7ad..98253fff 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -149,7 +149,7 @@ DEFUN(cfg_no_stats_reporter_mtu, cfg_no_stats_reporter_mtu_cmd, NO_STR "Set the maximum packet size\n") { return set_srep_parameter_int(vty, osmo_stats_reporter_set_mtu, - 0, "mtu"); + "0", "mtu"); } DEFUN(cfg_stats_reporter_prefix, cfg_stats_reporter_prefix_cmd, -- cgit v1.2.3