type Gauge … type GaugeOpts … type GaugeVecOpts … // NewGauge creates a new Gauge based on the provided GaugeOpts. // // The returned implementation is optimized for a fast Set method. If you have a // choice for managing the value of a Gauge via Set vs. Inc/Dec/Add/Sub, pick // the former. For example, the Inc method of the returned Gauge is slower than // the Inc method of a Counter returned by NewCounter. This matches the typical // scenarios for Gauges and Counters, where the former tends to be Set-heavy and // the latter Inc-heavy. func NewGauge(opts GaugeOpts) Gauge { … } type gauge … func (g *gauge) Desc() *Desc { … } func (g *gauge) Set(val float64) { … } func (g *gauge) SetToCurrentTime() { … } func (g *gauge) Inc() { … } func (g *gauge) Dec() { … } func (g *gauge) Add(val float64) { … } func (g *gauge) Sub(val float64) { … } func (g *gauge) Write(out *dto.Metric) error { … } type GaugeVec … // NewGaugeVec creates a new GaugeVec based on the provided GaugeOpts and // partitioned by the given label names. func NewGaugeVec(opts GaugeOpts, labelNames []string) *GaugeVec { … } // NewGaugeVec creates a new GaugeVec based on the provided GaugeVecOpts. func (v2) NewGaugeVec(opts GaugeVecOpts) *GaugeVec { … } // GetMetricWithLabelValues returns the Gauge for the given slice of label // values (same order as the variable labels in Desc). If that combination of // label values is accessed for the first time, a new Gauge is created. // // It is possible to call this method without using the returned Gauge to only // create the new Gauge but leave it at its starting value 0. See also the // SummaryVec example. // // Keeping the Gauge for later use is possible (and should be considered if // performance is critical), but keep in mind that Reset, DeleteLabelValues and // Delete can be used to delete the Gauge from the GaugeVec. In that case, the // Gauge will still exist, but it will not be exported anymore, even if a // Gauge with the same label values is created later. See also the CounterVec // example. // // An error is returned if the number of label values is not the same as the // number of variable labels in Desc (minus any curried labels). // // Note that for more than one label value, this method is prone to mistakes // caused by an incorrect order of arguments. Consider GetMetricWith(Labels) as // an alternative to avoid that type of mistake. For higher label numbers, the // latter has a much more readable (albeit more verbose) syntax, but it comes // with a performance overhead (for creating and processing the Labels map). func (v *GaugeVec) GetMetricWithLabelValues(lvs ...string) (Gauge, error) { … } // GetMetricWith returns the Gauge for the given Labels map (the label names // must match those of the variable labels in Desc). If that label map is // accessed for the first time, a new Gauge is created. Implications of // creating a Gauge without using it and keeping the Gauge for later use are // the same as for GetMetricWithLabelValues. // // An error is returned if the number and names of the Labels are inconsistent // with those of the variable labels in Desc (minus any curried labels). // // This method is used for the same purpose as // GetMetricWithLabelValues(...string). See there for pros and cons of the two // methods. func (v *GaugeVec) GetMetricWith(labels Labels) (Gauge, error) { … } // WithLabelValues works as GetMetricWithLabelValues, but panics where // GetMetricWithLabelValues would have returned an error. Not returning an // error allows shortcuts like // // myVec.WithLabelValues("404", "GET").Add(42) func (v *GaugeVec) WithLabelValues(lvs ...string) Gauge { … } // With works as GetMetricWith, but panics where GetMetricWithLabels would have // returned an error. Not returning an error allows shortcuts like // // myVec.With(prometheus.Labels{"code": "404", "method": "GET"}).Add(42) func (v *GaugeVec) With(labels Labels) Gauge { … } // CurryWith returns a vector curried with the provided labels, i.e. the // returned vector has those labels pre-set for all labeled operations performed // on it. The cardinality of the curried vector is reduced accordingly. The // order of the remaining labels stays the same (just with the curried labels // taken out of the sequence – which is relevant for the // (GetMetric)WithLabelValues methods). It is possible to curry a curried // vector, but only with labels not yet used for currying before. // // The metrics contained in the GaugeVec are shared between the curried and // uncurried vectors. They are just accessed differently. Curried and uncurried // vectors behave identically in terms of collection. Only one must be // registered with a given registry (usually the uncurried version). The Reset // method deletes all metrics, even if called on a curried vector. func (v *GaugeVec) CurryWith(labels Labels) (*GaugeVec, error) { … } // MustCurryWith works as CurryWith but panics where CurryWith would have // returned an error. func (v *GaugeVec) MustCurryWith(labels Labels) *GaugeVec { … } type GaugeFunc … // NewGaugeFunc creates a new GaugeFunc based on the provided GaugeOpts. The // value reported is determined by calling the given function from within the // Write method. Take into account that metric collection may happen // concurrently. Therefore, it must be safe to call the provided function // concurrently. // // NewGaugeFunc is a good way to create an “info” style metric with a constant // value of 1. Example: // https://github.com/prometheus/common/blob/8558a5b7db3c84fa38b4766966059a7bd5bfa2ee/version/info.go#L36-L56 func NewGaugeFunc(opts GaugeOpts, function func() float64) GaugeFunc { … }