forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
periodic.go
135 lines (118 loc) · 2.35 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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")
emit(
tLog.Session("database-queries"),
Event{
Name: "database queries",
Value: DatabaseQueries.Delta(),
State: EventStateOK,
},
)
if len(Databases) > 0 {
for _, database := range Databases {
emit(
tLog.Session("database-connections"),
Event{
Name: "database connections",
Value: database.Stats().OpenConnections,
State: EventStateOK,
Attributes: map[string]string{
"ConnectionName": database.Name(),
},
},
)
}
}
emit(
logger.Session("containers-deleted"),
Event{
Name: "containers deleted",
Value: ContainersDeleted.Delta(),
State: EventStateOK,
},
)
emit(
logger.Session("volumes-deleted"),
Event{
Name: "volumes deleted",
Value: VolumesDeleted.Delta(),
State: EventStateOK,
},
)
emit(
logger.Session("containers-created"),
Event{
Name: "containers created",
Value: ContainersCreated.Delta(),
State: EventStateOK,
},
)
emit(
logger.Session("volumes-created"),
Event{
Name: "volumes created",
Value: VolumesCreated.Delta(),
State: EventStateOK,
},
)
emit(
logger.Session("failed-containers"),
Event{
Name: "failed containers",
Value: FailedContainers.Delta(),
State: EventStateOK,
},
)
emit(
logger.Session("failed-volumes"),
Event{
Name: "failed volumes",
Value: FailedVolumes.Delta(),
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,
},
)
}
}