Skip to content

Commit

Permalink
metrics: Return all registered metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
codebien committed May 11, 2023
1 parent c00bfbb commit 3c26712
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions metrics/registry.go
Expand Up @@ -71,6 +71,21 @@ func (r *Registry) MustNewMetric(name string, typ MetricType, t ...ValueType) *M
return m
}

// All returns all the registered metrics.
func (r *Registry) All() []*Metric {
r.l.RLock()
defer r.l.RUnlock()

if len(r.metrics) < 1 {
return nil
}
s := make([]*Metric, 0, len(r.metrics))
for _, m := range r.metrics {
s = append(s, m)
}
return s
}

func (r *Registry) newMetric(name string, mt MetricType, vt ...ValueType) *Metric {
valueType := Default
if len(vt) > 0 {
Expand Down

0 comments on commit 3c26712

Please sign in to comment.