Home › Guides › Grafana Alloy tutorial

Grafana Alloy Tutorial for Beginners

This guide takes one Linux server from nothing to a full Grafana Cloud dashboard: CPU, memory, disks, network and logs, on the free plan. Grafana Alloy does all the collecting. You install it with one command, then write the collecting part of its config yourself, block by block, so you know what every line does. It follows the video step by step.

Grafana Alloy tutorial for beginners: from a Linux server to Grafana Cloud

What is Grafana Alloy?

Grafana is the screen: dashboards, graphs and alerts. It doesn't collect anything by itself. Something has to run on your server, read the numbers and the logs, and ship them to a database. That something is called a collector.

Alloy is Grafana's own collector. It replaces the older Grafana Agent, Promtail and the node exporter, in one program.

Two kinds of data

In Grafana Cloud, both databases are already set up for you.

How an Alloy config works

An Alloy config is made of components. Each component is one block that does one job: collect data, process it, or send it somewhere. You connect them with forward_to, and the output of one flows into the next. That chain is your pipeline. This is the one you build here:

prometheus.exporter.unixreads CPU, memory, disk, network→ prometheus.scrapeevery 60 s→ prometheus.remote_writeGrafana Cloud Prometheus
loki.source.journalsystemd journal→ loki.writeGrafana Cloud Loki

What you need

Step 1: check your server's architecture

The install command depends on your processor type, so check it first:

uname -m
OutputWhat it isPick in Grafana Cloud
x86_64The usual Intel or AMD serverAmd64
aarch64An ARM processorArm64

Step 2: add the Linux Server connection in Grafana Cloud

  1. In the Grafana Cloud menu, open Connections → Add new connection.
  2. Search for Linux and open Linux Server. This page writes the install command for you.
  3. Select your platform. Ubuntu is based on Debian, so pick Debian for Ubuntu too.
  4. Select the architecture from step 1: Arm64 for ARM, Amd64 for Intel or AMD.

Step 3: create the API token

Click Run Grafana Alloy. Alloy needs a token to prove to Grafana Cloud that it's allowed to send data.

Click Create token. Under the token is Remote Configuration. It lets you manage all your collectors from Grafana Cloud later, in Fleet Management. Leave it on. It doesn't change anything in this guide.

The install command

Grafana Cloud now shows the install command. It's one line: the addresses of your metrics and logs databases, your account IDs, and the token. The last part downloads Grafana's install script and runs it. It looks like this:

GCLOUD_HOSTED_METRICS_ID="<metrics-id>" GCLOUD_HOSTED_METRICS_URL="<metrics-url>" GCLOUD_HOSTED_LOGS_ID="<logs-id>" GCLOUD_HOSTED_LOGS_URL="<logs-url>" GCLOUD_FM_URL="<fleet-management-url>" GCLOUD_FM_POLL_FREQUENCY="60s" GCLOUD_FM_HOSTED_ID="<stack-id>" GCLOUD_FM_LOCAL_ATTRIBUTES="{}" ARCH="arm64" GCLOUD_RW_API_KEY="<your-token>" /bin/sh -c "$(curl -fsSL https://storage.googleapis.com/cloud-onboarding/alloy/scripts/install-linux.sh)"

Copy yours from Grafana Cloud, not from here. The block above only shows the shape. The real command has your own IDs, URLs and token filled in, and the ARCH value you picked. Treat it like a password: anyone with the token can send data into your account.

Step 4: install Alloy and check the service

On the server, paste the command and press Enter. It asks for your sudo password, because it installs a system package. It downloads Alloy, writes a config file to /etc/alloy/config.alloy, and starts Alloy as a system service. Check it:

systemctl status alloy

You want to see this line. Press Q to get your prompt back.

Active: active (running)

Step 5: read the config file the installer wrote

sudo cat /etc/alloy/config.alloy

You'll see three blocks. Here they are with the IDs and URLs replaced by placeholders (the remotecfg block is shortened):

remotecfg {
	url            = "https://fleet-management-prod-<nnn>.grafana.net"
	id             = "web-01"
	poll_frequency = "60s"
	...
	basic_auth {
		username = "<stack-id>"
		password = sys.env("GCLOUD_RW_API_KEY")
	}
}

prometheus.remote_write "metrics_service" {
	endpoint {
		url = "https://prometheus-prod-<nn>-prod-<region>.grafana.net/api/prom/push"

		basic_auth {
			username = "<metrics-id>"
			password = sys.env("GCLOUD_RW_API_KEY")
		}
	}
}

loki.write "grafana_cloud_loki" {
	endpoint {
		url = "https://logs-prod-<nnn>.grafana.net/loki/api/v1/push"

		basic_auth {
			username = "<logs-id>"
			password = sys.env("GCLOUD_RW_API_KEY")
		}
	}
}

Every block is a component: its type first, then a label you choose, in quotes. So prometheus.remote_write "metrics_service" is a component of type prometheus.remote_write with the label metrics_service.

The token isn't written in this file. sys.env("GCLOUD_RW_API_KEY") reads it from an environment variable that the installer saved in a protected file.

These blocks only send. Nothing here collects anything yet, so Grafana would stay empty. The next step adds the collecting part.

Step 6: add the metrics and logs pipeline

Open the file in nano:

sudo nano /etc/alloy/config.alloy

Press Alt+/ to jump to the end of the file, and paste these lines after the blocks the installer wrote:

// METRICS: collect, scrape, send
prometheus.exporter.unix "linux" { }

prometheus.scrape "linux" {
  targets    = prometheus.exporter.unix.linux.targets
  forward_to = [prometheus.remote_write.metrics_service.receiver]
}

// LOGS: read the systemd journal, send
loki.source.journal "linux" {
  labels     = { job = "integrations/node_exporter", instance = constants.hostname }
  forward_to = [loki.write.grafana_cloud_loki.receiver]
}

Save with Ctrl+O and Enter, then exit with Ctrl+X. Here is what each block does.

prometheus.exporter.unix "linux"

A node exporter built into Alloy. It reads CPU, memory, disks and network straight from Linux. The label is linux. The empty { } means it runs with its defaults.

prometheus.scrape "linux"

It reads the exporter, by default every 60 seconds.

The exporter also puts two labels on every metric: instance, the server's name, and job. The ready-made Linux dashboards filter on exactly these labels. Exporter, scrape, remote write: that's the metrics pipeline.

loki.source.journal "linux"

It reads the systemd journal, where Linux keeps the logs of every service.

Check your labels. metrics_service and grafana_cloud_loki are the labels Grafana Cloud's installer gave the remote write and Loki write blocks. If yours are different, use your labels after forward_to.

Step 7: restart Alloy and check for errors

Restart Alloy so it loads the new config, then check the status again:

sudo systemctl restart alloy
systemctl status alloy

It should still say active (running). If you made a typo, it says failed. This shows you the error with the exact line:

journalctl -u alloy

Step 8: open the Alloy web UI

Alloy has its own web page on port 12345, but by default it only answers on the server itself. To open it from your computer, edit /etc/default/alloy:

sudo nano /etc/default/alloy

Find the CUSTOM_ARGS line (Ctrl+W searches in nano) and set the listen address to 0.0.0.0, port 12345:

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

Only on a trusted network. This page has no login. Anyone who can reach port 12345 can see your pipeline.

Save, exit, restart Alloy, and get the server's IP address. It's the first one listed:

sudo systemctl restart alloy
hostname -I

In your browser, open http://SERVER-IP:12345.

Tip (not in the video): right after a restart, the scrape target can show as not scraped yet. The first scrape happens within 60 seconds, so reload the page after a minute.

Step 9: test the connection and install the dashboards

  1. Back in Grafana Cloud, on the Linux Server page, scroll down and click Test connection. It confirms Alloy is sending data.
  2. Click Install. It adds the ready-made Linux dashboards and alert rules to your stack.
  3. Click View dashboards and open Linux node / overview. Pick your instance (web-01 in the video). Uptime, CPU, memory, disk and network, all from the three blocks you wrote.

Step 10: explore metrics and logs

One metric

Open Explore. Pick your Grafana Cloud Prometheus data source, switch the query editor to Code, type this and run the query:

node_load1

node_load1 is the server's load average over the last minute. The legend shows its labels: the instance (web-01) and the job the exporter added.

The logs

Switch to your Grafana Cloud Loki data source (its name ends in -logs), and query by the instance label. Replace web-01 with your server's hostname:

{instance="web-01"}

Every line from the server's journal, searchable.

If no data shows up

If your dashboards stay empty, start here:

journalctl -u alloy
What you seeWhy
systemctl status alloy says failed A typo in config.alloy. journalctl -u alloy shows the exact line.
Alloy runs, but Grafana Cloud stays empty Almost always the token, or a typo in a component name after targets or forward_to.
forward_to points at a component that doesn't exist Your installer used different labels than metrics_service or grafana_cloud_loki. Copy the labels from the top of your own file.
The dashboard has no data for your server Check the instance picker at the top. The dashboards filter on the instance and job labels.
You can't open port 12345 in the browser CUSTOM_ARGS isn't set, or Alloy wasn't restarted after the change.
Not sure where the data stops Open the Alloy web UI. A component that isn't healthy, or a scrape target that was never scraped, shows you which block to fix.

Watch the video

The whole setup on camera, from an empty Grafana Cloud account to the dashboard, including the Alloy web UI drawing the pipeline live:

Related

Rolling out Alloy across more than one server?

One server and one pipeline is a lab. A company means many collectors, Fleet Management, labels that stay consistent, and alerts that wake up the right person. I'm a Grafana Champion, and I help teams set up monitoring and observability, from Alloy pipelines to dashboards and alerting. See my services, or tell me what you run and I'll tell you how I'd set it up.