-
Notifications
You must be signed in to change notification settings - Fork 3
/
application_metrics.go
42 lines (34 loc) · 1.17 KB
/
application_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
package application
import (
"time"
"github.com/Sirupsen/logrus"
"github.com/rcrowley/go-metrics"
)
func (app *Application) NewMetricsRegistry(handlerInstruments map[string]chan int64, latencyGauges map[string]metrics.Gauge) metrics.Registry {
r := metrics.NewRegistry()
metrics.RegisterDebugGCStats(r)
metrics.RegisterRuntimeMemStats(r)
for handlerName, _ := range handlerInstruments {
latencyGauges[handlerName] = metrics.NewGauge()
r.Register("requests."+handlerName+".ms", latencyGauges[handlerName])
}
go metrics.CaptureDebugGCStats(r, time.Second*60)
go metrics.CaptureRuntimeMemStats(r, time.Second*60)
// Capture request handlers latency
for handlerName, latencyChan := range handlerInstruments {
go func(handlerName string, latencyChan chan int64) {
for latency := range latencyChan {
app.OutLogger.WithFields(logrus.Fields{
"Handler": handlerName,
"NanoSeconds": latency,
"MicroSeconds": latency / 1000,
"MilliSeconds": latency / 1000 / 1000,
}).Info("Capturing latency data")
app.RLock()
latencyGauges[handlerName].Update(latency / 1000 / 1000)
app.RUnlock()
}
}(handlerName, latencyChan)
}
return r
}