doc.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2014 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 provides embeddable metric primitives for servers and
  14. // standardized exposition of telemetry through a web services interface.
  15. //
  16. // All exported functions and methods are safe to be used concurrently unless
  17. // specified otherwise.
  18. //
  19. // To expose metrics registered with the Prometheus registry, an HTTP server
  20. // needs to know about the Prometheus handler. The usual endpoint is "/metrics".
  21. //
  22. // http.Handle("/metrics", prometheus.Handler())
  23. //
  24. // As a starting point a very basic usage example:
  25. //
  26. // package main
  27. //
  28. // import (
  29. // "net/http"
  30. //
  31. // "github.com/prometheus/client_golang/prometheus"
  32. // )
  33. //
  34. // var (
  35. // cpuTemp = prometheus.NewGauge(prometheus.GaugeOpts{
  36. // Name: "cpu_temperature_celsius",
  37. // Help: "Current temperature of the CPU.",
  38. // })
  39. // hdFailures = prometheus.NewCounter(prometheus.CounterOpts{
  40. // Name: "hd_errors_total",
  41. // Help: "Number of hard-disk errors.",
  42. // })
  43. // )
  44. //
  45. // func init() {
  46. // prometheus.MustRegister(cpuTemp)
  47. // prometheus.MustRegister(hdFailures)
  48. // }
  49. //
  50. // func main() {
  51. // cpuTemp.Set(65.3)
  52. // hdFailures.Inc()
  53. //
  54. // http.Handle("/metrics", prometheus.Handler())
  55. // http.ListenAndServe(":8080", nil)
  56. // }
  57. //
  58. //
  59. // This is a complete program that exports two metrics, a Gauge and a Counter.
  60. // It also exports some stats about the HTTP usage of the /metrics
  61. // endpoint. (See the Handler function for more detail.)
  62. //
  63. // Two more advanced metric types are the Summary and Histogram.
  64. //
  65. // In addition to the fundamental metric types Gauge, Counter, Summary, and
  66. // Histogram, a very important part of the Prometheus data model is the
  67. // partitioning of samples along dimensions called labels, which results in
  68. // metric vectors. The fundamental types are GaugeVec, CounterVec, SummaryVec,
  69. // and HistogramVec.
  70. //
  71. // Those are all the parts needed for basic usage. Detailed documentation and
  72. // examples are provided below.
  73. //
  74. // Everything else this package offers is essentially for "power users" only. A
  75. // few pointers to "power user features":
  76. //
  77. // All the various ...Opts structs have a ConstLabels field for labels that
  78. // never change their value (which is only useful under special circumstances,
  79. // see documentation of the Opts type).
  80. //
  81. // The Untyped metric behaves like a Gauge, but signals the Prometheus server
  82. // not to assume anything about its type.
  83. //
  84. // Functions to fine-tune how the metric registry works: EnableCollectChecks,
  85. // PanicOnCollectError, Register, Unregister, SetMetricFamilyInjectionHook.
  86. //
  87. // For custom metric collection, there are two entry points: Custom Metric
  88. // implementations and custom Collector implementations. A Metric is the
  89. // fundamental unit in the Prometheus data model: a sample at a point in time
  90. // together with its meta-data (like its fully-qualified name and any number of
  91. // pairs of label name and label value) that knows how to marshal itself into a
  92. // data transfer object (aka DTO, implemented as a protocol buffer). A Collector
  93. // gets registered with the Prometheus registry and manages the collection of
  94. // one or more Metrics. Many parts of this package are building blocks for
  95. // Metrics and Collectors. Desc is the metric descriptor, actually used by all
  96. // metrics under the hood, and by Collectors to describe the Metrics to be
  97. // collected, but only to be dealt with by users if they implement their own
  98. // Metrics or Collectors. To create a Desc, the BuildFQName function will come
  99. // in handy. Other useful components for Metric and Collector implementation
  100. // include: LabelPairSorter to sort the DTO version of label pairs,
  101. // NewConstMetric and MustNewConstMetric to create "throw away" Metrics at
  102. // collection time, MetricVec to bundle custom Metrics into a metric vector
  103. // Collector, SelfCollector to make a custom Metric collect itself.
  104. //
  105. // A good example for a custom Collector is the ExpVarCollector included in this
  106. // package, which exports variables exported via the "expvar" package as
  107. // Prometheus metrics.
  108. package prometheus