Install Alloy
Config
Edit/etc/alloy/config.alloy:
local.file_match
local.file_match
Defines the log files Alloy should watch. Each entry in
path_targets is a file path plus labels (job, app, host, type) that get attached to every log line shipped from that file — these labels are what you filter on later in Grafana/Loki queries.loki.source.file
loki.source.file
Tails the files matched above and forwards new log lines to the configured receiver.
loki.write
loki.write
Pushes the collected logs to Loki’s push API. The endpoint matches the Loki setup running on port
4100 (http://127.0.0.1:4100/loki/api/v1/push).Add a new block inside
path_targets for every new app you deploy — just point __path__ at its PM2 log file and give it a unique app label.systemd service
The Alloy package installs a systemd service automatically at/etc/systemd/system/alloy.service. Enable and start it: