goRuntimeMemStats provides the metrics initially provided by runtime.ReadMemStats. From Go 1.17 those similar (and better) statistics are provided by runtime/metrics, so while eval closure works on runtime.MemStats, the struct from Go 1.17+ is populated using runtime/metrics. Those are the defaults
()
| 24 | // while eval closure works on runtime.MemStats, the struct from Go 1.17+ is |
| 25 | // populated using runtime/metrics. Those are the defaults we can't alter. |
| 26 | func goRuntimeMemStats() memStatsMetrics { |
| 27 | return memStatsMetrics{ |
| 28 | { |
| 29 | desc: NewDesc( |
| 30 | memstatNamespace("alloc_bytes"), |
| 31 | "Number of bytes allocated in heap and currently in use. Equals to /memory/classes/heap/objects:bytes.", |
| 32 | nil, nil, |
| 33 | ), |
| 34 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.Alloc) }, |
| 35 | valType: GaugeValue, |
| 36 | }, { |
| 37 | desc: NewDesc( |
| 38 | memstatNamespace("alloc_bytes_total"), |
| 39 | "Total number of bytes allocated in heap until now, even if released already. Equals to /gc/heap/allocs:bytes.", |
| 40 | nil, nil, |
| 41 | ), |
| 42 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.TotalAlloc) }, |
| 43 | valType: CounterValue, |
| 44 | }, { |
| 45 | desc: NewDesc( |
| 46 | memstatNamespace("sys_bytes"), |
| 47 | "Number of bytes obtained from system. Equals to /memory/classes/total:byte.", |
| 48 | nil, nil, |
| 49 | ), |
| 50 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.Sys) }, |
| 51 | valType: GaugeValue, |
| 52 | }, { |
| 53 | desc: NewDesc( |
| 54 | memstatNamespace("mallocs_total"), |
| 55 | // TODO(bwplotka): We could add go_memstats_heap_objects, probably useful for discovery. Let's gather more feedback, kind of a waste of bytes for everybody for compatibility reasons to keep both, and we can't really rename/remove useful metric. |
| 56 | "Total number of heap objects allocated, both live and gc-ed. Semantically a counter version for go_memstats_heap_objects gauge. Equals to /gc/heap/allocs:objects + /gc/heap/tiny/allocs:objects.", |
| 57 | nil, nil, |
| 58 | ), |
| 59 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.Mallocs) }, |
| 60 | valType: CounterValue, |
| 61 | }, { |
| 62 | desc: NewDesc( |
| 63 | memstatNamespace("frees_total"), |
| 64 | "Total number of heap objects frees. Equals to /gc/heap/frees:objects + /gc/heap/tiny/allocs:objects.", |
| 65 | nil, nil, |
| 66 | ), |
| 67 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.Frees) }, |
| 68 | valType: CounterValue, |
| 69 | }, { |
| 70 | desc: NewDesc( |
| 71 | memstatNamespace("heap_alloc_bytes"), |
| 72 | "Number of heap bytes allocated and currently in use, same as go_memstats_alloc_bytes. Equals to /memory/classes/heap/objects:bytes.", |
| 73 | nil, nil, |
| 74 | ), |
| 75 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapAlloc) }, |
| 76 | valType: GaugeValue, |
| 77 | }, { |
| 78 | desc: NewDesc( |
| 79 | memstatNamespace("heap_sys_bytes"), |
| 80 | "Number of heap bytes obtained from system. Equals to /memory/classes/heap/objects:bytes + /memory/classes/heap/unused:bytes + /memory/classes/heap/released:bytes + /memory/classes/heap/free:bytes.", |
| 81 | nil, nil, |
| 82 | ), |
| 83 | eval: func(ms *runtime.MemStats) float64 { return float64(ms.HeapSys) }, |