1 | 1 |
package prometheus
|
2 | 2 |
|
3 | 3 |
import (
|
4 | |
"time"
|
5 | |
|
6 | 4 |
"github.com/prometheus/client_golang/prometheus"
|
7 | 5 |
|
8 | 6 |
"github.com/peterbourgon/gokit/metrics"
|
|
138 | 136 |
Pairs map[string]string
|
139 | 137 |
}
|
140 | 138 |
|
141 | |
// NewSummary returns a new Histogram backed by a Prometheus summary. It uses
|
142 | |
// a 10-second max age for bucketing, emulating statsd. The histogram is
|
143 | |
// automatically registered via prometheus.Register.
|
144 | |
func NewSummary(namespace, subsystem, name, help string, fieldKeys []string) metrics.Histogram {
|
145 | |
return NewSummaryWithLabels(namespace, subsystem, name, help, fieldKeys, prometheus.Labels{})
|
146 | |
}
|
147 | |
|
148 | |
// NewSummaryWithLabels is the same as NewSummary, but attaches a set of const
|
149 | |
// label pairs to the metric.
|
150 | |
func NewSummaryWithLabels(namespace, subsystem, name, help string, fieldKeys []string, constLabels prometheus.Labels) metrics.Histogram {
|
151 | |
m := prometheus.NewSummaryVec(
|
152 | |
prometheus.SummaryOpts{
|
153 | |
Namespace: namespace,
|
154 | |
Subsystem: subsystem,
|
155 | |
Name: name,
|
156 | |
Help: help,
|
157 | |
ConstLabels: constLabels,
|
158 | |
MaxAge: 10 * time.Second,
|
159 | |
},
|
160 | |
fieldKeys,
|
161 | |
)
|
162 | |
prometheus.MustRegister(m)
|
163 | |
|
|
139 |
// NewSummary returns a new Histogram backed by a Prometheus summary. The
|
|
140 |
// histogram is automatically registered via prometheus.Register.
|
|
141 |
//
|
|
142 |
// For more information on Prometheus histograms and summaries, refer to
|
|
143 |
// http://prometheus.io/docs/practices/histograms.
|
|
144 |
func NewSummary(opts prometheus.SummaryOpts, fieldKeys []string) metrics.Histogram {
|
|
145 |
m := prometheus.NewSummaryVec(opts, fieldKeys)
|
|
146 |
prometheus.MustRegister(m)
|
164 | 147 |
return prometheusSummary{
|
165 | 148 |
SummaryVec: m,
|
166 | 149 |
Pairs: pairsFrom(fieldKeys),
|
|
183 | 166 |
Pairs map[string]string
|
184 | 167 |
}
|
185 | 168 |
|
186 | |
// NewHistogram returns a new Histogram backed by a Prometheus Histogram.
|
187 | |
// Observations are counted into buckets; see Prometheus documentation for
|
188 | |
// details. The histogram is automatically registered via prometheus.Register.
|
189 | |
func NewHistogram(namespace, subsystem, name, help string, fieldKeys []string, buckets []float64) metrics.Histogram {
|
190 | |
return NewHistogramWithLabels(namespace, subsystem, name, help, fieldKeys, buckets, prometheus.Labels{})
|
191 | |
}
|
192 | |
|
193 | |
// NewHistogramWithLabels is the same as NewHistogram, but attaches a set of const
|
194 | |
// label pairs to the metric.
|
195 | |
func NewHistogramWithLabels(namespace, subsystem, name, help string, fieldKeys []string, buckets []float64, constLabels prometheus.Labels) metrics.Histogram {
|
196 | |
m := prometheus.NewHistogramVec(
|
197 | |
prometheus.HistogramOpts{
|
198 | |
Namespace: namespace,
|
199 | |
Subsystem: subsystem,
|
200 | |
Name: name,
|
201 | |
Help: help,
|
202 | |
ConstLabels: constLabels,
|
203 | |
Buckets: buckets,
|
204 | |
},
|
205 | |
fieldKeys,
|
206 | |
)
|
207 | |
prometheus.MustRegister(m)
|
208 | |
|
|
169 |
// NewHistogram returns a new Histogram backed by a Prometheus Histogram. The
|
|
170 |
// histogram is automatically registered via prometheus.Register.
|
|
171 |
//
|
|
172 |
// For more information on Prometheus histograms and summaries, refer to
|
|
173 |
// http://prometheus.io/docs/practices/histograms.
|
|
174 |
func NewHistogram(opts prometheus.HistogramOpts, fieldKeys []string) metrics.Histogram {
|
|
175 |
m := prometheus.NewHistogramVec(opts, fieldKeys)
|
|
176 |
prometheus.MustRegister(m)
|
209 | 177 |
return prometheusHistogram{
|
210 | 178 |
HistogramVec: m,
|
211 | 179 |
Pairs: pairsFrom(fieldKeys),
|