mirror of https://gerrit.osmocom.org/libosmocore
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
This commit is contained in:
parent
4e92472281
commit
bfc8377398
|
@ -108,6 +108,7 @@ struct osmo_stats_config {
|
|||
int interval;
|
||||
};
|
||||
|
||||
extern struct llist_head osmo_stats_reporter_list;
|
||||
extern struct osmo_stats_config *osmo_stats_config;
|
||||
|
||||
void osmo_stats_init(void *ctx);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -269,14 +269,20 @@ DEFUN(cfg_stats_reporter_flush_period, cfg_stats_reporter_flush_period_cmd,
|
|||
}
|
||||
|
||||
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_stats_reporter_statsd, cfg_stats_reporter_statsd_cmd,
|
|||
}
|
||||
|
||||
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_no_stats_reporter_statsd, cfg_no_stats_reporter_statsd_cmd,
|
|||
}
|
||||
|
||||
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_stats_reporter_log, cfg_stats_reporter_log_cmd,
|
|||
}
|
||||
|
||||
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 @@ DEFUN(stats_reset,
|
|||
|
||||
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 @@ static int config_write_stats(struct vty *vty)
|
|||
{
|
||||
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);
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ stats_vty_test> en
|
|||
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 reporter log
|
|||
...
|
||||
|
||||
|
||||
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
|
||||
...
|
||||
|
|
Loading…
Reference in New Issue