2018-02-23 09:56:08 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-04-23 14:43:00 +00:00
|
|
|
"io"
|
2018-02-23 09:56:08 +00:00
|
|
|
"log"
|
2018-03-01 17:55:31 +00:00
|
|
|
"time"
|
2018-02-23 09:56:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Stop the compiler from complaining during debugging.
|
|
|
|
var (
|
2022-04-23 14:43:00 +00:00
|
|
|
_ = io.Discard
|
2018-02-23 09:56:08 +00:00
|
|
|
_ = log.LstdFlags
|
|
|
|
)
|
|
|
|
|
|
|
|
func Example() {
|
|
|
|
c := NewCounter()
|
|
|
|
Register("money", c)
|
|
|
|
c.Inc(17)
|
|
|
|
|
|
|
|
// Threadsafe registration
|
|
|
|
t := GetOrRegisterTimer("db.get.latency", nil)
|
2018-03-01 17:55:31 +00:00
|
|
|
t.Time(func() { time.Sleep(10 * time.Millisecond) })
|
2018-02-23 09:56:08 +00:00
|
|
|
t.Update(1)
|
|
|
|
|
|
|
|
fmt.Println(c.Count())
|
|
|
|
fmt.Println(t.Min())
|
|
|
|
// Output: 17
|
|
|
|
// 1
|
|
|
|
}
|