func Read(m []Sample)
Read populates each Value field in the given slice of metric samples.
Desired metrics should be present in the slice with the appropriate name. The user of this API is encouraged to re-use the same slice between calls for efficiency, but is not required to do so.
Note that re-use has some caveats. Notably, Values should not be read or manipulated while a Read with that value is outstanding; that is a data race. This property includes pointer-typed Values (for example, Float64Histogram) whose underlying storage will be reused by Read when possible. To safely use such values in a concurrent setting, all data must be deep-copied.
It is safe to execute multiple Read calls concurrently, but their arguments must share no underlying memory. When in doubt, create a new []Sample from scratch, which is always safe, though may be inefficient.
Sample values with names not appearing in All will have their Value populated as KindBad to indicate that the name is unknown.
Description describes a runtime metric.
type Description struct { // Name is the full name of the metric which includes the unit. // // The format of the metric may be described by the following regular expression. // // ^(?P<name>/[^:]+):(?P<unit>[^:*/]+(?:[*/][^:*/]+)*)$ // // The format splits the name into two components, separated by a colon: a path which always // starts with a /, and a machine-parseable unit. The name may contain any valid Unicode // codepoint in between / characters, but by convention will try to stick to lowercase // characters and hyphens. An example of such a path might be "/memory/heap/free". // // The unit is by convention a series of lowercase English unit names (singular or plural) // without prefixes delimited by '*' or '/'. The unit names may contain any valid Unicode // codepoint that is not a delimiter. // Examples of units might be "seconds", "bytes", "bytes/second", "cpu-seconds", // "byte*cpu-seconds", and "bytes/second/second". // // For histograms, multiple units may apply. For instance, the units of the buckets and // the count. By convention, for histograms, the units of the count are always "samples" // with the type of sample evident by the metric's name, while the unit in the name // specifies the buckets' unit. // // A complete name might look like "/memory/heap/free:bytes". Name string // Description is an English language sentence describing the metric. Description string // Kind is the kind of value for this metric. // // The purpose of this field is to allow users to filter out metrics whose values are // types which their application may not understand. Kind ValueKind // Cumulative is whether or not the metric is cumulative. If a cumulative metric is just // a single number, then it increases monotonically. If the metric is a distribution, // then each bucket count increases monotonically. // // This flag thus indicates whether or not it's useful to compute a rate from this value. Cumulative bool }
func All() []Description
All returns a slice of containing metric descriptions for all supported metrics.
Float64Histogram represents a distribution of float64 values.
type Float64Histogram struct { // Counts contains the weights for each histogram bucket. // // Given N buckets, Count[n] is the weight of the range // [bucket[n], bucket[n+1]), for 0 <= n < N. Counts []uint64 // Buckets contains the boundaries of the histogram buckets, in increasing order. // // Buckets[0] is the inclusive lower bound of the minimum bucket while // Buckets[len(Buckets)-1] is the exclusive upper bound of the maximum bucket. // Hence, there are len(Buckets)-1 counts. Furthermore, len(Buckets) != 1, always, // since at least two boundaries are required to describe one bucket (and 0 // boundaries are used to describe 0 buckets). // // Buckets[0] is permitted to have value -Inf and Buckets[len(Buckets)-1] is // permitted to have value Inf. // // For a given metric name, the value of Buckets is guaranteed not to change // between calls until program exit. // // This slice value is permitted to alias with other Float64Histograms' Buckets // fields, so the values within should only ever be read. If they need to be // modified, the user must make a copy. Buckets []float64 }
Sample captures a single metric sample.
type Sample struct { // Name is the name of the metric sampled. // // It must correspond to a name in one of the metric descriptions // returned by All. Name string // Value is the value of the metric sample. Value Value }
Value represents a metric value returned by the runtime.
type Value struct {
// contains filtered or unexported fields
}
func (v Value) Float64() float64
Float64 returns the internal float64 value for the metric.
If v.Kind() != KindFloat64, this method panics.
func (v Value) Float64Histogram() *Float64Histogram
Float64Histogram returns the internal *Float64Histogram value for the metric.
If v.Kind() != KindFloat64Histogram, this method panics.
func (v Value) Kind() ValueKind
Kind returns the tag representing the kind of value this is.
func (v Value) Uint64() uint64
Uint64 returns the internal uint64 value for the metric.
If v.Kind() != KindUint64, this method panics.
ValueKind is a tag for a metric Value which indicates its type.
type ValueKind int
const ( // KindBad indicates that the Value has no type and should not be used. KindBad ValueKind = iota // KindUint64 indicates that the type of the Value is a uint64. KindUint64 // KindFloat64 indicates that the type of the Value is a float64. KindFloat64 // KindFloat64Histogram indicates that the type of the Value is a *Float64Histogram. KindFloat64Histogram )