1 // 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
6 // http://www.apache.org/licenses/LICENSE-2.0
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.
16 // Observer is the interface that wraps the Observe method, which is used by
17 // Histogram and Summary to add observations.
18 type Observer interface {
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.
26 // This adapter is usually used in connection with the Timer type, and there are
27 // two general use cases:
29 // The most common one is to use a Gauge as the Observer for a Timer.
30 // See the "Gauge" Timer example.
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
35 type ObserverFunc func(float64)
37 // Observe calls f(value). It implements Observer.
38 func (f ObserverFunc) Observe(value float64) {
42 // ObserverVec is an interface implemented by `HistogramVec` and `SummaryVec`.
43 type ObserverVec interface {
44 GetMetricWith(Labels) (Observer, error)
45 GetMetricWithLabelValues(lvs ...string) (Observer, error)
47 WithLabelValues(...string) Observer
48 CurryWith(Labels) (ObserverVec, error)
49 MustCurryWith(Labels) ObserverVec