Install Alloy Binary and Start as a Service
Description
Now we will create the Alloy agent service that will act as the collector for Loki.
We can also get the Alloy binary from github.
To check the latest version of Alloy, visit its releases page.
https://github.com/grafana/alloy/releases
# |
|
# |
|
# |
|
And allow the execute
permission on the Alloy binary.
# |
|
Create the Alloy config
Create a new file named config.alloy
.
# |
|
Copy/paste this content below into it.
local.file_match "system" {
path_targets = [{
__address__ = "localhost",
__path__ = "/var/log/*log",
job = "varlogs",
stream = "stdout",
}]
}
loki.source.file "system" {
targets = local.file_match.system.targets
forward_to = [loki.write.default.receiver]
legacy_positions_file = "/tmp/positions.yaml"
}
loki.write "default" {
endpoint {
url = "http://localhost:3100/loki/api/v1/push"
}
external_labels = {}
}
Configure Alloy as a Service
Now we will configure Alloy as a service so that we can keep it running in the background.
Create user specifically for the Alloy service
# |
|
Create a file named alloy.service
.
# |
|
And add this script,
1 2 3 4 5 6 7 8 9 10 11 |
|
Now start and check the service is running.
# # # |
|
We can now leave the new Alloy service running.
Read Alloy logs
# |
|
Explore in Grafana
Open the Explore tab, select the Loki datasource, and use {job="varlogs"}
as your first query.
To Convert a Promtail Config to Alloy
This command will read an existing promtail-local-config.yaml
, re-create it in the Alloy format and save it as config.alloy
.
# # |
|