From 615c249a332bb71796a7d643dab51ea1670d5e1a Mon Sep 17 00:00:00 2001 From: Kobus Coetzer Date: Fri, 12 Jul 2019 14:46:44 +1000 Subject: [PATCH] Update request_time to include additional metrics --- couchdb-exporter_test.go | 13 +++++++------ lib/collector-v1.go | 2 +- lib/collector-v2.go | 18 +++++++++++++++++- lib/collector.go | 18 ++++++++++++++++++ lib/couchdb-stats.go | 25 ++++++++++++++----------- lib/exporter.go | 13 +++++-------- 6 files changed, 62 insertions(+), 27 deletions(-) diff --git a/couchdb-exporter_test.go b/couchdb-exporter_test.go index 832805d4..211dc759 100644 --- a/couchdb-exporter_test.go +++ b/couchdb-exporter_test.go @@ -3,11 +3,6 @@ package main import ( "encoding/base64" "fmt" - "github.com/gesellix/couchdb-cluster-config/pkg" - "github.com/gesellix/couchdb-prometheus-exporter/lib" - "github.com/gesellix/couchdb-prometheus-exporter/testutil" - "github.com/prometheus/client_golang/prometheus" - "github.com/stretchr/testify/assert" "io/ioutil" "log" "net" @@ -16,6 +11,12 @@ import ( "strings" "testing" "time" + + "github.com/gesellix/couchdb-cluster-config/pkg" + "github.com/gesellix/couchdb-prometheus-exporter/lib" + "github.com/gesellix/couchdb-prometheus-exporter/testutil" + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" ) var clusterSetupDelay = 5 * time.Second @@ -170,7 +171,7 @@ func TestCouchdbStatsV1(t *testing.T) { } func TestCouchdbStatsV2(t *testing.T) { - performCouchdbStatsTest(t, "v2", 228, 4712, 58570, 17) + performCouchdbStatsTest(t, "v2", 258, 4712, 58570, 17) } func TestCouchdbStatsV1Integration(t *testing.T) { diff --git a/lib/collector-v1.go b/lib/collector-v1.go index 9d868aa2..3fec993d 100644 --- a/lib/collector-v1.go +++ b/lib/collector-v1.go @@ -20,7 +20,7 @@ func (e *Exporter) collectV1(stats Stats, exposedHttpStatusCodes []string, colle e.databaseWrites.WithLabelValues(name).Set(nodeStats.Couchdb.DatabaseWrites.Current) e.openDatabases.WithLabelValues(name).Set(nodeStats.Couchdb.OpenDatabases.Current) e.openOsFiles.WithLabelValues(name).Set(nodeStats.Couchdb.OpenOsFiles.Current) - e.requestTime.WithLabelValues(name).Set(nodeStats.Couchdb.RequestTime.Current) + e.requestTime.WithLabelValues(name, "Current").Set(nodeStats.Couchdb.RequestTime.Current) for _, code := range exposedHttpStatusCodes { if _, ok := nodeStats.HttpdStatusCodes[code]; ok { diff --git a/lib/collector-v2.go b/lib/collector-v2.go index f751c7e4..972d611c 100644 --- a/lib/collector-v2.go +++ b/lib/collector-v2.go @@ -20,7 +20,23 @@ func (e *Exporter) collectV2(stats Stats, exposedHttpStatusCodes []string, colle e.databaseWrites.WithLabelValues(name).Set(nodeStats.Couchdb.DatabaseWrites.Value) e.openDatabases.WithLabelValues(name).Set(nodeStats.Couchdb.OpenDatabases.Value) e.openOsFiles.WithLabelValues(name).Set(nodeStats.Couchdb.OpenOsFiles.Value) - e.requestTime.WithLabelValues(name).Set(nodeStats.Couchdb.RequestTime.Value.Median) + + e.requestTime.WithLabelValues(name, "Min").Set(nodeStats.Couchdb.RequestTime.Value.Min) + e.requestTime.WithLabelValues(name, "Max").Set(nodeStats.Couchdb.RequestTime.Value.Max) + e.requestTime.WithLabelValues(name, "ArithmeticMean").Set(nodeStats.Couchdb.RequestTime.Value.ArithmeticMean) + e.requestTime.WithLabelValues(name, "GeometricMean").Set(nodeStats.Couchdb.RequestTime.Value.GeometricMean) + e.requestTime.WithLabelValues(name, "HarmonicMean").Set(nodeStats.Couchdb.RequestTime.Value.HarmonicMean) + e.requestTime.WithLabelValues(name, "Median").Set(nodeStats.Couchdb.RequestTime.Value.Median) + e.requestTime.WithLabelValues(name, "Variance").Set(nodeStats.Couchdb.RequestTime.Value.Variance) + e.requestTime.WithLabelValues(name, "StandardDeviation").Set(nodeStats.Couchdb.RequestTime.Value.StandardDeviation) + e.requestTime.WithLabelValues(name, "Skewness").Set(nodeStats.Couchdb.RequestTime.Value.Skewness) + e.requestTime.WithLabelValues(name, "Kurtosis").Set(nodeStats.Couchdb.RequestTime.Value.Kurtosis) + e.requestTime.WithLabelValues(name, "p50").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[0][1]) + e.requestTime.WithLabelValues(name, "p75").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[1][1]) + e.requestTime.WithLabelValues(name, "p90").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[2][1]) + e.requestTime.WithLabelValues(name, "p95").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[3][1]) + e.requestTime.WithLabelValues(name, "p99").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[4][1]) + e.requestTime.WithLabelValues(name, "p999").Set(nodeStats.Couchdb.RequestTime.Value.Percentile[5][1]) for _, level := range exposedLogLevels { e.couchLog.WithLabelValues(level, name).Set(nodeStats.CouchLog.Level[level].Value) diff --git a/lib/collector.go b/lib/collector.go index 30fc396f..2ec62636 100644 --- a/lib/collector.go +++ b/lib/collector.go @@ -68,6 +68,24 @@ var ( "owner_crashes", "worker_crashes", "closes"} + + exposedRequestTimes = []string{ + "Min", + "Max", + "ArithmeticMean", + "GeometricMean", + "HarmonicMean", + "Median", + "Variance", + "StandardDeviation", + "Skewness", + "Kurtosis"} + + exposedPercentiles = []string{ + "p50", + "p75", + "p99", + "p999"} ) type CollectorConfig struct { diff --git a/lib/couchdb-stats.go b/lib/couchdb-stats.go index fa7917d4..27726f10 100644 --- a/lib/couchdb-stats.go +++ b/lib/couchdb-stats.go @@ -15,19 +15,22 @@ type Counter struct { Desc string } +type Percent map[int]float64 + // v2.x api type HistogramValue struct { - Min float64 `json:"min"` - Max float64 `json:"max"` - ArithmeticMean float64 `json:"arithmetic_mean"` - GeometricMean float64 `json:"geometric_mean"` - HarmonicMean float64 `json:"harmonic_mean"` - Median float64 `json:"median"` - Variance float64 `json:"variance"` - StandardDeviation float64 `json:"standard_deviation"` - Skewness float64 `json:"skewness"` - Kurtosis float64 `json:"kurtosis"` - N float64 `json:"n"` + Min float64 `json:"min"` + Max float64 `json:"max"` + ArithmeticMean float64 `json:"arithmetic_mean"` + GeometricMean float64 `json:"geometric_mean"` + HarmonicMean float64 `json:"harmonic_mean"` + Median float64 `json:"median"` + Variance float64 `json:"variance"` + StandardDeviation float64 `json:"standard_deviation"` + Skewness float64 `json:"skewness"` + Kurtosis float64 `json:"kurtosis"` + Percentile [][]float64 `json:"percentile"` + N float64 `json:"n"` } type Histogram struct { diff --git a/lib/exporter.go b/lib/exporter.go index 57414ba5..92904740 100644 --- a/lib/exporter.go +++ b/lib/exporter.go @@ -55,13 +55,10 @@ type Exporter struct { couchLog *prometheus.GaugeVec - fabricWorker *prometheus.GaugeVec - fabricOpenShard *prometheus.GaugeVec - fabricReadRepairs *prometheus.GaugeVec - fabricFailure *prometheus.GaugeVec - fabricDocUpdate *prometheus.GaugeVec - fabricMismatchedErrors *prometheus.GaugeVec - fabricWriteQuorumErrors *prometheus.GaugeVec + fabricWorker *prometheus.GaugeVec + fabricOpenShard *prometheus.GaugeVec + fabricReadRepairs *prometheus.GaugeVec + fabricDocUpdate *prometheus.GaugeVec couchReplicatorChangesReadFailures *prometheus.GaugeVec couchReplicatorChangesReaderDeaths *prometheus.GaugeVec @@ -195,7 +192,7 @@ func NewExporter(uri string, basicAuth BasicAuth, collectorConfig CollectorConfi Name: "request_time", Help: "length of a request inside CouchDB without MochiWeb", }, - []string{"node_name"}), + []string{"node_name", "metric"}), httpdStatusCodes: prometheus.NewGaugeVec( prometheus.GaugeOpts{