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 Feb 20, 2023
1 parent 8601303 commit b485b22
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions metrics/registry.go
Expand Up @@ -71,6 +71,23 @@ func (r *Registry) MustNewMetric(name string, typ MetricType, t ...ValueType) *M
return m
}

// All returns all the metrics registered.
//
// TODO: add a unit test
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 b485b22

Please sign in to comment.