laforge has uploaded this change for review.

View Change

e1d: stat_items for the GPS-DO related bits

It is interesting from a monitoring point of view to be able to
correlate the GPSDO state with other performance counters we export.

While each GPS-DO only exists once per icE1usb, we still export the
state per line, to make it easy for external monitoring to have one set
of counters per line.

Change-Id: I1f98610b7c725146a3f016a8737440be5baae858
---
M src/e1d.h
M src/intf_line.c
M src/usb.c
3 files changed, 45 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/osmo-e1d refs/changes/30/27830/1
diff --git a/src/e1d.h b/src/e1d.h
index 00d2149..42be1b4 100644
--- a/src/e1d.h
+++ b/src/e1d.h
@@ -28,6 +28,7 @@
#include <osmocom/core/isdnhdlc.h>
#include <osmocom/core/linuxlist.h>
#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/stat_item.h>
#include <osmocom/core/timer.h>
#include <osmocom/vty/command.h>

@@ -45,6 +46,8 @@
};

#define line_ctr_add(line, idx, add) rate_ctr_add(rate_ctr_group_get_ctr((line)->ctrs, idx), add)
+#define line_stat_set(line, idx, add) \
+ osmo_stat_item_set(osmo_stat_item_group_get_item((line)->stats, idx), add)

enum e1d_line_ctr {
LINE_CTR_LOS,
@@ -58,6 +61,14 @@
LINE_CTR_FRAMES_DEMUXED_E1O,
};

+enum e1d_line_stat_item {
+ LINE_GPSDO_STATE,
+ LINE_GPSDO_ANTENNA,
+ LINE_GPSDO_TUNE_COARSE,
+ LINE_GPSDO_TUNE_FINE,
+ LINE_GPSDO_FREQ_EST,
+};
+
enum e1_ts_mode {
E1_TS_MODE_OFF = 0,
E1_TS_MODE_RAW,
@@ -118,6 +129,7 @@

void *drv_data;
struct rate_ctr_group *ctrs;
+ struct osmo_stat_item_group *stats;

/* timeslots for channelized mode */
struct e1_ts ts[32];
diff --git a/src/intf_line.c b/src/intf_line.c
index 234f0c0..d12c0df 100644
--- a/src/intf_line.c
+++ b/src/intf_line.c
@@ -35,6 +35,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/stats.h>
#include <osmocom/core/rate_ctr.h>
+#include <osmocom/core/stat_item.h>
#include <osmocom/core/timer.h>
#include <osmocom/e1d/proto.h>

@@ -68,6 +69,23 @@
.ctr_desc = line_ctr_description,
};

+static const struct osmo_stat_item_desc line_stat_description[] = {
+ [LINE_GPSDO_STATE] = { "gpsdo:state", "GPSDO State" },
+ [LINE_GPSDO_ANTENNA] = { "gpsdo:antenna", "GSPDO Antenna State" },
+ [LINE_GPSDO_TUNE_COARSE]= { "gpsdo:tune:coarse", "GSPDO Coarse Tuning" },
+ [LINE_GPSDO_TUNE_FINE] = { "gpsdo:tune:fine", "GSPDO Fine Tuning" },
+ [LINE_GPSDO_FREQ_EST] = { "gpsdo:freq_est", "GSPDO Frequency Estimate" },
+};
+
+static const struct osmo_stat_item_group_desc line_stats_desc = {
+ .group_name_prefix = "e1d_line",
+ .group_description = "Stat items for E1 line",
+ .class_id = OSMO_STATS_CLASS_GLOBAL,
+ .num_items = ARRAY_SIZE(line_stat_description),
+ .item_desc = line_stat_description,
+};
+
+
/* watchdog timer, called once per second to check if we still receive data on the line */
static void line_watchdog_cb(void *data)
{
@@ -253,8 +271,13 @@

line->ctrs = rate_ctr_group_alloc(line, &line_ctrg_desc, intf->id << 8 | line->id);
OSMO_ASSERT(line->ctrs);
+
+ line->stats = osmo_stat_item_group_alloc(line, &line_stats_desc, intf->id << 8 | line->id);
+ OSMO_ASSERT(line->stats);
+
snprintf(name, sizeof(name), "I%u:L%u", intf->id, line->id);
rate_ctr_group_set_name(line->ctrs, name);
+ osmo_stat_item_group_set_name(line->stats, name);

llist_add_tail(&line->list, &intf->lines);

diff --git a/src/usb.c b/src/usb.c
index 1949485..fa6ddee 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -707,6 +707,7 @@
struct e1_usb_intf_data *id = intf->drv_data;
struct e1usb_gpsdo_status *last_st = &id->gpsdo.last_status;
const struct e1usb_gpsdo_status *st;
+ struct e1_line *line;

if (len < sizeof(*st)) {
LOGPIF(intf, DE1D, LOGL_ERROR, "GPSDO status %zu < %zu!\n", len, sizeof(*st));
@@ -742,6 +743,15 @@
LOGPIF(intf, DE1D, LOGL_ERROR, "GPS Fix LOST\n");
}

+ /* update stat_items for statsd / monitoring */
+ llist_for_each_entry(line, &intf->lines, list) {
+ line_stat_set(line, LINE_GPSDO_STATE, st->state);
+ line_stat_set(line, LINE_GPSDO_ANTENNA, st->antenna_state);
+ line_stat_set(line, LINE_GPSDO_TUNE_COARSE, libusb_le16_to_cpu(st->tune.coarse));
+ line_stat_set(line, LINE_GPSDO_TUNE_FINE, libusb_le16_to_cpu(st->tune.fine));
+ line_stat_set(line, LINE_GPSDO_FREQ_EST, osmo_load32le(&st->freq_est));
+ }
+
/* update our state */
memcpy(last_st, st, sizeof(*last_st));
}

To view, visit change 27830. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: osmo-e1d
Gerrit-Branch: master
Gerrit-Change-Id: I1f98610b7c725146a3f016a8737440be5baae858
Gerrit-Change-Number: 27830
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>
Gerrit-MessageType: newchange