forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
periodic.go
114 lines (100 loc) · 2.16 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package metric
import (
"runtime"
"time"
"code.cloudfoundry.org/lager"
"github.com/bigdatadev/goryman"
)
func PeriodicallyEmit(logger lager.Logger, interval time.Duration) {
ticker := time.NewTicker(interval)
defer ticker.Stop()
for range ticker.C {
tLog := logger.Session("tick")
trackedContainers := TrackedContainers.Max()
trackedVolumes := TrackedVolumes.Max()
databaseQueries := DatabaseQueries.Delta()
databaseConnections := DatabaseConnections.Max()
emit(
tLog.Session("tracked-containers", lager.Data{
"count": trackedContainers,
}),
goryman.Event{
Service: "tracked containers",
Metric: trackedContainers,
State: "ok",
},
)
emit(
tLog.Session("tracked-volumes", lager.Data{
"count": trackedVolumes,
}),
goryman.Event{
Service: "tracked volumes",
Metric: trackedVolumes,
State: "ok",
},
)
emit(
tLog.Session("database-queries", lager.Data{
"count": databaseQueries,
}),
goryman.Event{
Service: "database queries",
Metric: databaseQueries,
State: "ok",
},
)
emit(
tLog.Session("database-connections", lager.Data{
"count": databaseConnections,
}),
goryman.Event{
Service: "database connections",
Metric: databaseConnections,
State: "ok",
},
)
var memStats runtime.MemStats
runtime.ReadMemStats(&memStats)
emit(
tLog.Session("gc-pause-total-duration", lager.Data{
"ns": memStats.PauseTotalNs,
}),
goryman.Event{
Service: "gc pause total duration",
Metric: int(memStats.PauseTotalNs),
State: "ok",
},
)
emit(
tLog.Session("mallocs", lager.Data{
"count": memStats.Mallocs,
}),
goryman.Event{
Service: "mallocs",
Metric: int(memStats.Mallocs),
State: "ok",
},
)
emit(
tLog.Session("frees", lager.Data{
"count": memStats.Frees,
}),
goryman.Event{
Service: "frees",
Metric: int(memStats.Frees),
State: "ok",
},
)
emit(
tLog.Session("goroutines", lager.Data{
"count": runtime.NumGoroutine(),
}),
goryman.Event{
Service: "goroutines",
Metric: int(runtime.NumGoroutine()),
State: "ok",
},
)
}
}