metrics

package
v0.0.0-...-817968b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

metrics

使用方法

类型

  • Counter: 计数器,单调递增或递减
  • Gauge: 计量器,统计瞬时状态的数据信息。
  • Meters: 度量某个时间段的平均处理次数(request per second)
  • Histogram: 直方图,统计数据的分布情况,最大值、最小值、平均值、中位数,百分比(75%、90%、95%、98%、99%和99.9%)
  • Summary: .
  • Timers: 计时器, 统计某一块代码段的执行时间以及其分布情况,基于Histograms和Meters来实现的。

libraries

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Flush

func Flush(w Writer)

Flush .

func SetDefault

func SetDefault(r Registry)

SetDefault 设置默认Registry

Types

type Bucket

type Bucket struct {
	CumulativeCount uint64
	UpperBound      float64
}

type Counter

type Counter interface {
	Metric
	Value() int64
	Add(int64)
	Inc()
	Dec()
}

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.

func NewCounter

func NewCounter(opts *CounterOpts) Counter

NewCounter create counter

type CounterOpts

type CounterOpts = Opts

type CounterSet

type CounterSet interface {
	Labels(labels Labels) Counter
	Values(labels ...string) Counter
}

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

type Gauge interface {
	Metric
	Value() int64
	Set(int64)
	Add(int64)
	Sub(int64)
	Inc()
	Dec()
}

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.

func NewGauge

func NewGauge(opts *Opts) Gauge

NewGauge create gauge

type GaugeFloat

type GaugeFloat interface {
	Metric
	Value() float64
	Set(float64)
	Add(float64)
	Sub(float64)
}

GaugeFloat like Gauge, but type type is float64

func NewGaugeFloat

func NewGaugeFloat(opts *GaugeFloatOpts) GaugeFloat

NewGaugeFloat create gauge

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 GaugeOpts

type GaugeOpts = Opts

type GaugeSet

type GaugeSet interface {
	Labels(labels Labels) Gauge
	Values(labels ...string) Gauge
}

func NewGaugeSet

func NewGaugeSet(opts *GaugeOpts, labelNames []string) GaugeSet

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 HistogramModel struct {
	SampleCount uint64
	SampleSum   float64
	Buckets     []Bucket
}

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

type HistogramSet interface {
	Labels(labels Labels) Histogram
	Values(labels ...string) Histogram
}

func NewHistogramSet

func NewHistogramSet(opts *HistogramOpts, labelNames []string) HistogramSet

type Labels

type Labels map[string]string

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)

func NewMeter

func NewMeter(opts *MeterOpts) Meter

type MeterModel

type MeterModel struct {
}

type MeterOpts

type MeterOpts = Opts

type MeterSet

type MeterSet interface {
	Labels(labels Labels) Meter
	Values(labels ...string) Meter
}

func NewMeterSet

func NewMeterSet(opts *MeterOpts, labelNames []string) MeterSet

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 Pair

type Pair struct {
	Name  string
	Value string
}

Pair key-value pair

type Quantile

type Quantile struct {
	Quantile float64
	Value    float64
}

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并注册

func NewRegistry

func NewRegistry() Registry

NewRegistry 新建Registry

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 SummaryModel struct {
	SampleCount uint64
	SampleSum   float64
	Quantiles   []Quantile
}

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

type SummarySet interface {
	Labels(labels Labels) Summary
	Values(labels ...string) Summary
}

func NewSummarySet

func NewSummarySet(opts *SummaryOpts, labelNames []string) SummarySet

type Timer

type Timer interface {
	Metric
	Value() *TimerModel
}

Timer 是Histogram和Meter的结合,Histogram统计耗时分布,Meter统计QPS;

func NewTimer

func NewTimer(opts *TimerOpts) Timer

type TimerModel

type TimerModel struct {
}

type TimerOpts

type TimerOpts = Opts

type TimerSet

type TimerSet interface {
	Labels(labels Labels) Timer
	Values(labels ...string) Timer
}

func NewTimerSet

func NewTimerSet(opts *TimerOpts, labelNames []string) TimerSet

type Writer

type Writer interface {
	Write(m Metric)
}

Writer 提供各种指标接口,用于写入最终平台

func NewConsoleWriter

func NewConsoleWriter() Writer

NewConsoleWriter 控制台输出

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL