Skip to content

Commit c625bef

Browse files
Merge pull request #65 from martin-helmich/feature/configurable-buckets
Make histogram buckets configurable
2 parents ca4a2dc + 804ab58 commit c625bef

File tree

6 files changed

+16
-5
lines changed

6 files changed

+16
-5
lines changed

README.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace "app1" {
100100
environment = "production"
101101
foo = "bar"
102102
}
103+
104+
histogram_buckets = [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
103105
}
104106
105107
namespace "app2" {
@@ -138,6 +140,7 @@ namespaces:
138140
app: "application-one"
139141
environment: "production"
140142
foo: "bar"
143+
histogram_buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
141144
- name: app2
142145
format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\" $upstream_response_time"
143146
source_files:

config/struct_namespace.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77

88
// NamespaceConfig is a struct describing single metric namespaces
99
type NamespaceConfig struct {
10-
Name string `hcl:",key"`
11-
SourceFiles []string `hcl:"source_files" yaml:"source_files"`
12-
Format string `hcl:"format"`
13-
Labels map[string]string `hcl:"labels"`
14-
RelabelConfigs []RelabelConfig `hcl:"relabel" yaml:"relabel_configs"`
10+
Name string `hcl:",key"`
11+
SourceFiles []string `hcl:"source_files" yaml:"source_files"`
12+
Format string `hcl:"format"`
13+
Labels map[string]string `hcl:"labels"`
14+
RelabelConfigs []RelabelConfig `hcl:"relabel" yaml:"relabel_configs"`
15+
HistogramBuckets []float64 `hcl:"histogram_buckets" yaml:"histogram_buckets"`
1516

1617
OrderedLabelNames []string
1718
OrderedLabelValues []string

example-config.hcl

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace "nginx" {
2727
foo = "bar"
2828
}
2929

30+
histogram_buckets = [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
31+
3032
relabel "user" {
3133
from = "remote_user"
3234
// whitelist = ["-", "user1", "user2"]

features/test-configuration.hcl

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ port = 4040
33
namespace "nginx" {
44
source_files = [".behave-sandbox/access-1.log"]
55
format = "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\""
6+
7+
histogram_buckets = [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
68
}
79

810
namespace "apache" {

features/test-configuration.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespaces:
66
source_files:
77
- .behave-sandbox/access-1.log
88
format: "$remote_addr - $remote_user [$time_local] \"$request\" $status $body_bytes_sent \"$http_referer\" \"$http_user_agent\" \"$http_x_forwarded_for\""
9+
histogram_buckets: [.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10]
910
- name: apache
1011
source_files:
1112
- .behave-sandbox/access-2.log

main.go

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (m *Metrics) Init(cfg *config.NamespaceConfig) {
8383
Namespace: cfg.Name,
8484
Name: "http_upstream_time_seconds_hist",
8585
Help: "Time needed by upstream servers to handle requests",
86+
Buckets: cfg.HistogramBuckets,
8687
}, labels)
8788

8889
m.responseSeconds = prometheus.NewSummaryVec(prometheus.SummaryOpts{
@@ -95,6 +96,7 @@ func (m *Metrics) Init(cfg *config.NamespaceConfig) {
9596
Namespace: cfg.Name,
9697
Name: "http_response_time_seconds_hist",
9798
Help: "Time needed by NGINX to handle requests",
99+
Buckets: cfg.HistogramBuckets,
98100
}, labels)
99101

100102
m.parseErrorsTotal = prometheus.NewCounter(prometheus.CounterOpts{

0 commit comments

Comments
 (0)