Introduction
Grafana Alloy stands out as a versatile observability solution that is not tied to any vendor and is source, in nature. A collaborative effort between Grafana Labs and the OpenTelemetry project.The platform serves as a hub for gathering and analyzing observability insights such as metrics,data logs and traces from origins.It essentially brings together observability tools including Prometheus (for metrics),Loki (, for logs) and Tempo (for traces) to work seamlessly in unison.”Alloy enables effortless gathering and analysis of data, from services to provide understanding of the well being and efficiency of your systems.
Prerequisites
- Minium 2 core CPU and 4 GB of memory on the Ubuntu OS.
- High speed network speed.
- Basic knowledge of the Linux command line.
In this post, We will show you how to install Grafana Alloy on ubuntu 24.04 LTS linux machine.
Step 1: Update the System
We need to 1st update the current ubuntu reposiotry by using given command.
sudo apt-get update
Step 2: Upgrade the Packages
We need to also upgrade the default packages by executing and following the command.
sudo apt-get upgrade -y
Step 3: Install GPG
sudo apt-get install gpg -y
Step 4: Install Grafana Alloy
sudo mkdir -p /etc/apt/keyrings/
wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
Step 5: Updating Repository
sudo apt-get update
Step 6: Installing Alloy
sudo apt-get install alloy -y
Step 7: Start Grafana Alloy Service
By default Grafana Alloy service will be stop state to make sure, We need to execute the givne command.
sudo systemctl status alloy
To start the Alloy service and get status.
sudo systemctl start alloy && sudo systemctl status alloy
Step 8: To view the logs
sudo journalctl -u alloy
Step 9: Configure Local Logs
sudo vim /etc/alloy/config.alloy
Paste the following configure.
local.file_match "local_files" {
path_targets = [{"__path__" = "/var/log/*.log"}]
sync_period = "5s"
}
loki.source.file "local_files" {
targets = local.file_match.local_files.targets
forward_to = [loki.process.add_labels.receiver]
}
loki.process "add_labels" {
forward_to = [loki.write.local_loki.receiver]
stage.labels {
values = {
job = "my_job_name",
service_name = "my_service_name",
}
}
}
loki.write "local_loki" {
endpoint {
url = "http://localhost:3100/loki/api/v1/push"
// basic_auth {
// username = "admin"
// password = "admin"
// }
}
}
Step 10: Restart Grafana Alloy
We need to restart the Grafana Alloy to get an updated configuration that only sends the local machine logs to Loki; however, we can also add or update the configuration as per the project requirement.
sudo systemctl restart alloy