diff --git a/go.mod b/go.mod index e128ade..fe0cd58 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/cenkalti/backoff/v4 v4.0.2 // indirect github.com/emvi/api-go v0.0.0-20191210194347-0a945446f6a8 github.com/emvi/logbuch v1.1.1 - github.com/emvi/pirsch v0.0.0-20200625182355-75f0aba03718 + github.com/emvi/pirsch v0.0.0-20200625233854-9bc410bf1483 github.com/gorilla/mux v1.7.4 github.com/gosimple/slug v1.9.0 github.com/jmoiron/sqlx v1.2.0 diff --git a/go.sum b/go.sum index f4e7092..d6a34c3 100644 --- a/go.sum +++ b/go.sum @@ -97,6 +97,8 @@ github.com/emvi/pirsch v0.0.0-20200625145826-bf2196e7b9f8 h1:m/3rKmlG0s6nlW+yvND github.com/emvi/pirsch v0.0.0-20200625145826-bf2196e7b9f8/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g= github.com/emvi/pirsch v0.0.0-20200625182355-75f0aba03718 h1:FOaeJg2A9rGb5WMZsnW/2SorGesIoVn9doW1Okgt1BU= github.com/emvi/pirsch v0.0.0-20200625182355-75f0aba03718/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g= +github.com/emvi/pirsch v0.0.0-20200625233854-9bc410bf1483 h1:hTW+M/0XaAEn1+bpXL/z2DZAFU1xgvKk56OgL1lodSU= +github.com/emvi/pirsch v0.0.0-20200625233854-9bc410bf1483/go.mod h1:+YmBbltJ3feZz9L/QQyqwywltYvQKBfzrGD51TPKl5g= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/exoscale/egoscale v0.18.1/go.mod h1:Z7OOdzzTOz1Q1PjQXumlz9Wn/CddH0zSYdCF3rnBKXE= diff --git a/main.go b/main.go index 4609b8a..cf4a60f 100644 --- a/main.go +++ b/main.go @@ -119,6 +119,7 @@ func serveBlogArticle() http.HandlerFunc { func serveTracking() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + tracker.Hit(r) start, _ := strconv.Atoi(r.URL.Query().Get("start")) if start > 365 { @@ -128,18 +129,30 @@ func serveTracking() http.HandlerFunc { } totalVisitorsLabels, totalVisitorsDps := tracking.GetTotalVisitors(start) + hourlyVisitorsLabels, hourlyVisitorsDps := tracking.GetHourlyVisitors(start) + hourlyVisitorsTodayLabels, hourlyVisitorsTodayDps := tracking.GetHourlyVisitorsToday() tplCache.RenderWithoutCache(w, "tracking.html", struct { - Start int - TotalVisitorsLabels template.JS - TotalVisitorsDps template.JS - PageVisits []tracking.PageVisits - Languages []pirsch.VisitorLanguage + Start int + TotalVisitorsLabels template.JS + TotalVisitorsDps template.JS + PageVisits []tracking.PageVisits + Languages []pirsch.VisitorLanguage + HourlyVisitorsLabels template.JS + HourlyVisitorsDps template.JS + HourlyVisitorsTodayLabels template.JS + HourlyVisitorsTodayDps template.JS + ActiveVisitors int }{ start, totalVisitorsLabels, totalVisitorsDps, tracking.GetPageVisits(start), tracking.GetLanguages(start), + hourlyVisitorsLabels, + hourlyVisitorsDps, + hourlyVisitorsTodayLabels, + hourlyVisitorsTodayDps, + tracking.GetActiveVisitors(), }) } } diff --git a/template/tracking.html b/template/tracking.html index 9c926da..6f0b5d2 100644 --- a/template/tracking.html +++ b/template/tracking.html @@ -14,13 +14,21 @@ Year

- - - +
+

Active Visitors

+

+ Active within the last five minutes: {{.ActiveVisitors}} +

+ +

Total Visitors

+
+

Visitors Per Hour

+ +

Pages Visits

@@ -57,13 +65,21 @@ - - -