-
Notifications
You must be signed in to change notification settings - Fork 3
/
runtime.go
34 lines (27 loc) · 871 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
package metric
import (
"bufio"
"fmt"
"runtime"
"time"
)
var startTime time.Time
func init() {
startTime = time.Now()
}
func StartTime() time.Time {
return startTime
}
type Runtime struct{}
var _ = Metrical(&Runtime{})
func (*Runtime) CollectMetrics(w *bufio.Writer) {
_, _ = w.WriteString(fmt.Sprintf("Uptime: %v (since %v)\n", time.Since(startTime), startTime))
_, _ = w.WriteString(fmt.Sprintln("Num CPU:", runtime.NumCPU()))
_, _ = w.WriteString(fmt.Sprintln("Num Goroutines:", runtime.NumGoroutine()))
var memstats runtime.MemStats
runtime.ReadMemStats(&memstats)
_, _ = w.WriteString(fmt.Sprintln("Heap Used:", memstats.Alloc))
_, _ = w.WriteString(fmt.Sprintln("Heap Allocated:", memstats.Sys))
_, _ = w.WriteString(fmt.Sprintln("Stack Used:", memstats.StackInuse))
_, _ = w.WriteString(fmt.Sprintln("Stack Allocated:", memstats.StackSys))
}