LocalHake

Tutorial

Grafana pdc-agent as a Service

Set up a pdc-agent as a service to connect Prometheus to Grafana on Ubuntu 24.04

Hake HardwarePublished Updated ~7 minintermediate

This post contains paid links (affiliate) — how that works.


▶ Watch this build on YouTube
Contents

Introduction

This guide will provide instructions on how to set up a Grafana pdc-agent as a service in Ubuntu 24.04

Get pdc-agent Credentials

In Grafana, open up the side menu and select "Private data source connect"

Grafana sidebar menu showing Private data source connect option

If the network does not already exist, select "Add new network". Then provide a name

Grafana dialog to connect to a new network

Select the "Binary" option

Grafana PDC installation method selection with Binary selected

Click the button to create a token. A token will be generated, scroll down to step 3 and find the section that states "Run the binary". Copy the command into a notepad, this will be needed for later.

Download the pdc-agent

Navigate to the pdc-agent Download Page and locate the release with the "Latest" tag. At the time of this wiki the latest version is pdc-agent_Linux_x86_64.tar.gz and it will be used as an example in future commands within this wiki.

Download

Download the latest version to the home directory

bash
wget -P ~/ https://github.com/grafana/pdc-agent/releases/download/v0.0.36/pdc-agent_Linux_x86_64.tar.gz

Extract

Extract the downloaded file

bash
tar -xvf ~/pdc-agent_Linux_x86_64.tar.gz

Move the extracted files

bash
sudo mv ~/pdc-agent_Linux_x86_64/pdc /usr/local/bin/pdc

Prepare Executable

Make executable

Make the pdc binary executable

bash
sudo chmod +x /usr/local/bin/pdc

Clean Up

Delete the tar.gz file

bash
rm -rf ~/pdc-agent_Linux_x86_64*

Set Permissions

Set permissions

bash
sudo chown -R $USER:$USER /usr/local/bin/pdc

Credentials

Create Environmental Variables

Create a file to store sensitive values as environmental variables

bash
sudo nano /etc/default/pdc-agent

Add Credentials

Open the notepad that you saved the command from earlier. Paste in the values provided by Grafana for your pdc-agent. Then press ctrl + x, then y, then enter to save.

text
GCLOUD_PDC_SIGNING_TOKEN="your_signing_token_here"
CLUSTER="your_cluster"
GCLOUD_HOSTED_GRAFANA_ID="your_grafana_id"
  • -token is the GCLOUD_PDC_SIGNING_TOKEN
  • -cluster is the CLUSTER
  • -gcloud-hosted-grafana-id is the GCLOUD_HOSTED_GRAFANA_ID

Create the Service

Open with Nano

Use nano to create a pdc-agent.service file

bash
sudo nano /etc/systemd/system/pdc-agent.service

Add the Configuration

Add the following configuration, then press ctrl + x, then y, then enter to save.

text
[Unit]
Description=PDC Agent
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/pdc-agent
ExecStart=/usr/local/bin/pdc -token $GCLOUD_PDC_SIGNING_TOKEN -cluster $CLUSTER -gcloud-hosted-grafana-id $GCLOUD_HOSTED_GRAFANA_ID
Restart=always

[Install]
WantedBy=multi-user.target

Start the Service

Reload

Reload the daemon

bash
sudo systemctl daemon-reload

Start

Start the service

bash
sudo systemctl start pdc-agent

Enable

Enable the service

bash
sudo systemctl enable pdc-agent

Verify

Verify the service is running

bash
sudo systemctl status pdc-agent

Connect to Grafana

Now go back to the "Private data source connect" page in Grafana. Click "Test agent connection". The "agents connected" should now state "1".

Add Prometheus Data Source

Now that Grafana is connected to the local pdc-agent, Prometheus can be added as a data source if it is already configured. If it has not been configured yet, it can be installed as a service.

In the menu select "Data Sources".

Grafana sidebar menu showing Data sources option

Select "Add new data source". Then select "Prometheus". Set the "Name" for the data source.

Grafana data source name field showing milton-prometheus

Enter in http://<YOUR IP>:9090 as the Prometheus server URL. Where it says <YOUR IP> use the internal IP for the PC running the pdc-agent. This can be found with ip a.

Grafana Connection section showing Prometheus server URL

Scroll all the way to the bottom and click the dropdown for "Private data source connect" and choose the data source you just set up.

Grafana Private data source connect with Save and test button

Then click "Save & Test". You should receive a success message

Grafana success message showing Successfully queried the Prometheus API

Gear used