Getting Started with Grafana Alloy

Aamod Kadam
5 min readJul 13, 2024

--

Setting up Grafana Alloy on EC2 instance

What is Grafana Alloy ?

Grafana Alloy is a vendor agnostic OpenTelemetry Collector distribution with a programmable pipeline.

Vendor Agnostic : Though open source the brain behind is Grafana Labs , however it can be used with any platform whether it is on-prem or Cloud or even with any OS such as Linux , Windows , MaC OS etc. Grafana Alloy can be used with systems , applications developed in any programming platforms such as Java , .NET .

OpenTelemetry is an observability framework and toolkit to provide standard way to generate , collect and export telemetry data. Telemetry data including metrics, traces and logs. OpenTelemetery is a Cloud Native Computation Foundation (CNCF) project and the key goal of Open Telemetry is to easily instrument your applications (Systems) no matter their language, infrastructure and runtime.

Programmable Pipeline enables to receive the metrics and process it through a series of components which is configurable. For example you may want to only process error logs or drop the debug logs before forwarding it to log aggregator or you may want to relabel data before sending it to any log aggregator tool for better analysis.

Grafana Alloy in Observability Stack

Interestingly if I look up the name alloy the following definition comes up.

It looks like Grafana Alloy is also aimed to strengthen observability stack by enabling you to combine existing frameworks and tools including Prometheus , Jaeger, Grafana Loki so that collectively observability stack is strengthened !

This post focuses on setting up Grafana Alloy on Ubuntu VM running in AWS cloud.

I intend to discuss the use case in another post.

My Setup

EC2 instance type : t2.micro

OS : Ubuntu

AMI : ubuntu-noble-24.04-amd64-server-20240701.1

The instance is associated with a Public IP and the security group is configured to provide SSH access restricted to my Public IP.

Step — Setup Alloy

Step — Import the GPG key and add the Grafana package repository

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 — Update the repositories

sudo apt-get update

Step — Install Alloy

sudo apt-get install alloy

Installing Alloy

Step — Run Alloy

Start Alloy Service

sudo systemctl start alloy

Check Alloy Service Status

sudo systemctl status alloy

Configure Alloy to run at bootup

sudo systemctl enable alloy.service

Step — Configure Alloy

The default configuration is located at /etc/alloy/config.alloy

By default alloy runs on port 12345 and binds to local address i.e. 127.0.0.1

If you want to expose Alloy to the outside world you need to configure alloy to run it on all network interfaces .

To change the configuration edit /etc/default/alloy and make the following changes i.e. add

--server.http.listen-addr=0.0.0.0:12345" to CUSTOM_ARGS

Restart the alloy service

sudo systemctl restart alloy

To confirm that the changes are picked up by service use the following command.

sudo ss -lutp | grep alloy

ss — socket statistics — another utility to display socket information

-l : display only listening sockets

-t : display TCP sockets

-u : display UDP sockets

-p : show processes using socket

Step — Amend the security group to allow traffic on port 12345

Ensure to modify the security group associated with ec2 instace to allow inbound traffic on port 12345.

Now if you go to the public IP:12345 then one should see the Alloy UI.

Grafana Alloy consists of Components and the components can be chained together to create some kind of pipeline.

The pipeline is configured in the /etc/alloy/config.alloy

The ability to program this pipeline is one of the biggest advantages of Grafana Alloy.

The above configuration file is configured to

  1. Use prometheus exporter to scrape the metric data
  2. It can then forward it to another component for e.g. `prometheus.remote_write` or `prometheus.relabel`

It also provides visual representation of the pipeline which is quite handy when you are having a bigger pipeline.

For this post nothing is configured with Prometheus so just ignore this but that should give an idea of how you can visualize it using Grafana Alloy.

Grafana Alloy is something you should start evaluating if you are looking at setting up or even enhancing your observability stack !

References :

https://grafana.com/docs/alloy/latest/

https://github.com/grafana/alloy

--

--

Aamod Kadam

AWS Community Builder | upGrad Course Author | 7 x AWS | Terraform Associate | Cloud Consulting | AWS | Azure | Docker | Kubernetes | Software Architecture