Skip to content

Commit

Permalink
Merge pull request #58 from myaser/histogram
Browse files Browse the repository at this point in the history
migrate to histogram
  • Loading branch information
zbindenren authored Nov 22, 2022
2 parents 13484e6 + 18e1f48 commit 1269eab
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ All performed checks expose metrics which can be used to monitor/alert:

At `/metrics` you will find these:
- `kubenurse_errors_total`: Kubenurse error counter partitioned by error type
- `kubenurse_request_duration`: Kubenurse request duration partitioned by error type, summary over one minute
- `kubenurse_request_duration`: a histogram for Kubenurse request duration partitioned by error type
2 changes: 1 addition & 1 deletion doc/grafana-kubenurse.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"steppedLine": false,
"targets": [
{
"expr": "kubenurse_request_duration{quantile=\"0.9\", type=~\"$type\"}",
"expr": "histogram_quantile(0.9, rate(kubenurse_request_duration{type=~\"$type\"}[1m]))",
"interval": "",
"legendFormat": "{{pod}}: {{type}}",
"refId": "A"
Expand Down
19 changes: 9 additions & 10 deletions internal/servicecheck/servicecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ func New(ctx context.Context, discovery *kubediscovery.Client, promRegistry *pro
[]string{"type"},
)

durationSummary := prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: metricsNamespace,
Name: "request_duration",
Help: "Kubenurse request duration partitioned by error type",
MaxAge: 1 * time.Minute,
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
durationHistogram := prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: metricsNamespace,
Name: "request_duration",
Help: "Kubenurse request duration partitioned by target path",
Buckets: prometheus.DefBuckets,
},
[]string{"type"},
)

promRegistry.MustRegister(errorCounter, durationSummary)
promRegistry.MustRegister(errorCounter, durationHistogram)

// setup http transport
transport, err := generateRoundTripper(os.Getenv("KUBENURSE_EXTRA_CA"), os.Getenv("KUBENURSE_INSECURE") == "true")
Expand All @@ -65,7 +64,7 @@ func New(ctx context.Context, discovery *kubediscovery.Client, promRegistry *pro
httpClient: httpClient,
cacheTTL: cacheTTL,
errorCounter: errorCounter,
durationSummary: durationSummary,
durationHistogram: durationHistogram,
stop: make(chan struct{}),
}, nil
}
Expand Down Expand Up @@ -210,7 +209,7 @@ func (c *Checker) measure(check Check, label string) (string, error) {
res, err := check()

// Process metrics
c.durationSummary.WithLabelValues(label).Observe(time.Since(start).Seconds())
c.durationHistogram.WithLabelValues(label).Observe(time.Since(start).Seconds())

if err != nil {
log.Printf("failed request for %s with %v", label, err)
Expand Down
4 changes: 2 additions & 2 deletions internal/servicecheck/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Checker struct {
discovery *kubediscovery.Client

// metrics
errorCounter *prometheus.CounterVec
durationSummary *prometheus.SummaryVec
errorCounter *prometheus.CounterVec
durationHistogram *prometheus.HistogramVec

// Http Client for https requests
httpClient *http.Client
Expand Down

0 comments on commit 1269eab

Please sign in to comment.