forked from google/cloudprober
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntime.go
57 lines (47 loc) · 1.79 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package sysvars
import (
"runtime"
"time"
"github.com/google/cloudprober/logger"
"github.com/google/cloudprober/metrics"
)
func runtimeVars(dataChan chan *metrics.EventMetrics, l *logger.Logger) {
m := &runtime.MemStats{}
runtime.ReadMemStats(m)
ts := time.Now()
osRuntimeVars(dataChan, l)
counterRuntimeVars(dataChan, ts, m, l)
gaugeRuntimeVars(dataChan, ts, m, l)
}
// counterRuntimeVars exports counter runtime stats, stats that grow through
// the lifetime of the process. These stats are exported as CUMULATIVE
// EventMetrics.
func counterRuntimeVars(dataChan chan *metrics.EventMetrics, ts time.Time, m *runtime.MemStats, l *logger.Logger) {
em := metrics.NewEventMetrics(ts).
AddLabel("ptype", "sysvars").
AddLabel("probe", "sysvars")
// Time since this module started.
timeSince := time.Since(startTime).Seconds()
em.AddMetric("uptime_msec", metrics.NewFloat(timeSince*1000))
// GC memory stats
em.AddMetric("gc_time_msec", metrics.NewFloat(float64(m.PauseTotalNs)/1e6))
em.AddMetric("mallocs", metrics.NewInt(int64(m.Mallocs)))
em.AddMetric("frees", metrics.NewInt(int64(m.Frees)))
dataChan <- em
l.Info(em.String())
}
// gaugeRuntimeVars exports gauge runtime stats, stats that represent the
// current state and may go up or down. These stats are exported as GAUGE
// EventMetrics.
func gaugeRuntimeVars(dataChan chan *metrics.EventMetrics, ts time.Time, m *runtime.MemStats, l *logger.Logger) {
em := metrics.NewEventMetrics(ts).
AddLabel("ptype", "sysvars").
AddLabel("probe", "sysvars")
em.Kind = metrics.GAUGE
// Number of goroutines
em.AddMetric("goroutines", metrics.NewInt(int64(runtime.NumGoroutine())))
// Overall memory being used by the Go runtime (in bytes).
em.AddMetric("mem_stats_sys_bytes", metrics.NewInt(int64(m.Sys)))
dataChan <- em
l.Info(em.String())
}