Skip to content

Commit 366d50b

Browse files
authored
Merge pull request #2 from shaheed121/add_upstream_header_time
Add http_upstream_header_time_seconds metrics
2 parents cb4d7a3 + f91e6b0 commit 366d50b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ LINES:
195195
}
196196
}
197197

198+
if headerTime, err := entry.Field("upstream_header_time"); err == nil {
199+
if totalTime, err := parseUpstreamTime(headerTime); err == nil {
200+
logger.Debug("(%s): matched upstream_header_time to %.3f", file, totalTime)
201+
metrics.upstreamHeaderSeconds.WithLabelValues(labelValues...).Observe(totalTime)
202+
} else {
203+
logger.Warn("(%s): failed to parse upstream_header_time field", file, err)
204+
}
205+
}
206+
198207
if responseTime, err := entry.FloatField("request_time"); err == nil {
199208
logger.Debug("(%s): matched request_time to %.3f", file, responseTime)
200209
metrics.requestSeconds.WithLabelValues(labelValues...).Observe(responseTime)

metrics.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66

77
// metrics is the struct that contains pointers to our metric containers.
88
type metrics struct {
9-
bodyBytes *prometheus.HistogramVec
10-
upstreamSeconds *prometheus.HistogramVec
11-
requestSeconds *prometheus.HistogramVec
9+
bodyBytes *prometheus.HistogramVec
10+
upstreamHeaderSeconds *prometheus.HistogramVec
11+
upstreamSeconds *prometheus.HistogramVec
12+
requestSeconds *prometheus.HistogramVec
1213
}
1314

1415
// newMetrics creates a new metrics based on the provided application and
@@ -35,11 +36,19 @@ func newMetrics(application string, labelNames []string) *metrics {
3536
ConstLabels: prometheus.Labels{"application": application},
3637
}, labelNames)
3738

38-
prometheus.MustRegister(bodyBytes, upstreamSeconds, requestSeconds)
39+
upstreamHeaderSeconds := prometheus.NewHistogramVec(prometheus.HistogramOpts{
40+
Namespace: "nginx",
41+
Name: "http_upstream_header_time_seconds",
42+
Help: "Time to receiving the first byte of the response header from upstream servers",
43+
ConstLabels: prometheus.Labels{"application": application},
44+
}, labelNames)
45+
46+
prometheus.MustRegister(bodyBytes, upstreamHeaderSeconds, upstreamSeconds, requestSeconds)
3947

4048
return &metrics{
41-
bodyBytes: bodyBytes,
42-
requestSeconds: requestSeconds,
43-
upstreamSeconds: upstreamSeconds,
49+
bodyBytes: bodyBytes,
50+
requestSeconds: requestSeconds,
51+
upstreamSeconds: upstreamSeconds,
52+
upstreamHeaderSeconds: upstreamHeaderSeconds,
4453
}
4554
}

0 commit comments

Comments
 (0)