Install Alloy Binary and Start as a Service
Video Lecture
(Pay Per View)
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.
alloy v1.10.2
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.
Add alloy user to adm group.
So add the user alloy
to the adm
group
# |
|
Verify that the user is now in the adm
group
# |
|
Restart Alloy and check status
# # |
|
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
.
# # |
|
Alloy Web UI
Alloy has a self hosted user interface hosted on address http://localhost:12345
that can be used to view its status.
This UI can only be accessed from localhost. If you want to view it from an external connection, you can set the --server.http.listen-addr
property.
# |
|
Edit this line in the script.
1 2 3 4 5 6 7 8 9 10 11 |
|
Now start and check the service is running.
# # |
|
You should now be able to access it from the address http://your-ip-or-domain:12345
However, this will not be encrypted. If you have set up Alloy as a service as shown above, you have a domain name, SSL and an NGinx reverse proxy as described in this course, you can set the --server.http.ui-path-prefix
property and add an NGinx proxy pass.
Set the --server.http.ui-path-prefix
# |
|
Edit this line in the script.
1 2 3 4 5 6 7 8 9 10 11 |
|
Add the NGinx Proxy Pass
# |
|
Add this location directive.
location /alloy/ {
proxy_set_header Host $http_host;
proxy_pass http://localhost:12345/alloy/;
}