Help build the future of open source observability software Open positions

Check out the open source projects we support Downloads

Grot cannot remember your choice unless you click the consent notice at the bottom.

A guide to scaling Grafana Alloy deployments across multiple hosts

A guide to scaling Grafana Alloy deployments across multiple hosts

15 Apr, 2024 5 min

Last week we introduced Grafana Alloy, our distribution of the OpenTelemetry Collector with built-in Prometheus pipelines and support for metrics, logs, traces, and profiles. We’re excited to see the community embrace Alloy, and we want to help them use and scale it as easily as possible.

Many developers that need to deploy and manage software across several hosts turn to Ansible for its ease of use and versatility. That also makes Ansible an excellent choice for deploying Grafana Alloy, as it simplifies the automation of installation, setup, and management tasks related to Alloy.

In this guide we’ll walk you through how to use the alloy role with the Grafana Ansible collection to deploy and manage Alloy across multiple Linux hosts. We’ll then show you how to explore your data in Grafana.

Before you begin

To get started, you should have the following:

  • Linux hosts with SSH access and sufficient permissions
  • Ansible installed on your base system

Install the Grafana Ansible collection

The Alloy role is available in the Grafana Ansible collection as of the 4.0.0 release.

To install the Grafana Ansible collection, run this command:

ansible-galaxy collection install grafana.grafana:4.0.0

Create an Ansible inventory file

Next, you will set up your hosts and create an inventory file.

  1. Create an Ansible inventory file.

An Ansible inventory, which resides in a file named inventory, lists each host IP on a separate line, like this (8 hosts shown):    # hostname = ubuntu-01    # hostname = ubuntu-02    # hostname = centos-01    # hostname = centos-02      # hostname = debian-01        # hostname = debian-02    # hostname = fedora-01    # hostname = fedora-02

Note: If you are copying the above file, remove the comments (#).

  1. Create an ansible.cfg file within the same directory as inventory, with the following values:
inventory = inventory  # Path to the inventory file
private_key_file = ~/.ssh/id_rsa   # Path to my private SSH Key

Use the Alloy Ansible role

Next you will create an Ansible playbook that calls the alloy role from the grafana.grafana Ansible collection.

To use the Alloy Ansible role:

  1. Create a file named deploy-alloy.yml in the same directory as ansible.cfg and inventory and add the configuration below.
- name: Install Alloy
  hosts: all
  become: true

    - name: Install Alloy
        name: grafana.grafana.alloy
        config: |
          prometheus.scrape "default" {
            targets = [{"__address__" = "localhost:12345"}]
            forward_to = [prometheus.remote_write.prom.receiver]
          prometheus.remote_write "prom" {
            endpoint {
                url = "<YOUR_PROMETHEUS_PUSH_ENDPOINT>"

                basic_auth {
                username = "149xxx"
                password = "glc_xxx"

The playbook calls the alloy role from the grafana.grafana Ansible collection. The Alloy configuration in this playbook sends metrics from the Linux hosts to your Prometheus data sources.

Refer to the Grafana Ansible documentation to understand the other variables you can pass to the alloy role.

  1. To run the playbook, run this command:
ansible-playbook deploy-alloy.yml

Note: You can place the deploy-alloy.yml, ansible.cfg, and inventory files in different directories based on your needs.

Check that metrics are being ingested into Prometheus

Metrics will soon be available in Grafana if your Prometheus data sources are added.

To test this, use the Explore feature. Click the Explore icon (compass icon) in the vertical navigation bar.

To check metrics:

  1. Find the Explore section. Look for the Explore icon (it looks like a compass) on the left-side vertical navigation bar in Grafana and click it.
  2. Select Your Prometheus data source. At the top of the page, there’s a dropdown menu. Use it to pick the Prometheus data source you’ve added.
  3. Run a test query. Type in the query {instance="centos-01"}, where "centos-01" should be replaced with the hostname of one of your Linux hosts. This is just an example to get you started, so change it to match your actual hostname.
  4. Check metrics. After running the query, if you see a graph and a table with data (similar to the example shown in the image below), it means your metrics are correctly being fetched and displayed.
Metrics example
  1. Explore additional metrics. Explore other metrics—like CPU load, memory usage, disk IO, network bandwidth—and create dashboards to gain insights into your system’s performance.

If you don’t see any data, it could mean that metrics aren’t being collected as expected. To troubleshoot, check the status of your Alloy service by running this command:

sudo systemctl status alloy.service

If the Alloy service isn’t running, there might be an issue with the configuration syntax, or you might need to debug further. For help with this, take a look at the documentation available on configuring Alloy correctly and troubleshooting common issues.

Next steps: Set up clustering

Once you’ve got Grafana Alloy up and running across various Linux hosts, the next step to enhance its performance and reliability is to configure it for clustering. This setup lets individual Alloy instances collaborate, sharing workloads efficiently and ensuring your monitoring system remains available even under high demand.

For detailed guidance on how to configure Alloy for clustering, including step-by-step instructions and best practices, refer to our documentation.

Grafana Cloud is the easiest way to get started with metrics, logs, traces, dashboards, and more. We have a generous forever-free tier and plans for every use case. Sign up for free now!