const ( InstrumentHandlerResponseSize = iota InstrumentHandlerRequestSize InstrumentHandlerDuration InstrumentHandlerCounter InstrumentHandlerInFlight )
func Deregister(n *Namespace)
Deregister removes all the metrics in the provided namespace from the global metrics registry
func Handler() http.Handler
Handler returns the global http.Handler that provides the prometheus metrics format on GET requests. This handler is no longer instrumented.
func InstrumentHandler(metrics []*HTTPMetric, handler http.Handler) http.HandlerFunc
func InstrumentHandlerFunc(metrics []*HTTPMetric, handlerFunc http.HandlerFunc) http.HandlerFunc
func Register(n *Namespace)
Register adds all the metrics in the provided namespace to the global metrics registry
func StartTimer(timer Timer) (done func())
StartTimer begins a timer observation at the callsite. When the target operation is completed, the caller should call the return done func().
Counter is a metrics that can only increment its current count
type Counter interface { // Inc adds Sum(vs) to the counter. Sum(vs) must be positive. // // If len(vs) == 0, increments the counter by 1. Inc(vs ...float64) }
Gauge is a metric that allows incrementing and decrementing a value
type Gauge interface { Inc(...float64) Dec(...float64) // Add adds the provided value to the gauge's current value Add(float64) // Set replaces the gauge's current value with the provided value Set(float64) }
HTTPHandlerOpts describes a set of configurable options of http metrics
type HTTPHandlerOpts struct { DurationBuckets []float64 RequestSizeBuckets []float64 ResponseSizeBuckets []float64 }
type HTTPMetric struct { prometheus.Collector // contains filtered or unexported fields }
LabeledCounter is counter that must have labels populated before use.
type LabeledCounter interface { WithValues(vs ...string) Counter }
LabeledGauge describes a gauge the must have values populated before use.
type LabeledGauge interface { WithValues(labels ...string) Gauge }
LabeledTimer is a timer that must have label values populated before use.
type LabeledTimer interface { WithValues(labels ...string) *labeledTimerObserver }
type Labels map[string]string
Namespace describes a set of metrics that share a namespace and subsystem.
type Namespace struct {
// contains filtered or unexported fields
}
func NewNamespace(name, subsystem string, labels Labels) *Namespace
NewNamespace returns a namespaces that is responsible for managing a collection of metrics for a particual namespace and subsystem
labels allows const labels to be added to all metrics created in this namespace and are commonly used for data like application version and git commit
func (n *Namespace) Add(collector prometheus.Collector)
func (n *Namespace) Collect(ch chan<- prometheus.Metric)
func (n *Namespace) Describe(ch chan<- *prometheus.Desc)
func (n *Namespace) NewCounter(name, help string) Counter
func (n *Namespace) NewDefaultHttpMetrics(handlerName string) []*HTTPMetric
func (n *Namespace) NewDesc(name, help string, unit Unit, labels ...string) *prometheus.Desc
func (n *Namespace) NewGauge(name, help string, unit Unit) Gauge
func (n *Namespace) NewHttpMetrics(handlerName string, durationBuckets, requestSizeBuckets, responseSizeBuckets []float64) []*HTTPMetric
func (n *Namespace) NewHttpMetricsWithOpts(handlerName string, opts HTTPHandlerOpts) []*HTTPMetric
func (n *Namespace) NewInFlightGaugeMetric(handlerName string) *HTTPMetric
func (n *Namespace) NewLabeledCounter(name, help string, labels ...string) LabeledCounter
func (n *Namespace) NewLabeledGauge(name, help string, unit Unit, labels ...string) LabeledGauge
func (n *Namespace) NewLabeledTimer(name, help string, labels ...string) LabeledTimer
func (n *Namespace) NewRequestDurationMetric(handlerName string, buckets []float64) *HTTPMetric
func (n *Namespace) NewRequestSizeMetric(handlerName string, buckets []float64) *HTTPMetric
func (n *Namespace) NewRequestTotalMetric(handlerName string) *HTTPMetric
func (n *Namespace) NewResponseSizeMetric(handlerName string, buckets []float64) *HTTPMetric
func (n *Namespace) NewTimer(name, help string) Timer
func (n *Namespace) WithConstLabels(labels Labels) *Namespace
WithConstLabels returns a namespace with the provided set of labels merged with the existing constant labels on the namespace.
Only metrics created with the returned namespace will get the new constant labels. The returned namespace must be registered separately.
Timer is a metric that allows collecting the duration of an action in seconds
type Timer interface { // Update records an observation, duration, and converts to the target // units. Update(duration time.Duration) // UpdateSince will add the duration from the provided starting time to the // timer's summary with the precisions that was used in creation of the timer UpdateSince(time.Time) }
Unit represents the type or precision of a metric that is appended to the metrics fully qualified name
type Unit string
const ( Nanoseconds Unit = "nanoseconds" Seconds Unit = "seconds" Bytes Unit = "bytes" Total Unit = "total" )