Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented Last-Modified HTTP header metric #407

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
Name: "probe_failed_due_to_regex",
Help: "Indicates if probe failed due to regex",
})

probeHTTPLastModified = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_http_last_modified_timestamp_seconds",
Help: "Returns the Last-Modified HTTP response header in unixtime",
})
)

for _, lv := range []string{"resolve", "connect", "tls", "processing", "transfer"} {
Expand Down Expand Up @@ -337,6 +342,12 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
// At this point body is fully read and we can write end time.
tt.current.end = time.Now()

// Check if there is a Last-Modified HTTP response header.
if t, err := http.ParseTime(resp.Header.Get("Last-Modified")); err == nil {
registry.MustRegister(probeHTTPLastModified)
probeHTTPLastModified.Set(float64(t.Unix()))
}

var httpVersionNumber float64
httpVersionNumber, err = strconv.ParseFloat(strings.TrimPrefix(resp.Proto, "HTTP/"), 64)
if err != nil {
Expand Down