Change in libosmocore[master]: stats: Add stats commands related to testing

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/.

daniel gerrit-no-reply at lists.osmocom.org
Thu Jul 16 10:44:15 UTC 2020


daniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/19296 )


Change subject: stats: Add stats commands related to testing
......................................................................

stats: Add stats commands related to testing

* Allow to set the reporting interval to 0 for manual reporting
* stats reset command to reset all statistics
* stats report command to manually trigger statistics reporting

Change-Id: I9febcb65650abfd538caedfbca77a787e66d517a
Related: SYS#4877
---
M src/stats.c
M src/vty/stats_vty.c
2 files changed, 53 insertions(+), 8 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/96/19296/1

diff --git a/src/stats.c b/src/stats.c
index a5a4d4b..c91a978 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -181,12 +181,21 @@
 	if (rc < 0)
 		LOGP(DLSTATS, LOGL_ERROR, "Failed to setup the timer with error code %d (fd=%d)\n",
 		     rc, osmo_stats_timer.fd);
-	rc = osmo_timerfd_schedule(&osmo_stats_timer, &ts_first, &ts_interval);
-	if (rc < 0)
-		LOGP(DLSTATS, LOGL_ERROR, "Failed to schedule the timer with error code %d (fd=%d, interval %d sec)\n",
-		     rc, osmo_stats_timer.fd, interval);
 
-	LOGP(DLSTATS, LOGL_INFO, "Stats timer started with interval %d sec\n", interval);
+        if (interval == 0) {
+		rc = osmo_timerfd_disable(&osmo_stats_timer);
+		if (rc < 0)
+			LOGP(DLSTATS, LOGL_ERROR, "Failed to disable the timer with error code %d (fd=%d)\n",
+			     rc, osmo_stats_timer.fd);
+        } else {
+
+		rc = osmo_timerfd_schedule(&osmo_stats_timer, &ts_first, &ts_interval);
+		if (rc < 0)
+			LOGP(DLSTATS, LOGL_ERROR, "Failed to schedule the timer with error code %d (fd=%d, interval %d sec)\n",
+			rc, osmo_stats_timer.fd, interval);
+
+		LOGP(DLSTATS, LOGL_INFO, "Stats timer started with interval %d sec\n", interval);
+	}
 
 	return 0;
 }
@@ -361,7 +370,7 @@
  *  \returns 0 on success; negative on error */
 int osmo_stats_set_interval(int interval)
 {
-	if (interval <= 0)
+	if (interval < 0)
 		return -EINVAL;
 
 	osmo_stats_config->interval = interval;
diff --git a/src/vty/stats_vty.c b/src/vty/stats_vty.c
index 4628281..83a8a5f 100644
--- a/src/vty/stats_vty.c
+++ b/src/vty/stats_vty.c
@@ -43,6 +43,8 @@
 
 #define SHOW_STATS_STR "Show statistical values\n"
 
+#define STATS_STR "Stats related commands\n"
+
 /*! \file stats_vty.c
  *  VTY interface for statsd / statistic items
  *
@@ -351,9 +353,9 @@
 }
 
 DEFUN(cfg_stats_interval, cfg_stats_interval_cmd,
-	"stats interval <1-65535>",
+	"stats interval <0-65535>",
 	CFG_STATS_STR "Set the reporting interval\n"
-	"Interval in seconds\n")
+	"Interval in seconds (set to 0 for manual reporting)\n")
 {
 	int rc;
 	int interval = atoi(argv[0]);
@@ -567,6 +569,37 @@
 	return CMD_SUCCESS;
 }
 
+DEFUN(stats_report,
+      stats_report_cmd,
+      "stats report",
+      STATS_STR "Report all stats\n")
+{
+        osmo_stats_report();
+	return CMD_SUCCESS;
+}
+
+static int reset_rate_ctr_group_handler(struct rate_ctr_group *ctrg, void *sctx_)
+{
+        rate_ctr_reset_group(ctrg);
+        return 0;
+}
+
+static int reset_osmo_stat_item_group_handler(struct osmo_stat_item_group *statg, void *sctx_)
+{
+        osmo_stat_item_reset_group(statg);
+        return 0;
+}
+
+DEFUN(stats_reset,
+      stats_reset_cmd,
+      "stats reset",
+      STATS_STR "Reset all stats\n")
+{
+        rate_ctr_for_each_group(reset_rate_ctr_group_handler, NULL);
+        osmo_stat_item_for_each_group(reset_osmo_stat_item_group_handler, NULL);
+	return CMD_SUCCESS;
+}
+
 static int config_write_stats_reporter(struct vty *vty, struct osmo_stats_reporter *srep)
 {
 	if (srep == NULL)
@@ -666,4 +699,7 @@
 
 	install_element_ve(&show_stats_asciidoc_table_cmd);
 	install_element_ve(&show_rate_counters_cmd);
+
+        install_element(ENABLE_NODE, &stats_report_cmd);
+        install_element(ENABLE_NODE, &stats_reset_cmd);
 }

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/19296
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I9febcb65650abfd538caedfbca77a787e66d517a
Gerrit-Change-Number: 19296
Gerrit-PatchSet: 1
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200716/45f26b63/attachment.htm>


More information about the gerrit-log mailing list