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:
Matt T. Proud 2013-04-28 19:40:30 +02:00
parent 26dbd0776e
commit a48ab34dd0
4 changed files with 44 additions and 51 deletions

View File

@ -14,9 +14,7 @@
package retrieval package retrieval
import ( import (
"github.com/prometheus/client_golang" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/maths"
"github.com/prometheus/client_golang/metrics"
) )
const ( const (
@ -30,24 +28,24 @@ const (
) )
var ( var (
networkLatencyHistogram = &metrics.HistogramSpecification{ networkLatencyHistogram = &prometheus.HistogramSpecification{
Starts: metrics.LogarithmicSizedBucketsFor(0, 1000), Starts: prometheus.LogarithmicSizedBucketsFor(0, 1000),
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100), BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}, 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{ retrievalDurations = prometheus.NewHistogram(&prometheus.HistogramSpecification{
Starts: metrics.LogarithmicSizedBucketsFor(0, 10000), Starts: prometheus.LogarithmicSizedBucketsFor(0, 10000),
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100), BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}}) ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}})
targetOperations = metrics.NewCounter() targetOperations = prometheus.NewCounter()
) )
func init() { func init() {
registry.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", registry.NilLabels, targetOperations) prometheus.Register("prometheus_target_operations_total", "The total numbers of operations of the various targets that are being monitored.", prometheus.NilLabels, targetOperations)
registry.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", registry.NilLabels, targetOperationLatencies) prometheus.Register("prometheus_target_operation_latency_ms", "The latencies for various target operations.", prometheus.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_targetpool_duration_ms", "The durations for each TargetPool to retrieve state from all included entities.", prometheus.NilLabels, retrievalDurations)
} }

View File

@ -14,7 +14,6 @@ package retrieval
import ( import (
"fmt" "fmt"
"github.com/prometheus/client_golang/metrics"
"github.com/prometheus/prometheus/model" "github.com/prometheus/prometheus/model"
"github.com/prometheus/prometheus/retrieval/format" "github.com/prometheus/prometheus/retrieval/format"
"log" "log"
@ -182,7 +181,18 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
done := make(chan bool) 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() { defer func() {
done <- true done <- true
}() }()
@ -211,20 +221,7 @@ func (t *target) Scrape(earliest time.Time, results chan format.Result) (err err
if err != nil { if err != nil {
return return
} }
} }(time.Now())
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)
select { select {
case <-done: case <-done:

View File

@ -14,9 +14,7 @@
package metric package metric
import ( import (
"github.com/prometheus/client_golang" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/maths"
"github.com/prometheus/client_golang/metrics"
"time" "time"
) )
@ -60,19 +58,19 @@ const (
) )
var ( var (
diskLatencyHistogram = &metrics.HistogramSpecification{ diskLatencyHistogram = &prometheus.HistogramSpecification{
Starts: metrics.LogarithmicSizedBucketsFor(0, 5000), Starts: prometheus.LogarithmicSizedBucketsFor(0, 5000),
BucketBuilder: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 100), BucketBuilder: prometheus.AccumulatingBucketBuilder(prometheus.EvictAndReplaceWith(10, prometheus.AverageReducer), 100),
ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99}, ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.90, 0.99},
} }
curationDuration = metrics.NewCounter() curationDuration = prometheus.NewCounter()
curationDurations = metrics.NewHistogram(diskLatencyHistogram) curationDurations = prometheus.NewHistogram(diskLatencyHistogram)
curationFilterOperations = metrics.NewCounter() curationFilterOperations = prometheus.NewCounter()
storageOperations = metrics.NewCounter() storageOperations = prometheus.NewCounter()
storageOperationDurations = metrics.NewCounter() storageOperationDurations = prometheus.NewCounter()
storageLatency = metrics.NewHistogram(diskLatencyHistogram) storageLatency = prometheus.NewHistogram(diskLatencyHistogram)
queueSizes = metrics.NewGauge() queueSizes = prometheus.NewGauge()
) )
func recordOutcome(duration time.Duration, err error, success, failure map[string]string) { 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() { func init() {
registry.Register("prometheus_metric_disk_operations_total", "Total number of metric-related disk operations.", registry.NilLabels, storageOperations) prometheus.Register("prometheus_metric_disk_operations_total", "Total number of metric-related disk operations.", prometheus.NilLabels, storageOperations)
registry.Register("prometheus_metric_disk_latency_microseconds", "Latency for metric disk operations in microseconds.", registry.NilLabels, storageLatency) prometheus.Register("prometheus_metric_disk_latency_microseconds", "Latency for metric disk operations in microseconds.", prometheus.NilLabels, storageLatency)
registry.Register("prometheus_storage_operation_time_total_microseconds", "The total time spent performing a given storage operation.", registry.NilLabels, storageOperationDurations) prometheus.Register("prometheus_storage_operation_time_total_microseconds", "The total time spent performing a given storage operation.", prometheus.NilLabels, storageOperationDurations)
registry.Register("prometheus_storage_queue_sizes_total", "The various sizes and capacities of the storage queues.", registry.NilLabels, queueSizes) prometheus.Register("prometheus_storage_queue_sizes_total", "The various sizes and capacities of the storage queues.", prometheus.NilLabels, queueSizes)
registry.Register("curation_filter_operations_total", "The number of curation filter operations completed.", registry.NilLabels, curationFilterOperations) prometheus.Register("curation_filter_operations_total", "The number of curation filter operations completed.", prometheus.NilLabels, curationFilterOperations)
} }

View File

@ -17,8 +17,8 @@ import (
"code.google.com/p/gorest" "code.google.com/p/gorest"
"flag" "flag"
"fmt" "fmt"
"github.com/prometheus/client_golang" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/exp" "github.com/prometheus/client_golang/prometheus/exp"
"github.com/prometheus/prometheus/appstate" "github.com/prometheus/prometheus/appstate"
"github.com/prometheus/prometheus/web/api" "github.com/prometheus/prometheus/web/api"
"github.com/prometheus/prometheus/web/blob" "github.com/prometheus/prometheus/web/blob"
@ -49,7 +49,7 @@ func StartServing(appState *appstate.ApplicationState) {
exp.HandleFunc("/console", consoleHandler) exp.HandleFunc("/console", consoleHandler)
exp.Handle("/api/", gorest.Handle()) exp.Handle("/api/", gorest.Handle())
exp.Handle("/metrics.json", registry.DefaultHandler) exp.Handle("/metrics.json", prometheus.DefaultHandler)
if *useLocalAssets { if *useLocalAssets {
exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static")))) exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
} else { } else {