aboutsummaryrefslogtreecommitdiff
path: root/handler.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-04 23:09:42 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-11-04 23:09:42 +0100
commit53ad91c63c2788a83d0e80985ffa89ce7cdf203f (patch)
tree33b7244bc0e7e036ecb411c2d6dfd2d2bc4f6c8c /handler.go
parent7fb24c41ec04d31d3170c9f26ebdbd6eb2ee5aa5 (diff)
added prometheus metrics
Diffstat (limited to 'handler.go')
-rw-r--r--handler.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/handler.go b/handler.go
index 735d798..e45a78f 100644
--- a/handler.go
+++ b/handler.go
@@ -21,7 +21,16 @@ type appHandler struct {
}
func (a appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(a.instance.Deadline))
+ // export prometheus metrics
+ var now time.Time = time.Now()
+ var statusCode int
+ defer func() {
+ rspcnt.Inc(a.instance.LogParameters.id(), a.endpoint, fmt.Sprintf("%d", statusCode))
+ latency.Observe(time.Now().Sub(now).Seconds(), a.instance.LogParameters.id(), a.endpoint, fmt.Sprintf("%d", statusCode))
+ }()
+ reqcnt.Inc(a.instance.LogParameters.id(), a.endpoint)
+
+ ctx, cancel := context.WithDeadline(r.Context(), now.Add(a.instance.Deadline))
defer cancel()
if r.Method != a.method {
@@ -71,6 +80,7 @@ func addEntry(ctx context.Context, i *Instance, w http.ResponseWriter, r *http.R
if err != nil {
return http.StatusInternalServerError, err
}
+ lastSdiTimestamp.Set(float64(time.Now().Unix()), i.LogParameters.id())
if err := WriteJsonResponse(rsp, w); err != nil {
return http.StatusInternalServerError, err
}
@@ -207,6 +217,8 @@ func getSth(ctx context.Context, i *Instance, w http.ResponseWriter, _ *http.Req
if err != nil {
return http.StatusInternalServerError, err
}
+ lastSthTimestamp.Set(float64(time.Now().Unix()), i.LogParameters.id())
+ lastSthSize.Set(float64(sth.SignedTreeHeadV1.TreeHead.TreeSize), i.LogParameters.id())
if err := WriteJsonResponse(rsp, w); err != nil {
return http.StatusInternalServerError, err
}