forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
periodic.go
77 lines (65 loc) · 1.31 KB
/
periodic.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package metric
import (
"runtime"
"time"
"code.cloudfoundry.org/lager"
)
func PeriodicallyEmit(logger lager.Logger, interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
tLog := logger.Session("tick")
databaseQueries := DatabaseQueries.Delta()
databaseConnections := DatabaseConnections.Max()
emit(
tLog.Session("database-queries"),
Event{
Name: "database queries",
Value: databaseQueries,
State: EventStateOK,
},
)
emit(
tLog.Session("database-connections"),
Event{
Name: "database connections",
Value: databaseConnections,
State: EventStateOK,
},
)
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
emit(
tLog.Session("gc-pause-total-duration"),
Event{
Name: "gc pause total duration",
Value: int(memStats.PauseTotalNs),
State: EventStateOK,
},
)
emit(
tLog.Session("mallocs"),
Event{
Name: "mallocs",
Value: int(memStats.Mallocs),
State: EventStateOK,
},
)
emit(
tLog.Session("frees"),
Event{
Name: "frees",
Value: int(memStats.Frees),
State: EventStateOK,
},
)
emit(
tLog.Session("goroutines"),
Event{
Name: "goroutines",
Value: int(runtime.NumGoroutine()),
State: EventStateOK,
},
)
}
}