Skip to content

Commit

Permalink
Add proper buckets for request/response sizes.
Browse files Browse the repository at this point in the history
    - default buckets in prom are for time, not transfer.
    - adjusts code to create proper bucketing for traffic sizes.
  • Loading branch information
76b900 authored and aldas committed Apr 5, 2022
1 parent 79225fb commit 102f2a9
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ import (
var defaultMetricPath = "/metrics"
var defaultSubsystem = "echo"

const (
_ = iota // ignore first value by assigning to blank identifier
KB float64 = 1 << (10 * iota)
MB
GB
TB
)

// reqDurBuckets is the buckets for request duration. Here, we use the prometheus defaults
// which are for ~10s request length max: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10}
var reqDurBuckets = prometheus.DefBuckets

// reqSzBuckets is the buckets for request size. Here we define a spectrom from 1KB thru 1NB up to 10MB.
var reqSzBuckets = []float64{1.0 * KB, 2.0 * KB, 5.0 * KB, 10.0 * KB, 100 * KB, 500 * KB, 1.0 * MB, 2.5 * MB, 5.0 * MB, 10.0 * MB}

// resSzBuckets is the buckets for response size. Here we define a spectrom from 1KB thru 1NB up to 10MB.
var resSzBuckets = []float64{1.0 * KB, 2.0 * KB, 5.0 * KB, 10.0 * KB, 100 * KB, 500 * KB, 1.0 * MB, 2.5 * MB, 5.0 * MB, 10.0 * MB}

// Standard default metrics
// counter, counter_vec, gauge, gauge_vec,
// histogram, histogram_vec, summary, summary_vec
Expand All @@ -54,21 +72,24 @@ var reqDur = &Metric{
Name: "request_duration_seconds",
Description: "The HTTP request latencies in seconds.",
Args: []string{"code", "method", "url"},
Type: "histogram_vec"}
Type: "histogram_vec",
Buckets: reqDurBuckets}

var resSz = &Metric{
ID: "resSz",
Name: "response_size_bytes",
Description: "The HTTP response sizes in bytes.",
Args: []string{"code", "method", "url"},
Type: "histogram_vec"}
Type: "histogram_vec",
Buckets: resSzBuckets}

var reqSz = &Metric{
ID: "reqSz",
Name: "request_size_bytes",
Description: "The HTTP request sizes in bytes.",
Args: []string{"code", "method", "url"},
Type: "histogram_vec"}
Type: "histogram_vec",
Buckets: reqSzBuckets}

var standardMetrics = []*Metric{
reqCnt,
Expand Down Expand Up @@ -108,6 +129,7 @@ type Metric struct {
Description string
Type string
Args []string
Buckets []float64
}

// Prometheus contains the metrics gathered by the instance and its path
Expand Down Expand Up @@ -307,6 +329,7 @@ func NewMetric(m *Metric, subsystem string) prometheus.Collector {
Subsystem: subsystem,
Name: m.Name,
Help: m.Description,
Buckets: m.Buckets,
},
m.Args,
)
Expand All @@ -316,6 +339,7 @@ func NewMetric(m *Metric, subsystem string) prometheus.Collector {
Subsystem: subsystem,
Name: m.Name,
Help: m.Description,
Buckets: m.Buckets,
},
)
case "summary_vec":
Expand Down

3 comments on commit 102f2a9

@AntonChubarov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! Why this commit is not included to recent tag and when it will be?

@aldas
Copy link
Contributor

@aldas aldas commented on 102f2a9 Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tagged a new release v0.13.0 it is included there.

@AntonChubarov
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much!

Please sign in to comment.