From 1dea032365c9cdff40e49c6681c330650e74b219 Mon Sep 17 00:00:00 2001 From: Evgenii Lepikhin Date: Fri, 29 Dec 2023 12:30:24 +0300 Subject: [PATCH 1/2] feat: Collect more metrics from LTE interfaces --- collector/lte_collector.go | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/collector/lte_collector.go b/collector/lte_collector.go index 4baf6f60..4d30b655 100644 --- a/collector/lte_collector.go +++ b/collector/lte_collector.go @@ -22,7 +22,7 @@ func newLteCollector() routerOSCollector { } func (c *lteCollector) init() { - c.props = []string{"current-cellid", "primary-band" ,"ca-band", "rssi", "rsrp", "rsrq", "sinr"} + c.props = []string{"current-cellid", "primary-band", "ca-band", "rssi", "rsrp", "rsrq", "sinr", "lac", "sector-id", "phy-cellid", "cqi", "session-uptime"} labelNames := []string{"name", "address", "interface", "cellid", "primaryband", "caband"} c.descriptions = make(map[string]*prometheus.Desc) for _, p := range c.props { @@ -106,16 +106,31 @@ func (c *lteCollector) collectMetricForProperty(property, iface string, re *prot if re.Map[property] == "" { return } - v, err := strconv.ParseFloat(re.Map[property], 64) - if err != nil { - log.WithFields(log.Fields{ - "property": property, - "interface": iface, - "device": ctx.device.Name, - "error": err, - }).Error("error parsing interface metric value") + + if property == "session-uptime" { + v, err := parseDuration(re.Map[property]) + if err != nil { + log.WithFields(log.Fields{ + "property": property, + "interface": iface, + "device": ctx.device.Name, + "error": err, + }).Error("error parsing interface duration metric value") + return + } + ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, iface, current_cellid, primaryband, caband) return + } else { + v, err := strconv.ParseFloat(re.Map[property], 64) + if err != nil { + log.WithFields(log.Fields{ + "property": property, + "interface": iface, + "device": ctx.device.Name, + "error": err, + }).Error("error parsing interface metric value") + return + } + ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address, iface, current_cellid, primaryband, caband) } - - ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address, iface, current_cellid, primaryband, caband) } From 2656afd9a5af09ba7fb7eba7213c58f57cec5d55 Mon Sep 17 00:00:00 2001 From: Evgenii Lepikhin Date: Sun, 14 Jan 2024 14:39:27 +0300 Subject: [PATCH 2/2] fix: Do not throw global error if just one collector failed --- collector/collector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/collector.go b/collector/collector.go index 61e7c3c3..3841a38c 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -354,7 +354,7 @@ func (c *collector) connectAndCollect(d *config.Device, ch chan<- prometheus.Met ctx := &collectorContext{ch, d, cl} err = co.collect(ctx) if err != nil { - return err + log.Error("error collecting metrics") } }