- Confirm you can query existing system logs with LogQL.
- Verify the application is writing logs to a local file.
- Update Alloy’s configuration to scrape that file and send logs to Loki.
- Restart Alloy and verify logs appear in Grafana.
1) Verify system logs (LogQL)
Start by confirming you can query system logs using a LogQL query:2) Confirm the application is writing to a file
On the node, inspect the application directory and confirm the app log exists:3) Update Alloy configuration to scrape the application log
Edit/etc/alloy/config.alloy and add a file match for the application log plus a Loki write endpoint. Below is a concise example showing the minimal blocks required to collect both system logs (wildcard path) and the specific application log:
path_targetsidentifies files to scrape; for the app example we used/home/bob/app/app.log.tail_from_end = trueensures the collector tails from the end of the file on startup, avoiding re-ingestion of historical lines after restarts.- You can either reuse an existing source and add targets, or create a dedicated
loki.source.filefor application logs as shown.
Be sure to use
sudo when editing /etc/alloy/config.alloy and restarting the service.4) Restart Alloy and confirm it’s running
After saving your changes, restart Alloy and check service status:5) Verify logs in Grafana / Loki
Open Grafana (or your Loki query UI) and run a LogQL query targeting the application filename:Links and references
- Alloy documentation: https://grafana.com/docs/alloy
- Grafana Loki documentation: https://grafana.com/docs/loki
- LogQL reference: https://grafana.com/docs/loki/latest/logql/