From 59b0466941f6f358f686ae98f02fd1fdb9f2d872 Mon Sep 17 00:00:00 2001 From: Anand Singh Kunwar Date: Thu, 13 Sep 2018 17:28:03 +0530 Subject: [PATCH] Fixed registrar stats for beats >= 6.3 * Previously registrar stats writes didn't have subdivisions of fail, success and total. In newer version of beats they do, adding support for the same. * Also adding error details on a log line to help in debugging in case of an issue --- VERSION | 2 +- collector/main.go | 2 +- collector/registrar.go | 30 ++++++++++++++++++++++++++---- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/VERSION b/VERSION index 6c6aa7c..17e51c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 \ No newline at end of file +0.1.1 diff --git a/collector/main.go b/collector/main.go index fb59f74..01044aa 100644 --- a/collector/main.go +++ b/collector/main.go @@ -92,7 +92,7 @@ func (b *mainCollector) Collect(ch chan<- prometheus.Metric) { err := b.fetchStatsEndpoint() if err != nil { ch <- prometheus.MustNewConstMetric(b.targetUp, prometheus.GaugeValue, float64(0)) // set target down - log.Errorf("Failed getting /stats endpoint of target") + log.Errorf("Failed getting /stats endpoint of target: " + err.Error()) return } diff --git a/collector/registrar.go b/collector/registrar.go index 83100ee..b68b4b2 100644 --- a/collector/registrar.go +++ b/collector/registrar.go @@ -6,7 +6,11 @@ import ( //Registrar json structure type Registrar struct { - Writes float64 `json:"writes"` + Writes struct { + Fail float64 `json:"fail"` + Success float64 `json:"success"` + Total float64 `json:"total"` + } `json:"writes"` States struct { Cleanup float64 `json:"cleanup"` Current float64 `json:"current"` @@ -30,10 +34,28 @@ func NewRegistrarCollector(beatInfo *BeatInfo, stats *Stats) prometheus.Collecto desc: prometheus.NewDesc( prometheus.BuildFQName(beatInfo.Beat, "registrar", "writes"), "registrar.writes", - nil, nil, + nil, prometheus.Labels{"writes": "fail"}, ), - eval: func(stats *Stats) float64 { return stats.Registrar.Writes }, - valType: prometheus.CounterValue, + eval: func(stats *Stats) float64 { return stats.Registrar.Writes.Fail }, + valType: prometheus.GaugeValue, + }, + { + desc: prometheus.NewDesc( + prometheus.BuildFQName(beatInfo.Beat, "registrar", "writes"), + "registrar.writes", + nil, prometheus.Labels{"writes": "success"}, + ), + eval: func(stats *Stats) float64 { return stats.Registrar.Writes.Success }, + valType: prometheus.GaugeValue, + }, + { + desc: prometheus.NewDesc( + prometheus.BuildFQName(beatInfo.Beat, "registrar", "writes"), + "registrar.writes", + nil, prometheus.Labels{"writes": "total"}, + ), + eval: func(stats *Stats) float64 { return stats.Registrar.Writes.Total }, + valType: prometheus.GaugeValue, }, { desc: prometheus.NewDesc(