您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

65 行
2.5 KiB

  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
  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. package prometheus
  14. // Observer is the interface that wraps the Observe method, which is used by
  15. // Histogram and Summary to add observations.
  16. type Observer interface {
  17. Observe(float64)
  18. }
  19. // The ObserverFunc type is an adapter to allow the use of ordinary
  20. // functions as Observers. If f is a function with the appropriate
  21. // signature, ObserverFunc(f) is an Observer that calls f.
  22. //
  23. // This adapter is usually used in connection with the Timer type, and there are
  24. // two general use cases:
  25. //
  26. // The most common one is to use a Gauge as the Observer for a Timer.
  27. // See the "Gauge" Timer example.
  28. //
  29. // The more advanced use case is to create a function that dynamically decides
  30. // which Observer to use for observing the duration. See the "Complex" Timer
  31. // example.
  32. type ObserverFunc func(float64)
  33. // Observe calls f(value). It implements Observer.
  34. func (f ObserverFunc) Observe(value float64) {
  35. f(value)
  36. }
  37. // ObserverVec is an interface implemented by `HistogramVec` and `SummaryVec`.
  38. type ObserverVec interface {
  39. GetMetricWith(Labels) (Observer, error)
  40. GetMetricWithLabelValues(lvs ...string) (Observer, error)
  41. With(Labels) Observer
  42. WithLabelValues(...string) Observer
  43. CurryWith(Labels) (ObserverVec, error)
  44. MustCurryWith(Labels) ObserverVec
  45. Collector
  46. }
  47. // ExemplarObserver is implemented by Observers that offer the option of
  48. // observing a value together with an exemplar. Its ObserveWithExemplar method
  49. // works like the Observe method of an Observer but also replaces the currently
  50. // saved exemplar (if any) with a new one, created from the provided value, the
  51. // current time as timestamp, and the provided Labels. Empty Labels will lead to
  52. // a valid (label-less) exemplar. But if Labels is nil, the current exemplar is
  53. // left in place. ObserveWithExemplar panics if any of the provided labels are
  54. // invalid or if the provided labels contain more than 64 runes in total.
  55. type ExemplarObserver interface {
  56. ObserveWithExemplar(value float64, exemplar Labels)
  57. }