Skip to content

Commit 0fffc9a

Browse files
authored
Merge pull request #3 from anhpt379/master
Make histogram buckets configurable
2 parents 366d50b + bced25e commit 0fffc9a

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

conf/nginx-log-exporter.yaml.example

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ applications:
2121
replace:
2222
- path: "^/api/v4/users/[0-9]+/"
2323
with: "/api/v4/users/<id>/"
24+
histogram_buckets: [.05, .1, .2, .5, 1, 2, 5, 10, 20, 30]
2425
gitlab-pages:
2526
log_files:
2627
- "/var/log/gitlab/nginx/gitlab_pages_access.log"

config.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@ type httpConfig struct {
8080

8181
// appConfig represents a single nginx "application" to export log files for.
8282
type appConfig struct {
83-
Format string
84-
FromBeginning bool `from_beginning`
85-
Labels map[string]string
86-
LogFiles []string `log_files`
83+
Format string
84+
FromBeginning bool `from_beginning`
85+
Labels map[string]string
86+
LogFiles []string `log_files`
87+
HistogramBuckets []float64 `histogram_buckets`
8788

8889
Exclude []filterConfig
8990
Include []filterConfig

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func do_main() error {
7676
// that belong to a single application
7777
func monitorApp(name string, ac *appConfig) {
7878
ln := append(staticLabels, ac.orderedLabelNames...)
79-
metrics := newMetrics(name, ln)
79+
metrics := newMetrics(name, ln, ac.HistogramBuckets)
8080

8181
parser := gonx.NewParser(ac.Format)
8282
for _, file := range ac.LogFiles {

metrics.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,36 @@ type metrics struct {
1414

1515
// newMetrics creates a new metrics based on the provided application and
1616
// label names.
17-
func newMetrics(application string, labelNames []string) *metrics {
17+
func newMetrics(application string, labelNames []string, histogramBuckets []float64) *metrics {
1818
bodyBytes := prometheus.NewHistogramVec(prometheus.HistogramOpts{
1919
Namespace: "nginx",
2020
Name: "http_body_bytes_sent",
2121
Help: "Number of body bytes sent to the client",
22+
Buckets: histogramBuckets,
2223
ConstLabels: prometheus.Labels{"application": application},
2324
}, labelNames)
2425

2526
requestSeconds := prometheus.NewHistogramVec(prometheus.HistogramOpts{
2627
Namespace: "nginx",
2728
Name: "http_request_time_seconds",
2829
Help: "Time spent on processing HTTP requests",
30+
Buckets: histogramBuckets,
2931
ConstLabels: prometheus.Labels{"application": application},
3032
}, labelNames)
3133

3234
upstreamSeconds := prometheus.NewHistogramVec(prometheus.HistogramOpts{
3335
Namespace: "nginx",
3436
Name: "http_upstream_response_time_seconds",
3537
Help: "Time spent on receiving a response from upstream servers",
38+
Buckets: histogramBuckets,
3639
ConstLabels: prometheus.Labels{"application": application},
3740
}, labelNames)
3841

3942
upstreamHeaderSeconds := prometheus.NewHistogramVec(prometheus.HistogramOpts{
4043
Namespace: "nginx",
4144
Name: "http_upstream_header_time_seconds",
4245
Help: "Time to receiving the first byte of the response header from upstream servers",
46+
Buckets: histogramBuckets,
4347
ConstLabels: prometheus.Labels{"application": application},
4448
}, labelNames)
4549

0 commit comments

Comments
 (0)