blob: 5806cd09e306cdd9c73df71839fc1273a5e2fc3f [file] [log] [blame]
khenaidooab1f7bd2019-11-14 14:00:27 -05001// Copyright 2017 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package prometheus
15
16// Observer is the interface that wraps the Observe method, which is used by
17// Histogram and Summary to add observations.
18type Observer interface {
19 Observe(float64)
20}
21
22// The ObserverFunc type is an adapter to allow the use of ordinary
23// functions as Observers. If f is a function with the appropriate
24// signature, ObserverFunc(f) is an Observer that calls f.
25//
26// This adapter is usually used in connection with the Timer type, and there are
27// two general use cases:
28//
29// The most common one is to use a Gauge as the Observer for a Timer.
30// See the "Gauge" Timer example.
31//
32// The more advanced use case is to create a function that dynamically decides
33// which Observer to use for observing the duration. See the "Complex" Timer
34// example.
35type ObserverFunc func(float64)
36
37// Observe calls f(value). It implements Observer.
38func (f ObserverFunc) Observe(value float64) {
39 f(value)
40}
41
42// ObserverVec is an interface implemented by `HistogramVec` and `SummaryVec`.
43type ObserverVec interface {
44 GetMetricWith(Labels) (Observer, error)
45 GetMetricWithLabelValues(lvs ...string) (Observer, error)
46 With(Labels) Observer
47 WithLabelValues(...string) Observer
48 CurryWith(Labels) (ObserverVec, error)
49 MustCurryWith(Labels) ObserverVec
50
51 Collector
52}