forked from abh/geodns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.go
49 lines (35 loc) · 1009 Bytes
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"runtime"
"time"
metrics "github.com/abh/geodns/Godeps/_workspace/src/github.com/rcrowley/go-metrics"
)
type ServerMetrics struct {
qCounter metrics.Meter
lastQueryCount int64
queriesHistogram metrics.Histogram
goroutines metrics.Gauge
}
func NewMetrics() *ServerMetrics {
m := new(ServerMetrics)
m.qCounter = metrics.GetOrRegisterMeter("queries", nil)
m.lastQueryCount = m.qCounter.Count()
m.queriesHistogram = metrics.GetOrRegisterHistogram(
"queries-histogram", nil,
metrics.NewExpDecaySample(600, 0.015),
)
m.goroutines = metrics.GetOrRegisterGauge("goroutines", nil)
return m
}
func (m *ServerMetrics) Updater() {
for {
time.Sleep(1 * time.Second)
// Make sure go-metrics get some input to update the rate
m.qCounter.Mark(0)
current := m.qCounter.Count()
newQueries := current - m.lastQueryCount
m.lastQueryCount = current
m.queriesHistogram.Update(newQueries)
m.goroutines.Update(int64(runtime.NumGoroutine()))
}
}