diff options
| author | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-10-19 15:11:50 +0200 | 
|---|---|---|
| committer | Jacob Erlbeck <jerlbeck@sysmocom.de> | 2015-10-28 23:53:46 +0100 | 
| commit | 7211fe157e1107d4a9c04a0ecf494a7b9633c400 (patch) | |
| tree | c0a62670c1c6a876e7db4dc09ad98fba1a806a2e /src/vty | |
| parent | aec583f68786f91c3f0d76a8f8706c85aaca07a8 (diff) | |
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
Diffstat (limited to 'src/vty')
| -rw-r--r-- | src/vty/utils.c | 58 | 
1 files changed, 58 insertions, 0 deletions
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 <osmocom/core/rate_ctr.h>  #include <osmocom/core/stat_item.h>  #include <osmocom/core/utils.h> +#include <osmocom/core/statistics.h>  #include <osmocom/vty/vty.h> @@ -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,  | 
