aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/Xe/gopreload/sample/runtimeStatLogs/main.go
blob: ac530e0d20a700bf6d788a75fd64a8891efbe55c (plain)
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
package main

import (
	"runtime"
	"time"

	"github.com/Xe/ln"
)

func init() {
	ln.Log(ln.F{
		"action": "started_up",
		"every":  "20_seconds",
		"what":   "gc_metrics",
	})

	go func() {
		for {
			time.Sleep(20 * time.Second)
			gatherMetrics()
		}
	}()
}

func gatherMetrics() {
	stats := &runtime.MemStats{}
	runtime.ReadMemStats(stats)

	ln.Log(ln.F{
		"gc-collections":     stats.NumGC,
		"gc-stw-pause-total": stats.PauseTotalNs,
		"live-object-count":  stats.Mallocs - stats.Frees,
		"heap-bytes":         stats.Alloc,
		"stack-bytes":        stats.StackInuse,
	})
}