aboutsummaryrefslogtreecommitdiffstats
path: root/http/http.go
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-01-12 00:04:23 +0100
committerMartin Polden <mpolden@mpolden.no>2020-01-12 00:04:23 +0100
commit8f942b848ee4ed8cc06bdfe7107b3358cee0e39b (patch)
tree5671d2e0db805323d629a9e9bdbe443dd8a58672 /http/http.go
parent6e9697ef071fceeae3fc9d1fe024034717fd47a2 (diff)
Add cache metrics
Diffstat (limited to 'http/http.go')
-rw-r--r--http/http.go44
1 files changed, 30 insertions, 14 deletions
diff --git a/http/http.go b/http/http.go
index 3bf047c..3da9b4f 100644
--- a/http/http.go
+++ b/http/http.go
@@ -33,10 +33,14 @@ type entry struct {
Rcode string `json:"rcode,omitempty"`
}
+type stats struct {
+ Summary summary `json:"summary"`
+ Requests []request `json:"requests"`
+}
+
type summary struct {
- Since string `json:"since"`
- Total int64 `json:"total"`
- Hijacked int64 `json:"hijacked"`
+ Log logStats `json:"log"`
+ Cache cacheStats `json:"cache"`
}
type request struct {
@@ -45,8 +49,14 @@ type request struct {
}
type logStats struct {
- Summary summary `json:"summary"`
- Requests []request `json:"requests"`
+ Since string `json:"since"`
+ Total int64 `json:"total"`
+ Hijacked int64 `json:"hijacked"`
+}
+
+type cacheStats struct {
+ Size int `json:"size"`
+ Capacity int `json:"capacity"`
}
type httpError struct {
@@ -137,26 +147,32 @@ func (s *Server) logHandler(w http.ResponseWriter, r *http.Request) (interface{}
}
func (s *Server) metricHandler(w http.ResponseWriter, r *http.Request) (interface{}, *httpError) {
- stats, err := s.logger.Stats()
+ lstats, err := s.logger.Stats()
if err != nil {
return nil, newHTTPError(err)
}
- requests := make([]request, 0, len(stats.Events))
- for _, e := range stats.Events {
+ requests := make([]request, 0, len(lstats.Events))
+ for _, e := range lstats.Events {
requests = append(requests, request{
Time: e.Time.Format(time.RFC3339),
Count: e.Count,
})
}
- logStats := logStats{
+ cstats := s.cache.Stats()
+ return stats{
Summary: summary{
- Since: stats.Since.Format(time.RFC3339),
- Total: stats.Total,
- Hijacked: stats.Hijacked,
+ Log: logStats{
+ Since: lstats.Since.Format(time.RFC3339),
+ Total: lstats.Total,
+ Hijacked: lstats.Hijacked,
+ },
+ Cache: cacheStats{
+ Capacity: cstats.Capacity,
+ Size: cstats.Size,
+ },
},
Requests: requests,
- }
- return logStats, nil
+ }, nil
}
// Close shuts down the HTTP server.