Refresh Prometheus client API usage.
The client API has been updated per https://github.com/prometheus/client_golang/pull/9.
This commit is contained in:
parent
26dbd0776e
commit
a48ab34dd0
|
@ -14,9 +14,7 @@
|
|||
package retrieval
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang"
|
||||
"github.com/prometheus/client_golang/maths"
|
||||
"github.com/prometheus/client_golang/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -30,24 +28,24 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
networkLatencyHistogram = &metrics.HistogramSpecification{
|
||||
Starts: metrics.LogarithmicSizedBucketsFor(0, 1000),
|
||||
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100),
|
||||
networkLatencyHistogram = &prometheus.HistogramSpecification{
|
||||
Starts: prometheus.LogarithmicSizedBucketsFor(0, 1000),
|
||||
BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
|
||||
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99},
|
||||
}
|
||||
|
||||
targetOperationLatencies = metrics.NewHistogram(networkLatencyHistogram)
|
||||
targetOperationLatencies = prometheus.NewHistogram(networkLatencyHistogram)
|
||||
|
||||
retrievalDurations = metrics.NewHistogram(&metrics.HistogramSpecification{
|
||||
Starts: metrics.LogarithmicSizedBucketsFor(0, 10000),
|
||||
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100),
|
||||
retrievalDurations = prometheus.NewHistogram(&prometheus.HistogramSpecification{
|
||||
Starts: prometheus.LogarithmicSizedBucketsFor(0, 10000),
|
||||
BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
|
||||
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}})
|
||||
|
||||
targetOperations = metrics.NewCounter()
|
||||
targetOperations = prometheus.NewCounter()
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", registry.NilLabels, targetOperations)
|
||||
registry.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", registry.NilLabels, targetOperationLatencies)
|
||||
registry.Register("prometheus_targetpool_duration_ms", "The durations for each TargetPool to retrieve state from all included entities.", registry.NilLabels, retrievalDurations)
|
||||
prometheus.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", prometheus.NilLabels, targetOperations)
|
||||
prometheus.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", prometheus.NilLabels, targetOperationLatencies)
|
||||
prometheus.Register("prometheus_targetpool_duration_ms", "The durations for each TargetPool to retrieve state from all included entities.", prometheus.NilLabels, retrievalDurations)
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ package retrieval
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/prometheus/client_golang/metrics"
|
||||
"github.com/prometheus/prometheus/model"
|
||||
"github.com/prometheus/prometheus/retrieval/format"
|
||||
"log"
|
||||
|
@ -182,7 +181,18 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
|
|||
|
||||
done := make(chan bool)
|
||||
|
||||
request := func() {
|
||||
go func(start time.Time) {
|
||||
defer func() {
|
||||
ms := float64(time.Since(start)) / float64(time.Millisecond)
|
||||
labels := map[string]string{address: t.Address(), outcome: success}
|
||||
if err != nil {
|
||||
labels[outcome] = failure
|
||||
}
|
||||
|
||||
targetOperationLatencies.Add(labels, ms)
|
||||
targetOperations.Increment(labels)
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
done <- true
|
||||
}()
|
||||
|
@ -211,20 +221,7 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
accumulator := func(d time.Duration) {
|
||||
ms := float64(d) / float64(time.Millisecond)
|
||||
labels := map[string]string{address: t.Address(), outcome: success}
|
||||
if err != nil {
|
||||
labels[outcome] = failure
|
||||
}
|
||||
|
||||
targetOperationLatencies.Add(labels, ms)
|
||||
targetOperations.Increment(labels)
|
||||
}
|
||||
|
||||
go metrics.InstrumentCall(request, accumulator)
|
||||
}(time.Now())
|
||||
|
||||
select {
|
||||
case <-done:
|
||||
|
|
|
@ -14,9 +14,7 @@
|
|||
package metric
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang"
|
||||
"github.com/prometheus/client_golang/maths"
|
||||
"github.com/prometheus/client_golang/metrics"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -60,19 +58,19 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
diskLatencyHistogram = &metrics.HistogramSpecification{
|
||||
Starts: metrics.LogarithmicSizedBucketsFor(0, 5000),
|
||||
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100),
|
||||
diskLatencyHistogram = &prometheus.HistogramSpecification{
|
||||
Starts: prometheus.LogarithmicSizedBucketsFor(0, 5000),
|
||||
BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
|
||||
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99},
|
||||
}
|
||||
|
||||
curationDuration = metrics.NewCounter()
|
||||
curationDurations = metrics.NewHistogram(diskLatencyHistogram)
|
||||
curationFilterOperations = metrics.NewCounter()
|
||||
storageOperations = metrics.NewCounter()
|
||||
storageOperationDurations = metrics.NewCounter()
|
||||
storageLatency = metrics.NewHistogram(diskLatencyHistogram)
|
||||
queueSizes = metrics.NewGauge()
|
||||
curationDuration = prometheus.NewCounter()
|
||||
curationDurations = prometheus.NewHistogram(diskLatencyHistogram)
|
||||
curationFilterOperations = prometheus.NewCounter()
|
||||
storageOperations = prometheus.NewCounter()
|
||||
storageOperationDurations = prometheus.NewCounter()
|
||||
storageLatency = prometheus.NewHistogram(diskLatencyHistogram)
|
||||
queueSizes = prometheus.NewGauge()
|
||||
)
|
||||
|
||||
func recordOutcome(duration time.Duration, err error, success, failure map[string]string) {
|
||||
|
@ -88,9 +86,9 @@ func recordOutcome(duration time.Duration, err error, success, failure map[strin
|
|||
}
|
||||
|
||||
func init() {
|
||||
registry.Register("prometheus_metric_disk_operations_total", "Total number of metric-related disk operations.", registry.NilLabels, storageOperations)
|
||||
registry.Register("prometheus_metric_disk_latency_microseconds", "Latency for metric disk operations in microseconds.", registry.NilLabels, storageLatency)
|
||||
registry.Register("prometheus_storage_operation_time_total_microseconds", "The total time spent performing a given storage operation.", registry.NilLabels, storageOperationDurations)
|
||||
registry.Register("prometheus_storage_queue_sizes_total", "The various sizes and capacities of the storage queues.", registry.NilLabels, queueSizes)
|
||||
registry.Register("curation_filter_operations_total", "The number of curation filter operations completed.", registry.NilLabels, curationFilterOperations)
|
||||
prometheus.Register("prometheus_metric_disk_operations_total", "Total number of metric-related disk operations.", prometheus.NilLabels, storageOperations)
|
||||
prometheus.Register("prometheus_metric_disk_latency_microseconds", "Latency for metric disk operations in microseconds.", prometheus.NilLabels, storageLatency)
|
||||
prometheus.Register("prometheus_storage_operation_time_total_microseconds", "The total time spent performing a given storage operation.", prometheus.NilLabels, storageOperationDurations)
|
||||
prometheus.Register("prometheus_storage_queue_sizes_total", "The various sizes and capacities of the storage queues.", prometheus.NilLabels, queueSizes)
|
||||
prometheus.Register("curation_filter_operations_total", "The number of curation filter operations completed.", prometheus.NilLabels, curationFilterOperations)
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import (
|
|||
"code.google.com/p/gorest"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/prometheus/client_golang"
|
||||
"github.com/prometheus/client_golang/exp"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/exp"
|
||||
"github.com/prometheus/prometheus/appstate"
|
||||
"github.com/prometheus/prometheus/web/api"
|
||||
"github.com/prometheus/prometheus/web/blob"
|
||||
|
@ -49,7 +49,7 @@ func StartServing(appState *appstate.ApplicationState) {
|
|||
exp.HandleFunc("/console", consoleHandler)
|
||||
|
||||
exp.Handle("/api/", gorest.Handle())
|
||||
exp.Handle("/metrics.json", registry.DefaultHandler)
|
||||
exp.Handle("/metrics.json", prometheus.DefaultHandler)
|
||||
if *useLocalAssets {
|
||||
exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue