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
(opts GaugeOpts)
| 76 | // scenarios for Gauges and Counters, where the former tends to be Set-heavy and |
| 77 | // the latter Inc-heavy. |
| 78 | func NewGauge(opts GaugeOpts) Gauge { |
| 79 | desc := NewDesc( |
| 80 | BuildFQName(opts.Namespace, opts.Subsystem, opts.Name), |
| 81 | opts.Help, |
| 82 | nil, |
| 83 | opts.ConstLabels, |
| 84 | ) |
| 85 | result := &gauge{desc: desc, labelPairs: desc.constLabelPairs} |
| 86 | result.init(result) // Init self-collection. |
| 87 | return result |
| 88 | } |
| 89 | |
| 90 | type gauge struct { |
| 91 | // valBits contains the bits of the represented float64 value. It has |