Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #37 from filecoin-saturn/metrics/pool
Browse files Browse the repository at this point in the history
add a metric of pool health
  • Loading branch information
aarshkshah1992 authored Feb 21, 2023
2 parents ebf9e25 + ce694ea commit 6fde809
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ var (
Help: "Number of active caboose peers",
})

poolHealthMetric = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "pool_health"),
Help: "Health of the caboose pool",
}, []string{"weight"})

fetchResponseMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: prometheus.BuildFQName("ipfs", "caboose", "fetch_errors"),
Help: "Errors fetching from Caboose Peers",
Expand All @@ -42,6 +47,7 @@ var (
func init() {
CabooseMetrics.MustRegister(poolErrorMetric)
CabooseMetrics.MustRegister(poolSizeMetric)
CabooseMetrics.MustRegister(poolHealthMetric)
CabooseMetrics.MustRegister(fetchResponseMetric)
CabooseMetrics.MustRegister(fetchSpeedMetric)
CabooseMetrics.MustRegister(fetchLatencyMetric)
Expand Down
15 changes: 15 additions & 0 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ func (p *pool) doRefresh() {
}
p.lk.Unlock()
poolSizeMetric.Set(float64(len(n)))

// periodic update of a pool health metric
p.lk.RLock()
byWeight := make(map[int]int)
for _, m := range p.endpoints {
if _, ok := byWeight[m.replication]; !ok {
byWeight[m.replication] = 0
}
byWeight[m.replication] += 1
}
poolHealthMetric.Reset()
for weight, cnt := range byWeight {
poolHealthMetric.WithLabelValues(fmt.Sprintf("%d", weight)).Set(float64(cnt))
}
p.lk.RUnlock()
} else {
poolErrorMetric.Add(1)
}
Expand Down

0 comments on commit 6fde809

Please sign in to comment.