forked from Netflix/spectator-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtime.go
42 lines (36 loc) · 956 Bytes
/
runtime.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 spectator
import (
"runtime"
"time"
)
type sysStatsCollector struct {
registry *Registry
curOpen *Gauge
maxOpen *Gauge
numGoroutines *Gauge
}
func goRuntimeStats(s *sysStatsCollector) {
s.numGoroutines.Set(float64(runtime.NumGoroutine()))
}
// Collects system stats: current/max file handles, number of goroutines
func CollectSysStats(registry *Registry) {
var s sysStatsCollector
s.registry = registry
s.maxOpen = registry.Gauge("fh.allocated", nil)
s.curOpen = registry.Gauge("fh.max", nil)
s.numGoroutines = registry.Gauge("go.numGoroutines", nil)
ticker := time.NewTicker(30 * time.Second)
go func() {
log := registry.config.Log
for range ticker.C {
log.Debugf("Collecting system stats")
fdStats(&s)
goRuntimeStats(&s)
}
}()
}
// Starts the collection of memory and file handle metrics
func CollectRuntimeMetrics(registry *Registry) {
CollectMemStats(registry)
CollectSysStats(registry)
}