this post was submitted on 27 Mar 2024
19 points (95.2% liked)

DevOps

1685 readers
3 users here now

DevOps integrates and automates the work of software development (Dev) and IT operations (Ops) as a means for improving and shortening the systems development life cycle.

Rules:

Icon base by Lorc under CC BY 3.0 with modifications to add a gradient

founded 1 year ago
MODERATORS
 

Out of principle I refuse to put any type of analytics on my sites. I don't want to send user data to third parties and I don't want to rely on data that comes from JavaScript on the browser unless strictly necessary.

But the thought recently occurred to me that I could use my server logs to create some basic data visualisation on Grafana.

I'd like very basic stuff:

  • hits
  • common referrers
  • geo location by IP address
  • bounce rates per page

What would be the recommended way to get this, assuming that I have traefik logs aggregates via Loki and Grafana installed?

top 6 comments
sorted by: hot top controversial new old
[–] [email protected] 5 points 7 months ago* (last edited 7 months ago) (1 children)

I did something very similar with Opensearch rather than grafana, but it’s definitely possible. My setup:

  • fluent-bit installed on webserver to scrape and parse nginx logs, then forward them over TLS to the monitoring server
  • on the monitoring server, a second fluent-bit service runs here to collect the forwarded logs and insert them into the correct index pattern. A filter also inserts geoip lookups into the records.
  • opensearch & dashboards set up to exclude known “bot” user-agents from the analytics, and do some other basic data cleanup to make the dashboards pretty

It works well, but could be a bit simpler admittedly. You may choose to use Loki instead of Opensearch/Elasticsearch, and there are plenty of other log parsing tools out there.

Another, much simpler option is to just run Goaccess on your log files, either periodically to generate reports, or as a daemon to create a live dashboard.

[–] [email protected] 1 points 7 months ago

Thanks, I think my question now is about figuring out if there is any ready-made dashboard for grafana. Maybe I just need to look a bit more.

[–] dbx12 3 points 7 months ago

I think you could also use awstats, which runs on the log files produced by your web server.

[–] Lodra 2 points 7 months ago

Professionally, I’ve spent the last year almost entirely focused on o11y, a numeronym for observability. IMO you want to run opentelemetry (aka otel) for a lot of this stuff. It’s a fantastic tool. We tell clients that if they don’t use otel, then they’re probably doing o11y wrong.

You can run it as a collector to scrape log files. If your apps are instrumented, they can emit telemetry via OTLP to otel instead. Then otel can process and export the data to various data backends like Minor (metrics), Loki (logs), and Tempo (traces). Then use Grafana for a UI. That particular set of tools is known as the LGTM stack. if you only want to handle logs, your stack could be simpler: otel, Loki, and Grafana.

A final thought is about a seeming want for metrics generated from logs. Otel can do that for you too.

[–] anzo 1 points 7 months ago (1 children)
[–] [email protected] 1 points 7 months ago

Both of them require use of client-side Javascript, which is blocked by most privacy extensions and browsers like Brave.