OLD | NEW |
1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 // Package runtimestats exposes metrics related to the Go runtime. | 5 // Package runtimestats exposes metrics related to the Go runtime. |
6 // | 6 // |
7 // It exports the allocator statistics (go/mem/* metrics) and the current number | 7 // It exports the allocator statistics (go/mem/* metrics) and the current number |
8 // of goroutines (go/goroutine/num). | 8 // of goroutines (go/goroutine/num). |
9 // | 9 // |
10 // Should be invoked manually for now. Call Report(c) to populate the metrics | 10 // Should be invoked manually for now. Call Report(c) to populate the metrics |
11 // prior tsmon Flush. | 11 // prior tsmon Flush. |
12 package runtimestats | 12 package runtimestats |
13 | 13 |
14 import ( | 14 import ( |
15 "runtime" | 15 "runtime" |
16 | 16 |
17 "golang.org/x/net/context" | 17 "golang.org/x/net/context" |
18 | 18 |
19 "github.com/luci/luci-go/common/tsmon/metric" | 19 "github.com/luci/luci-go/common/tsmon/metric" |
| 20 "github.com/luci/luci-go/common/tsmon/types" |
20 ) | 21 ) |
21 | 22 |
22 var ( | 23 var ( |
23 // Some per-process memory allocator stats. | 24 // Some per-process memory allocator stats. |
24 // See https://golang.org/pkg/runtime/#MemStats | 25 // See https://golang.org/pkg/runtime/#MemStats |
25 | 26 |
26 » MemAlloc = metric.NewInt("go/mem/alloc", "Bytes allocated and not
yet freed.") | 27 » MemAlloc = metric.NewInt("go/mem/alloc", "Bytes allocated and not
yet freed.", types.MetricMetadata{types.Bytes}) |
27 » MemTotalAlloc = metric.NewCounter("go/mem/total_alloc", "Bytes allocate
d (even if freed).") | 28 » MemTotalAlloc = metric.NewCounter("go/mem/total_alloc", "Bytes allocate
d (even if freed).", types.MetricMetadata{types.Bytes}) |
28 » MemMallocs = metric.NewCounter("go/mem/mallocs", "Number of mallocs.
") | 29 » MemMallocs = metric.NewCounter("go/mem/mallocs", "Number of mallocs.
", types.MetricMetadata{}) |
29 » MemFrees = metric.NewCounter("go/mem/frees", "Number of frees.") | 30 » MemFrees = metric.NewCounter("go/mem/frees", "Number of frees.", t
ypes.MetricMetadata{}) |
30 » MemNextGC = metric.NewInt("go/mem/next_gc", "Next GC will happen wh
en go/mem/alloc > this amount.") | 31 » MemNextGC = metric.NewInt("go/mem/next_gc", "Next GC will happen wh
en go/mem/alloc > this amount.", types.MetricMetadata{}) |
31 » MemNumGC = metric.NewCounter("go/mem/num_gc", "Number of garbage c
ollections.") | 32 » MemNumGC = metric.NewCounter("go/mem/num_gc", "Number of garbage c
ollections.", types.MetricMetadata{}) |
32 » MemPauseTotal = metric.NewCounter("go/mem/pause_total", "Total GC pause
, in microseconds.") | 33 » MemPauseTotal = metric.NewCounter("go/mem/pause_total", "Total GC pause
, in microseconds.", types.MetricMetadata{}) |
33 » MemHeapSys = metric.NewInt("go/mem/heap_sys", "Bytes obtained from s
ystem.") | 34 » MemHeapSys = metric.NewInt("go/mem/heap_sys", "Bytes obtained from s
ystem.", types.MetricMetadata{types.Bytes}) |
34 » MemHeapIdle = metric.NewInt("go/mem/heap_idle", "Bytes in idle spans.
") | 35 » MemHeapIdle = metric.NewInt("go/mem/heap_idle", "Bytes in idle spans.
", types.MetricMetadata{types.Bytes}) |
35 » MemHeapInuse = metric.NewInt("go/mem/heap_in_use", "Bytes in non-idle
span.") | 36 » MemHeapInuse = metric.NewInt("go/mem/heap_in_use", "Bytes in non-idle
span.", types.MetricMetadata{types.Bytes}) |
36 » MemHeapObjects = metric.NewCounter("go/mem/heap_objects", "total number
of allocated objects.") | 37 » MemHeapObjects = metric.NewCounter("go/mem/heap_objects", "total number
of allocated objects.", types.MetricMetadata{}) |
37 » MemStackInuse = metric.NewInt("go/mem/stack_in_use", "Bytes used by sta
ck allocator.") | 38 » MemStackInuse = metric.NewInt("go/mem/stack_in_use", "Bytes used by sta
ck allocator.", types.MetricMetadata{types.Bytes}) |
38 » MemStackSys = metric.NewInt("go/mem/stack_in_sys", "Bytes allocated t
o stack allocator.") | 39 » MemStackSys = metric.NewInt("go/mem/stack_in_sys", "Bytes allocated t
o stack allocator.", types.MetricMetadata{types.Bytes}) |
39 » MemMSpanInuse = metric.NewInt("go/mem/mspan_in_use", "Bytes used by msp
an structures.") | 40 » MemMSpanInuse = metric.NewInt("go/mem/mspan_in_use", "Bytes used by msp
an structures.", types.MetricMetadata{types.Bytes}) |
40 » MemMSpanSys = metric.NewInt("go/mem/mspan_in_sys", "Bytes allocated t
o mspan structures.") | 41 » MemMSpanSys = metric.NewInt("go/mem/mspan_in_sys", "Bytes allocated t
o mspan structures.", types.MetricMetadata{types.Bytes}) |
41 » MemMCacheInuse = metric.NewInt("go/mem/mcache_in_use", "Bytes used by mc
ache structures.") | 42 » MemMCacheInuse = metric.NewInt("go/mem/mcache_in_use", "Bytes used by mc
ache structures.", types.MetricMetadata{types.Bytes}) |
42 » MemMCacheSys = metric.NewInt("go/mem/mcache_in_sys", "Bytes allocated
to mcache structures.") | 43 » MemMCacheSys = metric.NewInt("go/mem/mcache_in_sys", "Bytes allocated
to mcache structures.", types.MetricMetadata{types.Bytes}) |
43 | 44 |
44 // Other runtime stats. | 45 // Other runtime stats. |
45 | 46 |
46 » GoroutineNum = metric.NewInt("go/goroutine/num", "The number of goroutin
es that currently exist.") | 47 » GoroutineNum = metric.NewInt("go/goroutine/num", "The number of goroutin
es that currently exist.", types.MetricMetadata{}) |
47 ) | 48 ) |
48 | 49 |
49 // Report updates runtime stats metrics. | 50 // Report updates runtime stats metrics. |
50 // | 51 // |
51 // Call it periodically (ideally right before flushing the metrics) to gather | 52 // Call it periodically (ideally right before flushing the metrics) to gather |
52 // runtime stats metrics. | 53 // runtime stats metrics. |
53 func Report(c context.Context) { | 54 func Report(c context.Context) { |
54 var stats runtime.MemStats | 55 var stats runtime.MemStats |
55 runtime.ReadMemStats(&stats) | 56 runtime.ReadMemStats(&stats) |
56 | 57 |
(...skipping 10 matching lines...) Expand all Loading... |
67 MemHeapObjects.Set(c, int64(stats.HeapObjects)) | 68 MemHeapObjects.Set(c, int64(stats.HeapObjects)) |
68 MemStackInuse.Set(c, int64(stats.StackInuse)) | 69 MemStackInuse.Set(c, int64(stats.StackInuse)) |
69 MemStackSys.Set(c, int64(stats.StackSys)) | 70 MemStackSys.Set(c, int64(stats.StackSys)) |
70 MemMSpanInuse.Set(c, int64(stats.MSpanInuse)) | 71 MemMSpanInuse.Set(c, int64(stats.MSpanInuse)) |
71 MemMSpanSys.Set(c, int64(stats.MSpanSys)) | 72 MemMSpanSys.Set(c, int64(stats.MSpanSys)) |
72 MemMCacheInuse.Set(c, int64(stats.MCacheInuse)) | 73 MemMCacheInuse.Set(c, int64(stats.MCacheInuse)) |
73 MemMCacheSys.Set(c, int64(stats.MCacheSys)) | 74 MemMCacheSys.Set(c, int64(stats.MCacheSys)) |
74 | 75 |
75 GoroutineNum.Set(c, int64(runtime.NumGoroutine())) | 76 GoroutineNum.Set(c, int64(runtime.NumGoroutine())) |
76 } | 77 } |
OLD | NEW |