Documentation
¶
Index ¶
- func Flush(w Writer)
- func SetDefault(r Registry)
- type Bucket
- type Counter
- type CounterOpts
- type CounterSet
- type Desc
- type Gauge
- type GaugeFloat
- type GaugeFloatOpts
- type GaugeFloatSet
- type GaugeOpts
- type GaugeSet
- type Histogram
- type HistogramModel
- type HistogramOpts
- type HistogramSet
- type Labels
- type Meter
- type MeterModel
- type MeterOpts
- type MeterSet
- type Metric
- type Opts
- type Pair
- type Quantile
- type Registry
- type Summary
- type SummaryModel
- type SummaryOpts
- type SummarySet
- type Timer
- type TimerModel
- type TimerOpts
- type TimerSet
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Counter ¶
Counter is a Metric that represents a single numerical value that only ever goes up. That implies that it cannot be used to count items whose number can also go down, e.g. the number of currently running goroutines. Those "counters" are represented by Gauges.
A Counter is typically used to count requests served, tasks completed, errors occurred, etc.
To create Counter instances, use NewCounter.
type CounterOpts ¶
type CounterOpts = Opts
type CounterSet ¶
CounterSet is a Collector that bundles a set of Counters that all share the same Desc, but have different values for their variable labels. This is used if you want to count the same thing partitioned by various dimensions (e.g. number of HTTP requests, partitioned by response code and method). Create instances with CounterSet.
func NewCounterSet ¶
func NewCounterSet(opts *CounterOpts, labelNames []string) CounterSet
type Desc ¶
type Desc struct { Name string // Help string // Labels []Pair // 所有标签,包含静态标签和动态标签,静态标签在前边,动态标签在后边 }
Desc is the descriptor used by every Metric. It is essentially the immutable meta-data of a Metric. The normal Metric implementations included in this package manage their Desc under the hood. Users only have to deal with Desc if they use advanced features like the ExpvarCollector or custom Collectors and Metrics.
Descriptors registered with the same registry have to fulfill certain consistency and uniqueness criteria if they share the same fully-qualified name: They must have the same help string and the same label names (aka label dimensions) in each, constLabels and variableLabels, but they must differ in the values of the constLabels.
Descriptors that share the same fully-qualified names and the same label values of their constLabels are considered equal.
Use NewDesc to create new Desc instances.
type Gauge ¶
Gauge is a Metric that represents a single numerical value that can arbitrarily go up and down.
A Gauge is typically used for measured values like temperatures or current memory usage, but also "counts" that can go up and down, like the number of running goroutines.
To create Gauge instances, use NewGauge.
type GaugeFloat ¶
GaugeFloat like Gauge, but type type is float64
type GaugeFloatOpts ¶
type GaugeFloatOpts = Opts
type GaugeFloatSet ¶
type GaugeFloatSet interface { Labels(labels Labels) GaugeFloat Values(labels ...string) GaugeFloat }
func NewGaugeFloatSet ¶
func NewGaugeFloatSet(opts *GaugeFloatOpts, labelNames []string) GaugeFloatSet
type GaugeSet ¶
func NewGaugeSet ¶
type Histogram ¶
type Histogram interface { Metric Value() *HistogramModel // Observe adds a single observation to the histogram. Observe(float64) }
A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a summary, it also provides a sum of observations and an observation count.
On the Prometheus server, quantiles can be calculated from a Histogram using the histogram_quantile function in the query language.
Note that Histograms, in contrast to Summaries, can be aggregated with the Prometheus query language (see the documentation for detailed procedures). However, Histograms require the user to pre-define suitable buckets, and they are in general less accurate. The Observe method of a Histogram has a very low performance overhead in comparison with the Observe method of a Summary.
To create Histogram instances, use NewHistogram.
func NewHistogram ¶
func NewHistogram(opts *HistogramOpts) Histogram
type HistogramModel ¶
type HistogramOpts ¶
type HistogramOpts struct { // Namespace, Subsystem, and Name are components of the fully-qualified // name of the Metric (created by joining these components with // "_"). Only Name is mandatory, the others merely help structuring the // name. Note that the fully-qualified name of the metric must be a // valid Prometheus metric name. Namespace string Subsystem string Name string // Help provides information about this metric. // // Metrics with the same fully-qualified name must have the same Help string. Help string Labels Labels }
type HistogramSet ¶
func NewHistogramSet ¶
func NewHistogramSet(opts *HistogramOpts, labelNames []string) HistogramSet
type Labels ¶
Labels represents a collection of label name -> value mappings. This type is commonly used with the With(Labels) and GetMetricWith(Labels) methods of metric vector Collectors, e.g.:
myVec.With(Labels{"code": "404", "method": "GET"}).Add(42)
The other use-case is the specification of constant label pairs in Opts or to create a Desc.
type Meter ¶
type Meter interface { Metric Value() *MeterModel Add(n int64) }
Meter 度量某个时间段的平均处理次数(request per second)
type MeterModel ¶
type MeterModel struct { }
type MeterSet ¶
func NewMeterSet ¶
type Metric ¶
type Metric interface { // Desc returns the descriptor for the Metric. This method idempotently // returns the same descriptor throughout the lifetime of the // Metric. The returned descriptor is immutable by contract. A Metric // unable to describe itself must return an invalid descriptor (created // with NewInvalidDesc). Desc() *Desc }
A Metric models a single sample value with its meta data being exported to Prometheus. Implementations of Metric in this package are Gauge, Counter, Histogram, Summary, and Untyped.
type Opts ¶
type Opts struct { // Namespace, Subsystem, and Name are components of the fully-qualified // name of the Metric (created by joining these components with // "_"). Only Name is mandatory, the others merely help structuring the // name. Note that the fully-qualified name of the metric must be a // valid Prometheus metric name. Namespace string Subsystem string Name string // Help provides information about this metric. // // Metrics with the same fully-qualified name must have the same Help string. Help string Labels Labels }
type Registry ¶
type Registry interface { NewCounter(opts *CounterOpts) Counter NewGauge(opts *GaugeOpts) Gauge NewGaugeFloat(opts *GaugeFloatOpts) GaugeFloat NewMeter(opts *MeterOpts) Meter NewHistogram(opts *HistogramOpts) Histogram NewSummary(opts *SummaryOpts) Summary NewTimer(opts *TimerOpts) Timer NewCounterSet(opts *CounterOpts, labelNames []string) CounterSet NewGaugeSet(opts *GaugeOpts, labelNames []string) GaugeSet NewGaugeFloatSet(opts *GaugeFloatOpts, labelNames []string) GaugeFloatSet NewMeterSet(opts *MeterOpts, labelNames []string) MeterSet NewHistogramSet(opts *HistogramOpts, labelNames []string) HistogramSet NewSummarySet(opts *SummaryOpts, labelNames []string) SummarySet NewTimerSet(opts *TimerOpts, labelNames []string) TimerSet Register(m Metric) Flush(w Writer) }
Registry 创建Metric并注册
type Summary ¶
type Summary interface { Metric Value() *SummaryModel // Observe adds a single observation to the summary. Observations are // usually positive or zero. Negative observations are accepted but // prevent current versions of Prometheus from properly detecting // counter resets in the sum of observations. See // https://prometheus.io/docs/practices/histograms/#count-and-sum-of-observations // for details. Observe(float64) }
A Summary captures individual observations from an event or sample stream and summarizes them in a manner similar to traditional summary statistics: 1. sum of observations, 2. observation count, 3. rank estimations.
A typical use-case is the observation of request latencies. By default, a Summary provides the median, the 90th and the 99th percentile of the latency as rank estimations. However, the default behavior will change in the upcoming v1.0.0 of the library. There will be no rank estimations at all by default. For a sane transition, it is recommended to set the desired rank estimations explicitly.
Note that the rank estimations cannot be aggregated in a meaningful way with the Prometheus query language (i.e. you cannot average or add them). If you need aggregatable quantiles (e.g. you want the 99th percentile latency of all queries served across all instances of a service), consider the Histogram metric type. See the Prometheus documentation for more details.
To create Summary instances, use NewSummary.
func NewSummary ¶
func NewSummary(opts *SummaryOpts) Summary
type SummaryModel ¶
type SummaryOpts ¶
type SummaryOpts struct { // Namespace, Subsystem, and Name are components of the fully-qualified // name of the Metric (created by joining these components with // "_"). Only Name is mandatory, the others merely help structuring the // name. Note that the fully-qualified name of the metric must be a // valid Prometheus metric name. Namespace string Subsystem string Name string // Help provides information about this metric. // // Metrics with the same fully-qualified name must have the same Help string. Help string Labels Labels }
type SummarySet ¶
func NewSummarySet ¶
func NewSummarySet(opts *SummaryOpts, labelNames []string) SummarySet
type Timer ¶
type Timer interface { Metric Value() *TimerModel }
Timer 是Histogram和Meter的结合,Histogram统计耗时分布,Meter统计QPS;
type TimerModel ¶
type TimerModel struct { }