summaryrefslogtreecommitdiffstats
path: root/src/stats.c
diff options
context:
space:
mode:
authorJacob Erlbeck <jerlbeck@sysmocom.de>2015-10-28 21:47:45 +0100
committerJacob Erlbeck <jerlbeck@sysmocom.de>2015-10-29 01:10:07 +0100
commitbc4f7ae512b32fa4b569dfc5242d0b7a5da3f81b (patch)
tree26754f63d142105a9b6939efe4378c2c2c6eff9d /src/stats.c
parent490b38f57a24726f3e3493fc3500cda526c5d0aa (diff)
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
Diffstat (limited to 'src/stats.c')
-rw-r--r--src/stats.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/stats.c b/src/stats.c
index f4c0b623..5027a621 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -68,6 +68,14 @@ static int stats_reporter_statsd_send_item(struct stats_reporter *srep,
const struct stat_item_group *statg,
const struct stat_item_desc *desc, int value);
+static int stats_reporter_log_send_counter(struct stats_reporter *srep,
+ const struct rate_ctr_group *ctrg,
+ const struct rate_ctr_desc *desc,
+ int64_t value, int64_t delta);
+static int stats_reporter_log_send_item(struct stats_reporter *srep,
+ const struct stat_item_group *statg,
+ const struct stat_item_desc *desc, int value);
+
static int stats_reporter_send(struct stats_reporter *srep, const char *data,
int data_len);
static int stats_reporter_send_buffer(struct stats_reporter *srep);
@@ -309,6 +317,61 @@ static int stats_reporter_send_buffer(struct stats_reporter *srep)
return rc;
}
+/*** log reporter ***/
+
+struct stats_reporter *stats_reporter_create_log(const char *name)
+{
+ struct stats_reporter *srep;
+ srep = stats_reporter_alloc(STATS_REPORTER_LOG, name);
+
+ srep->have_net_config = 0;
+
+ srep->send_counter = stats_reporter_log_send_counter;
+ srep->send_item = stats_reporter_log_send_item;
+
+ return srep;
+}
+
+static int stats_reporter_log_send(struct stats_reporter *srep,
+ const char *type,
+ const char *name1, int index1, const char *name2, int value,
+ const char *unit)
+{
+ LOGP(DSTATS, LOGL_INFO,
+ "stats t=%s p=%s g=%s i=%d n=%s v=%d u=%s\n",
+ type, srep->name_prefix ? srep->name_prefix : "",
+ name1 ? name1 : "", index1,
+ name2, value, unit ? unit : "");
+
+ return 0;
+}
+
+
+static int stats_reporter_log_send_counter(struct stats_reporter *srep,
+ const struct rate_ctr_group *ctrg,
+ const struct rate_ctr_desc *desc,
+ int64_t value, int64_t delta)
+{
+ if (ctrg)
+ return stats_reporter_log_send(srep, "c",
+ ctrg->desc->group_name_prefix,
+ ctrg->idx,
+ desc->name, value, NULL);
+ else
+ return stats_reporter_log_send(srep, "c",
+ NULL, -1,
+ desc->name, value, NULL);
+}
+
+static int stats_reporter_log_send_item(struct stats_reporter *srep,
+ const struct stat_item_group *statg,
+ const struct stat_item_desc *desc, int value)
+{
+ return stats_reporter_log_send(srep, "i",
+ statg->desc->group_name_prefix, statg->idx,
+ desc->name, value, desc->unit);
+}
+
/*** statsd reporter ***/
struct stats_reporter *stats_reporter_create_statsd(const char *name)