This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
fixeria gerrit-no-reply at lists.osmocom.orgfixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/26171 ) Change subject: stats: allow configuring reporter's name in the VTY ...................................................................... stats: allow configuring reporter's name in the VTY This allows configuring more than one reporter of the given type. Change-Id: Ia815c24dc974648985539913012b3b074ea317a9 Related: SYS#5713 --- M include/osmocom/core/stats.h M src/stats.c M src/vty/stats_vty.c M tests/stats/stats_vty_test.vty 4 files changed, 121 insertions(+), 28 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/71/26171/1 diff --git a/include/osmocom/core/stats.h b/include/osmocom/core/stats.h index b9edac2..c4f71c8 100644 --- a/include/osmocom/core/stats.h +++ b/include/osmocom/core/stats.h @@ -108,6 +108,7 @@ int interval; }; +extern struct llist_head osmo_stats_reporter_list; extern struct osmo_stats_config *osmo_stats_config; void osmo_stats_init(void *ctx); diff --git a/src/stats.c b/src/stats.c index 0967305..702e408 100644 --- a/src/stats.c +++ b/src/stats.c @@ -106,7 +106,7 @@ #define STATS_DEFAULT_INTERVAL 5 /* secs */ #define STATS_DEFAULT_BUFLEN 256 -static LLIST_HEAD(osmo_stats_reporter_list); +LLIST_HEAD(osmo_stats_reporter_list); static void *osmo_stats_ctx = NULL; static int is_initialised = 0; diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c index 17e7190..a4fc6ea 100644 --- a/src/vty/stats_vty.c +++ b/src/vty/stats_vty.c @@ -269,14 +269,20 @@ } 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") + "stats reporter statsd [NAME]", + CFG_STATS_STR CFG_REPORTER_STR + "Report to a STATSD server\n" + "Name of the reporter\n") { struct osmo_stats_reporter *srep; + const char *name = NULL; - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); + if (argc > 0) + name = argv[0]; + + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, name); if (!srep) { - srep = osmo_stats_reporter_create_statsd(NULL); + srep = osmo_stats_reporter_create_statsd(name); if (!srep) { vty_out(vty, "%% Unable to create statsd reporter%s", VTY_NEWLINE); @@ -293,12 +299,18 @@ } 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") + "no stats reporter statsd [NAME]", + NO_STR CFG_STATS_STR CFG_REPORTER_STR + "Report to a STATSD server\n" + "Name of the reporter\n") { struct osmo_stats_reporter *srep; + const char *name = NULL; - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); + if (argc > 0) + name = argv[0]; + + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, name); if (!srep) { vty_out(vty, "%% No statsd logging active%s", VTY_NEWLINE); @@ -311,14 +323,20 @@ } DEFUN(cfg_stats_reporter_log, cfg_stats_reporter_log_cmd, - "stats reporter log", - CFG_STATS_STR CFG_REPORTER_STR "Report to the logger\n") + "stats reporter log [NAME]", + CFG_STATS_STR CFG_REPORTER_STR + "Report to the logger\n" + "Name of the reporter\n") { struct osmo_stats_reporter *srep; + const char *name = NULL; - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); + if (argc > 0) + name = argv[0]; + + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, name); if (!srep) { - srep = osmo_stats_reporter_create_log(NULL); + srep = osmo_stats_reporter_create_log(name); if (!srep) { vty_out(vty, "%% Unable to create log reporter%s", VTY_NEWLINE); @@ -335,12 +353,18 @@ } 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") + "no stats reporter log [NAME]", + NO_STR CFG_STATS_STR CFG_REPORTER_STR + "Report to the logger\n" + "Name of the reporter\n") { struct osmo_stats_reporter *srep; + const char *name = NULL; - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); + if (argc > 0) + name = argv[0]; + + srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, name); if (!srep) { vty_out(vty, "%% No log reporting active%s", VTY_NEWLINE); @@ -598,18 +622,22 @@ static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep) { - if (srep == NULL) - return 0; + const char *type = NULL; switch (srep->type) { case OSMO_STATS_REPORTER_STATSD: - vty_out(vty, "stats reporter statsd%s", VTY_NEWLINE); + type = "statsd"; break; case OSMO_STATS_REPORTER_LOG: - vty_out(vty, "stats reporter log%s", VTY_NEWLINE); + type = "log"; break; } + vty_out(vty, "stats reporter %s", type); + if (srep->name != NULL) + vty_out(vty, " %s", srep->name); + vty_out(vty, "%s", VTY_NEWLINE); + vty_out(vty, " disable%s", VTY_NEWLINE); if (srep->have_net_config) { @@ -652,11 +680,9 @@ { struct osmo_stats_reporter *srep; - /* TODO: loop through all reporters */ - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_STATSD, NULL); - config_write_stats_reporter(vty, srep); - srep = osmo_stats_reporter_find(OSMO_STATS_REPORTER_LOG, NULL); - config_write_stats_reporter(vty, srep); + /* Loop through all reporters */ + llist_for_each_entry(srep, &osmo_stats_reporter_list, list) + config_write_stats_reporter(vty, srep); vty_out(vty, "stats interval %d%s", osmo_stats_config->interval, VTY_NEWLINE); diff --git a/tests/stats/stats_vty_test.vty b/tests/stats/stats_vty_test.vty index 4ec03c9..017b188 100644 --- a/tests/stats/stats_vty_test.vty +++ b/tests/stats/stats_vty_test.vty @@ -2,10 +2,10 @@ stats_vty_test# configure terminal stats_vty_test(config)# list ... - stats reporter statsd - no stats reporter statsd - stats reporter log - no stats reporter log + stats reporter statsd [NAME] + no stats reporter statsd [NAME] + stats reporter log [NAME] + no stats reporter log [NAME] stats interval <0-65535> ... @@ -148,6 +148,72 @@ ... +stats_vty_test(config)# ### Create an additional statsd reporter +stats_vty_test(config)# stats reporter statsd statsd-foo +stats_vty_test(config-stats)# level global +stats_vty_test(config-stats)# prefix statsd-one-prefix +stats_vty_test(config-stats)# remote-ip 192.168.2.200 +stats_vty_test(config-stats)# remote-port 9696 +stats_vty_test(config-stats)# flush-period 1 +stats_vty_test(config-stats)# exit + +stats_vty_test(config)# ### Create an additional log reporter +stats_vty_test(config)# stats reporter log log-bar +stats_vty_test(config-stats)# level global +stats_vty_test(config-stats)# prefix log-bar-prefix +stats_vty_test(config-stats)# flush-period 2 +stats_vty_test(config-stats)# exit + +stats_vty_test(config)# ### Create an additional log reporter +stats_vty_test(config)# stats reporter log log-zoo +stats_vty_test(config-stats)# level global +stats_vty_test(config-stats)# prefix log-zoo-prefix +stats_vty_test(config-stats)# flush-period 3 +stats_vty_test(config-stats)# exit + +stats_vty_test(config)# ### We should have 5 reporters now +stats_vty_test(config)# show running-config +... +stats reporter statsd + disable + remote-ip 192.168.1.200 + remote-port 6969 + level subscriber + prefix statsd-prefix + enable +stats reporter log + disable + level peer + prefix log-prefix + enable +stats reporter statsd statsd-foo + disable + remote-ip 192.168.2.200 + remote-port 9696 + level global + prefix statsd-one-prefix + flush-period 1 +stats reporter log log-bar + disable + level global + prefix log-bar-prefix + flush-period 2 +stats reporter log log-zoo + disable + level global + prefix log-zoo-prefix + flush-period 3 +... + + +stats_vty_test(config)# ### Test removing reporters +stats_vty_test(config)# no stats reporter statsd statsd-foo +stats_vty_test(config)# no stats reporter log log-bar +stats_vty_test(config)# no stats reporter log log-zoo +stats_vty_test(config)# show running-config +... !(foo|bar|zoo) + + stats_vty_test(config)# stats interval 1337 stats_vty_test(config)# show running-config ... -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/26171 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Ia815c24dc974648985539913012b3b074ea317a9 Gerrit-Change-Number: 26171 Gerrit-PatchSet: 1 Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20211109/e3acec82/attachment.htm>