Skip to content

Commit

Permalink
Fixed registrar stats for beats >= 6.3
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
anandsinghkunwar committed Sep 13, 2018
1 parent 090f990 commit 59b0466
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.1.1
2 changes: 1 addition & 1 deletion collector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
30 changes: 26 additions & 4 deletions collector/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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(
Expand Down

0 comments on commit 59b0466

Please sign in to comment.