From 844641a4704570c718fb96d990255a34290236d6 Mon Sep 17 00:00:00 2001 From: Johannes Visintini Date: Thu, 17 Jan 2019 11:00:43 +0100 Subject: [PATCH] Implemented Last-Modified HTTP header metric (#407) This feature returns a probe_http_last_modified metric with the content of the Last-Modified HTTP response header, if it is set by the server. Signed-off-by: Johannes Visintini --- prober/http.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/prober/http.go b/prober/http.go index ed58b96..9aa6104 100644 --- a/prober/http.go +++ b/prober/http.go @@ -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"} { @@ -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 { -- 2.25.1