diff options
author | Oscar Najera <hi@oscarnajera.com> | 2025-02-10 02:08:51 +0100 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2025-02-10 02:08:51 +0100 |
commit | 0967597ff39c925bd746223b994922e632a0c98e (patch) | |
tree | b732389062227b84aedce0d5044cd4d68c9ceb1d | |
parent | 7b90ec0b14a0114f055a26e2f29f92a3f771c87e (diff) | |
download | scratch-0967597ff39c925bd746223b994922e632a0c98e.tar.gz scratch-0967597ff39c925bd746223b994922e632a0c98e.tar.bz2 scratch-0967597ff39c925bd746223b994922e632a0c98e.zip |
stats for separate domains
-rw-r--r-- | webstats/queries.sql | 12 | ||||
-rw-r--r-- | webstats/server.lisp | 15 | ||||
-rw-r--r-- | webstats/stats.paren | 24 |
3 files changed, 45 insertions, 6 deletions
diff --git a/webstats/queries.sql b/webstats/queries.sql index 5e16da0..5a8a0ae 100644 --- a/webstats/queries.sql +++ b/webstats/queries.sql @@ -30,3 +30,15 @@ FROM STATS GROUP BY 1; + +-- name: activity-places +-- timeseries of loaded places +SELECT + (timestamp / 600) * 600 AS time, + count(page) FILTER (WHERE page LIKE 'http://localhost:4252%') AS stats, + count(page) FILTER (WHERE page LIKE 'http://localhost/%') AS stats_proxy, + count(page) FILTER (WHERE page LIKE 'http://localhost:1313%') AS blog +FROM + STATS +GROUP BY + 1 diff --git a/webstats/server.lisp b/webstats/server.lisp index a253b91..3fe237a 100644 --- a/webstats/server.lisp +++ b/webstats/server.lisp @@ -54,11 +54,16 @@ (setf (hunchentoot:content-type*) "text/javascript") (ps:ps-compile-file "stats.paren")) -(hunchentoot:define-easy-handler (metric :uri "/metric.json") () +(hunchentoot:define-easy-handler (metric :uri "/metric.json") (q) (setf (hunchentoot:content-type*) "application/json") - (let ((series (activity-stats *sqlite*))) - (cl-json:encode-json-to-string - (apply #'mapcar #'list series)))) + (cl-json:encode-json-to-string + (apply #'mapcar #'list + (cond + ((string= q "all") + (activity-stats *sqlite*)) + ((string= q "split") + (activity-places *sqlite*)) + ((list (list))))))) (hunchentoot:define-easy-handler (graphs :uri "/graphs") () (with-html-string @@ -79,7 +84,7 @@ (add-event-listener "load" (lambda () - (ps:chain (fetch "/stats/metric.json") + (ps:chain (fetch "/stats/metric.json?q=all") (then #'response-to-json) (then #'plot))))))))))) diff --git a/webstats/stats.paren b/webstats/stats.paren index 6491020..43c1be4 100644 --- a/webstats/stats.paren +++ b/webstats/stats.paren @@ -44,6 +44,9 @@ (chain response (json)) (throw (new (-error "not 2XX resp"))))) +(defun spaced-color (idx) + (concatenate 'string "hsl(" (* 137.506 idx) ",70%,55%)")) + (defun plot (data) (new (u-plot @@ -57,8 +60,27 @@ data (chain document (get-element-by-id "graph"))))) +(defun plot-site (data) + (new + (u-plot + (create + :title "Individual Site activity visits" + :width 450 + :height 400 + :cursor (create sync (create key "moo")) + :series (list (create label "Time") + (create label "stats" stroke (spaced-color 0)) + (create label "proxy" stroke (spaced-color 1)) + (create label "blog" stroke (spaced-color 2)))) + data + (chain document (get-element-by-id "graph"))))) + (add-event-listener "load" (lambda () (instrument-links) - (register-page-load))) + (register-page-load) + + (ps:chain (fetch "/stats/metric.json?q=split") + (then #'response-to-json) + (then #'plot-site)))) |