...

Source file src/github.com/go-kit/kit/metrics/provider/prometheus.go

Documentation: github.com/go-kit/kit/metrics/provider

     1  package provider
     2  
     3  import (
     4  	stdprometheus "github.com/prometheus/client_golang/prometheus"
     5  
     6  	"github.com/go-kit/kit/metrics"
     7  	"github.com/go-kit/kit/metrics/prometheus"
     8  )
     9  
    10  type prometheusProvider struct {
    11  	namespace string
    12  	subsystem string
    13  }
    14  
    15  // NewPrometheusProvider returns a Provider that produces Prometheus metrics.
    16  // Namespace and subsystem are applied to all produced metrics.
    17  func NewPrometheusProvider(namespace, subsystem string) Provider {
    18  	return &prometheusProvider{
    19  		namespace: namespace,
    20  		subsystem: subsystem,
    21  	}
    22  }
    23  
    24  // NewCounter implements Provider via prometheus.NewCounterFrom, i.e. the
    25  // counter is registered. The metric's namespace and subsystem are taken from
    26  // the Provider. Help is set to the name of the metric, and no const label names
    27  // are set.
    28  func (p *prometheusProvider) NewCounter(name string) metrics.Counter {
    29  	return prometheus.NewCounterFrom(stdprometheus.CounterOpts{
    30  		Namespace: p.namespace,
    31  		Subsystem: p.subsystem,
    32  		Name:      name,
    33  		Help:      name,
    34  	}, []string{})
    35  }
    36  
    37  // NewGauge implements Provider via prometheus.NewGaugeFrom, i.e. the gauge is
    38  // registered. The metric's namespace and subsystem are taken from the Provider.
    39  // Help is set to the name of the metric, and no const label names are set.
    40  func (p *prometheusProvider) NewGauge(name string) metrics.Gauge {
    41  	return prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
    42  		Namespace: p.namespace,
    43  		Subsystem: p.subsystem,
    44  		Name:      name,
    45  		Help:      name,
    46  	}, []string{})
    47  }
    48  
    49  // NewHistogram implements Provider via prometheus.NewSummaryFrom, i.e. the summary
    50  // is registered. The metric's namespace and subsystem are taken from the
    51  // Provider. Help is set to the name of the metric, and no const label names are
    52  // set. Buckets are ignored.
    53  func (p *prometheusProvider) NewHistogram(name string, _ int) metrics.Histogram {
    54  	return prometheus.NewSummaryFrom(stdprometheus.SummaryOpts{
    55  		Namespace: p.namespace,
    56  		Subsystem: p.subsystem,
    57  		Name:      name,
    58  		Help:      name,
    59  	}, []string{})
    60  }
    61  
    62  // Stop implements Provider, but is a no-op.
    63  func (p *prometheusProvider) Stop() {}
    64  

View as plain text