Skip to content

Commit 1269eab

Browse files
authored
Merge pull request #58 from myaser/histogram
migrate to histogram
2 parents 13484e6 + 18e1f48 commit 1269eab

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ All performed checks expose metrics which can be used to monitor/alert:
209209

210210
At `/metrics` you will find these:
211211
- `kubenurse_errors_total`: Kubenurse error counter partitioned by error type
212-
- `kubenurse_request_duration`: Kubenurse request duration partitioned by error type, summary over one minute
212+
- `kubenurse_request_duration`: a histogram for Kubenurse request duration partitioned by error type

doc/grafana-kubenurse.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"steppedLine": false,
6767
"targets": [
6868
{
69-
"expr": "kubenurse_request_duration{quantile=\"0.9\", type=~\"$type\"}",
69+
"expr": "histogram_quantile(0.9, rate(kubenurse_request_duration{type=~\"$type\"}[1m]))",
7070
"interval": "",
7171
"legendFormat": "{{pod}}: {{type}}",
7272
"refId": "A"

internal/servicecheck/servicecheck.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ func New(ctx context.Context, discovery *kubediscovery.Client, promRegistry *pro
3333
[]string{"type"},
3434
)
3535

36-
durationSummary := prometheus.NewSummaryVec(
37-
prometheus.SummaryOpts{
38-
Namespace: metricsNamespace,
39-
Name: "request_duration",
40-
Help: "Kubenurse request duration partitioned by error type",
41-
MaxAge: 1 * time.Minute,
42-
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
36+
durationHistogram := prometheus.NewHistogramVec(
37+
prometheus.HistogramOpts{
38+
Namespace: metricsNamespace,
39+
Name: "request_duration",
40+
Help: "Kubenurse request duration partitioned by target path",
41+
Buckets: prometheus.DefBuckets,
4342
},
4443
[]string{"type"},
4544
)
4645

47-
promRegistry.MustRegister(errorCounter, durationSummary)
46+
promRegistry.MustRegister(errorCounter, durationHistogram)
4847

4948
// setup http transport
5049
transport, err := generateRoundTripper(os.Getenv("KUBENURSE_EXTRA_CA"), os.Getenv("KUBENURSE_INSECURE") == "true")
@@ -65,7 +64,7 @@ func New(ctx context.Context, discovery *kubediscovery.Client, promRegistry *pro
6564
httpClient: httpClient,
6665
cacheTTL: cacheTTL,
6766
errorCounter: errorCounter,
68-
durationSummary: durationSummary,
67+
durationHistogram: durationHistogram,
6968
stop: make(chan struct{}),
7069
}, nil
7170
}
@@ -210,7 +209,7 @@ func (c *Checker) measure(check Check, label string) (string, error) {
210209
res, err := check()
211210

212211
// Process metrics
213-
c.durationSummary.WithLabelValues(label).Observe(time.Since(start).Seconds())
212+
c.durationHistogram.WithLabelValues(label).Observe(time.Since(start).Seconds())
214213

215214
if err != nil {
216215
log.Printf("failed request for %s with %v", label, err)

internal/servicecheck/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type Checker struct {
3434
discovery *kubediscovery.Client
3535

3636
// metrics
37-
errorCounter *prometheus.CounterVec
38-
durationSummary *prometheus.SummaryVec
37+
errorCounter *prometheus.CounterVec
38+
durationHistogram *prometheus.HistogramVec
3939

4040
// Http Client for https requests
4141
httpClient *http.Client

0 commit comments

Comments
 (0)