Installing Grafana Alloy on Ubuntu 24.04 LTS

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 "log_scrape" {
  targets    = local.file_match.local_files.targets
  forward_to = [loki.process.filter_logs.receiver]
  tail_from_end = true
}


loki.process "filter_logs" {
  stage.drop {
      source = ""
      expression  = ".*Connection closed by authenticating user root"
      drop_counter_reason = "noisy"
    }
  forward_to = [loki.write.grafana_loki.receiver]
}

loki.write "grafana_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

Author

Installing Grafana Alloy on Ubuntu 24.04 LTS

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top