1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
6 Package metrics provides a stable interface to access implementation-defined
7 metrics exported by the Go runtime. This package is similar to existing functions
8 like runtime.ReadMemStats and debug.ReadGCStats, but significantly more general.
10 The set of metrics defined by this package may evolve as the runtime itself
11 evolves, and also enables variation across Go implementations, whose relevant
12 metric sets may not intersect.
16 Metrics are designated by a string key, rather than, for example, a field name in
17 a struct. The full list of supported metrics is always available in the slice of
18 Descriptions returned by All. Each Description also includes useful information
19 about the metric, such as how to display it (for example, gauge vs. counter)
20 and how difficult or disruptive it is to obtain it (for example, do you need to
23 Thus, users of this API are encouraged to sample supported metrics defined by the
24 slice returned by All to remain compatible across Go versions. Of course, situations
25 arise where reading specific metrics is critical. For these cases, users are
26 encouraged to use build tags, and although metrics may be deprecated and removed,
27 users should consider this to be an exceptional and rare event, coinciding with a
28 very large change in a particular Go implementation.
30 Each metric key also has a "kind" that describes the format of the metric's value.
31 In the interest of not breaking users of this package, the "kind" for a given metric
32 is guaranteed not to change. If it must change, then a new metric will be introduced
33 with a new key and a new "kind."
37 As mentioned earlier, metric keys are strings. Their format is simple and well-defined,
38 designed to be both human and machine readable. It is split into two components,
39 separated by a colon: a rooted path and a unit. The choice to include the unit in
40 the key is motivated by compatibility: if a metric's unit changes, its semantics likely
41 did also, and a new key should be introduced.
43 For more details on the precise definition of the metric key's path and unit formats, see
44 the documentation of the Name field of the Description struct.
48 This package supports metrics whose values have a floating-point representation. In
49 order to improve ease-of-use, this package promises to never produce the following
50 classes of floating-point values: NaN, infinity.
54 Below is the full list of supported metrics, ordered lexicographically.
56 /gc/cycles/automatic:gc-cycles
57 Count of completed GC cycles generated by the Go runtime.
59 /gc/cycles/forced:gc-cycles
60 Count of completed GC cycles forced by the application.
62 /gc/cycles/total:gc-cycles
63 Count of all completed GC cycles.
65 /gc/heap/allocs-by-size:bytes
66 Distribution of all objects allocated by approximate size.
68 /gc/heap/frees-by-size:bytes
69 Distribution of all objects freed by approximate size.
72 Heap size target for the end of the GC cycle.
74 /gc/heap/objects:objects
75 Number of objects, live or unswept, occupying heap memory.
78 Distribution individual GC-related stop-the-world pause latencies.
80 /memory/classes/heap/free:bytes
81 Memory that is completely free and eligible to be returned to
82 the underlying system, but has not been. This metric is the
83 runtime's estimate of free address space that is backed by
86 /memory/classes/heap/objects:bytes
87 Memory occupied by live objects and dead objects that have
88 not yet been marked free by the garbage collector.
90 /memory/classes/heap/released:bytes
91 Memory that is completely free and has been returned to
92 the underlying system. This metric is the runtime's estimate of
93 free address space that is still mapped into the process, but
94 is not backed by physical memory.
96 /memory/classes/heap/stacks:bytes
97 Memory allocated from the heap that is reserved for stack
98 space, whether or not it is currently in-use.
100 /memory/classes/heap/unused:bytes
101 Memory that is reserved for heap objects but is not currently
102 used to hold heap objects.
104 /memory/classes/metadata/mcache/free:bytes
105 Memory that is reserved for runtime mcache structures, but
108 /memory/classes/metadata/mcache/inuse:bytes
109 Memory that is occupied by runtime mcache structures that
110 are currently being used.
112 /memory/classes/metadata/mspan/free:bytes
113 Memory that is reserved for runtime mspan structures, but
116 /memory/classes/metadata/mspan/inuse:bytes
117 Memory that is occupied by runtime mspan structures that are
118 currently being used.
120 /memory/classes/metadata/other:bytes
121 Memory that is reserved for or used to hold runtime
124 /memory/classes/os-stacks:bytes
125 Stack memory allocated by the underlying operating system.
127 /memory/classes/other:bytes
128 Memory used by execution trace buffers, structures for
129 debugging the runtime, finalizer and profiler specials, and
132 /memory/classes/profiling/buckets:bytes
133 Memory that is used by the stack trace hash map used for
136 /memory/classes/total:bytes
137 All memory mapped by the Go runtime into the current process
138 as read-write. Note that this does not include memory mapped
139 by code called via cgo or via the syscall package.
140 Sum of all metrics in /memory/classes.
142 /sched/goroutines:goroutines
143 Count of live goroutines.