Skip to content

Commit

Permalink
added range
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Feb 11, 2020
1 parent ebc7e7f commit 5f9d1b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ This golang package is used for monitoring [emitter.io](emitter.io) cluster. Thi

[![Join the chat at https://gitter.im/emitter-io/public](https://badges.gitter.im/emitter-io/public.svg)](https://gitter.im/emitter-io/public?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Build status](https://ci.appveyor.com/api/projects/status/3y2d9ssq760g8bfd?svg=true)](https://ci.appveyor.com/project/Kelindar/stats)
[![Coverage Status](https://coveralls.io/repos/github/emitter-io/stats/badge.svg?branch=master)](https://coveralls.io/github/emitter-io/emitter?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/emitter-io/stats/badge.svg?branch=master)](https://coveralls.io/github/emitter-io/stats?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/emitter-io/stats)](https://goreportcard.com/report/github.com/emitter-io/stats)

## Installation
Expand Down
11 changes: 9 additions & 2 deletions monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func (m *Monitor) Tag(name, tag string) {
// Snapshot encodes the metrics into a binary representation
func (m *Monitor) Snapshot() (out []byte) {
var snapshots []Snapshot
m.registry.Range(func(k, v interface{}) bool {
metric := v.(*Metric)
m.Range(func(metric *Metric) bool {
snapshots = append(snapshots, *metric.Snapshot())
metric.Reset()
return true
Expand All @@ -85,6 +84,14 @@ func (m *Monitor) Snapshot() (out []byte) {
return
}

// Range ranges over all the metrics in the monitor. The iteration stops if the function
// returns false, similar to sync.Map
func (m *Monitor) Range(f func(*Metric) bool) {
m.registry.Range(func(k, v interface{}) bool {
return f(v.(*Metric))
})
}

// MeasureRuntime captures the runtime metrics, this is a relatively slow process
// and code is largely inspired by go-metrics.
func (m *Monitor) MeasureRuntime() {
Expand Down

0 comments on commit 5f9d1b1

Please sign in to comment.