mirror of
https://github.com/prometheus/statsd_exporter.git
synced 2024-11-22 15:30:59 +00:00
Merge pull request #474 from pedro-stanaka/feat/update-golang-prom-client-native-histograms
Update client_golang to enable native histograms
This commit is contained in:
commit
f6ab38f75e
3 changed files with 34 additions and 6 deletions
12
README.md
12
README.md
|
@ -296,7 +296,6 @@ mappings:
|
||||||
name: "${2}_total"
|
name: "${2}_total"
|
||||||
labels:
|
labels:
|
||||||
provider: "$1"
|
provider: "$1"
|
||||||
mappings:
|
|
||||||
- match: "(.*)\\.(.*)--(.*)\\.status\.(.*)\\.count"
|
- match: "(.*)\\.(.*)--(.*)\\.status\.(.*)\\.count"
|
||||||
match_type: regex
|
match_type: regex
|
||||||
name: "request_total"
|
name: "request_total"
|
||||||
|
@ -403,6 +402,8 @@ mappings:
|
||||||
observer_type: histogram
|
observer_type: histogram
|
||||||
histogram_options:
|
histogram_options:
|
||||||
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
|
buckets: [ 0.01, 0.025, 0.05, 0.1 ]
|
||||||
|
native_histogram_bucket_factor: 1.1
|
||||||
|
native_histogram_max_buckets: 256
|
||||||
name: "my_timer"
|
name: "my_timer"
|
||||||
labels:
|
labels:
|
||||||
provider: "$2"
|
provider: "$2"
|
||||||
|
@ -416,6 +417,11 @@ values](https://godoc.org/github.com/prometheus/client_golang/prometheus#pkg-var
|
||||||
are used for the histogram buckets:
|
are used for the histogram buckets:
|
||||||
`[.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]`.
|
`[.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]`.
|
||||||
`+Inf` is added automatically.
|
`+Inf` is added automatically.
|
||||||
|
If your Prometheus server is enabled to scrape native histograms (v2.40.0+),
|
||||||
|
then you can set the `native_histogram_bucket_factor` to configure precision of the
|
||||||
|
buckets in the sparse histogram. More about this in the original [client_golang docs](https://github.com/prometheus/client_golang/blob/449b46435075e6e069e05af920fe028b941033cf/prometheus/histogram.go#L399-L430).
|
||||||
|
Also, a configuration of the maximum number of buckets can be set with `native_histogram_max_buckets`, this
|
||||||
|
avoids the histograms to grow too large in memory. More about this in the original [client_golang docs](https://github.com/prometheus/client_golang/blob/449b46435075e6e069e05af920fe028b941033cf/prometheus/histogram.go#L443-L467).
|
||||||
|
|
||||||
`observer_type` is only used when the statsd metric type is a timer, histogram, or distribution.
|
`observer_type` is only used when the statsd metric type is a timer, histogram, or distribution.
|
||||||
`buckets` is only used when the statsd metric type is one of these, and the `observer_type` is set to `histogram`.
|
`buckets` is only used when the statsd metric type is one of these, and the `observer_type` is set to `histogram`.
|
||||||
|
@ -470,6 +476,8 @@ defaults:
|
||||||
observer_type: histogram
|
observer_type: histogram
|
||||||
histogram_options:
|
histogram_options:
|
||||||
buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5 ]
|
buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5 ]
|
||||||
|
native_histogram_bucket_factor: 1.1
|
||||||
|
native_histogram_max_buckets: 256
|
||||||
summary_options:
|
summary_options:
|
||||||
quantiles:
|
quantiles:
|
||||||
- quantile: 0.99
|
- quantile: 0.99
|
||||||
|
@ -549,7 +557,7 @@ Possible values for `match_metric_type` are `gauge`, `counter` and `observer`.
|
||||||
|
|
||||||
There is a cache used to improve the performance of the metric mapping, that can greatly improvement performance.
|
There is a cache used to improve the performance of the metric mapping, that can greatly improvement performance.
|
||||||
The cache has a default maximum of 1000 unique statsd metric names -> prometheus metrics mappings that it can store.
|
The cache has a default maximum of 1000 unique statsd metric names -> prometheus metrics mappings that it can store.
|
||||||
This maximum can be adjust using the `statsd.cache-size` flag.
|
This maximum can be adjusted using the `statsd.cache-size` flag.
|
||||||
|
|
||||||
If the maximum is reached, entries are by default rotated using the [least recently used replacement policy](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)). This strategy is optimal when memory is constrained as only the most recent entries are retained.
|
If the maximum is reached, entries are by default rotated using the [least recently used replacement policy](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)). This strategy is optimal when memory is constrained as only the most recent entries are retained.
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,9 @@ type SummaryOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HistogramOptions struct {
|
type HistogramOptions struct {
|
||||||
Buckets []float64 `yaml:"buckets"`
|
Buckets []float64 `yaml:"buckets"`
|
||||||
|
NativeHistogramBucketFactor float64 `yaml:"native_histogram_bucket_factor"`
|
||||||
|
NativeHistogramMaxBuckets uint32 `yaml:"native_histogram_max_buckets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type metricObjective struct {
|
type metricObjective struct {
|
||||||
|
@ -88,6 +90,12 @@ func (m *MetricMapper) InitFromYAMLString(fileContents string) error {
|
||||||
if len(n.Defaults.HistogramOptions.Buckets) == 0 {
|
if len(n.Defaults.HistogramOptions.Buckets) == 0 {
|
||||||
n.Defaults.HistogramOptions.Buckets = prometheus.DefBuckets
|
n.Defaults.HistogramOptions.Buckets = prometheus.DefBuckets
|
||||||
}
|
}
|
||||||
|
if n.Defaults.HistogramOptions.NativeHistogramBucketFactor == 0 {
|
||||||
|
n.Defaults.HistogramOptions.NativeHistogramBucketFactor = 1.1
|
||||||
|
}
|
||||||
|
if n.Defaults.HistogramOptions.NativeHistogramMaxBuckets <= 0 {
|
||||||
|
n.Defaults.HistogramOptions.NativeHistogramMaxBuckets = 256
|
||||||
|
}
|
||||||
|
|
||||||
if len(n.Defaults.SummaryOptions.Quantiles) == 0 {
|
if len(n.Defaults.SummaryOptions.Quantiles) == 0 {
|
||||||
n.Defaults.SummaryOptions.Quantiles = defaultQuantiles
|
n.Defaults.SummaryOptions.Quantiles = defaultQuantiles
|
||||||
|
|
|
@ -274,10 +274,22 @@ func (r *Registry) GetHistogram(metricName string, labels prometheus.Labels, hel
|
||||||
if mapping.HistogramOptions != nil && len(mapping.HistogramOptions.Buckets) > 0 {
|
if mapping.HistogramOptions != nil && len(mapping.HistogramOptions.Buckets) > 0 {
|
||||||
buckets = mapping.HistogramOptions.Buckets
|
buckets = mapping.HistogramOptions.Buckets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bucketFactor := r.Mapper.Defaults.HistogramOptions.NativeHistogramBucketFactor
|
||||||
|
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramBucketFactor > 0 {
|
||||||
|
bucketFactor = mapping.HistogramOptions.NativeHistogramBucketFactor
|
||||||
|
}
|
||||||
|
|
||||||
|
maxBuckets := r.Mapper.Defaults.HistogramOptions.NativeHistogramMaxBuckets
|
||||||
|
if mapping.HistogramOptions != nil && mapping.HistogramOptions.NativeHistogramMaxBuckets > 0 {
|
||||||
|
maxBuckets = mapping.HistogramOptions.NativeHistogramMaxBuckets
|
||||||
|
}
|
||||||
histogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
histogramVec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||||
Name: metricName,
|
Name: metricName,
|
||||||
Help: help,
|
Help: help,
|
||||||
Buckets: buckets,
|
Buckets: buckets,
|
||||||
|
NativeHistogramBucketFactor: bucketFactor,
|
||||||
|
NativeHistogramMaxBucketNumber: maxBuckets,
|
||||||
}, labelNames)
|
}, labelNames)
|
||||||
|
|
||||||
if err := r.Registerer.Register(uncheckedCollector{histogramVec}); err != nil {
|
if err := r.Registerer.Register(uncheckedCollector{histogramVec}); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue