1. TOP
  2. Raspberry Pi
  3. Setup
  4. Grafana Cloud (free tier)
2026/10/12

日本語 English

Visualizing Raspberry Pi Data with Grafana Cloud (Free Tier)

Grafana is a visualization tool that excels at graphing time-series data, creating dashboards and sending alerts when thresholds are exceeded.
This page describes how to use the free tier (Free) of "Grafana Cloud", the cloud version provided by Grafana Labs, so that PLC data recorded in MariaDB on a Raspberry Pi can be viewed from PCs and smartphones in the office or on the go.

Prerequisite: this assumes MariaDB setup (creating testDB) has been completed following "Initial Setup and Server Construction". The Raspberry Pi must be able to reach the internet (outbound communication).
If you want to keep everything within the company LAN, use "Metabase".

Configuration

Factory/company LAN (no inbound ports opened) PLCFINS / MC, etc. Raspberry Pi Collection programPython MariaDB:3306 PDC agentSSH tunnel Outbound connection only Grafana CloudFree tier PC/smartphone browser
Grafana Cloud queries MariaDB through a tunnel opened outbound from the Raspberry Pi

The key is the PDC agent (Private Data Source Connect) running on the Raspberry Pi. The agent opens an encrypted tunnel (SSH) from the Raspberry Pi to Grafana Cloud, and Grafana Cloud queries MariaDB through that tunnel.

  • No inbound ports need to be opened on routers or firewalls (it works with outbound connections only)
  • Data stays in MariaDB on the Raspberry Pi, so it is not subject to the cloud retention limit (14 days)
  • MariaDB is not exposed to the internet, which is safer than putting the DB directly online

What the free tier includes

The main contents of the free tier (Free) as of October 2026. You can start without registering a credit card.

ItemFree tierEffect in this configuration
Grafana (dashboards)Up to 3 active users per monthFree if up to 3 people view and edit
Private Data Source ConnectAvailableUsed to connect to MariaDB
Metrics10k active series/month, 14-day retentionNot used, because MariaDB is queried directly
Logs and traces50 GB/month each, 14-day retentionNot used
AlertsAvailableThreshold breaches can be notified by email etc.
SupportCommunity support only 

* The free tier contents may change. Check the latest information on the Grafana Cloud pricing page.

Comparison of Metabase and Grafana

 Metabase (on the Raspberry Pi)Grafana Cloud (free tier)
Where it runsRaspberry PiCloud (only the agent on the Raspberry Pi)
Load on the Raspberry PiHigh (Java, about 1 GB of memory)Low (the agent is a few tens of MB)
InternetNot neededRequired (outbound only)
From outside / smartphonesVPN etc. requiredViewable as is
StrengthsSummary tables, analysis without SQLTime-series trends, real-time monitoring, alerts
Number of usersUnlimitedUp to 3 per month (free tier)

Preparing sample data

Create a table to display in Grafana. If you already have a table recording PLC data, use that table.

$ sudo mariadb
MariaDB
USE testDB;

-- Table recording values read from the PLC (example)
CREATE TABLE plc_log (
    id     INT AUTO_INCREMENT PRIMARY KEY,
    ts     TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    device VARCHAR(32) NOT NULL,
    value  DOUBLE
);
CREATE INDEX idx_plc_log_ts ON plc_log (ts);

-- Test data (60 rows, one per minute for the last hour)
INSERT INTO plc_log (ts, device, value)
SELECT NOW() - INTERVAL seq MINUTE, 'PLC1', 20 + RAND() * 10
FROM seq_0_to_59;

SELECT COUNT(*) FROM plc_log;
TIMESTAMP is recommended for the time type: Grafana treats DB times as UTC. With TIMESTAMP, MariaDB automatically converts to UTC when passing values, so they are displayed correctly in local time. If you record local Japan time in a DATETIME column, the graph will be off by 9 hours (in that case convert in the query, e.g. CONVERT_TZ(ts,'+09:00','+00:00')).

Read-only user for Grafana

Grafana only reads data, so create a user with only SELECT privileges. The PDC agent connects to MariaDB from the Raspberry Pi itself, so the source is limited to 127.0.0.1.

MariaDB
CREATE USER 'grafana'@'127.0.0.1' IDENTIFIED BY 'grafana_pass';
GRANT SELECT ON testDB.* TO 'grafana'@'127.0.0.1';
EXIT;

Change the password to something hard to guess.

Creating a Grafana Cloud account

  1. Sign up on the Grafana Cloud sign-up page with an email address or a Google/GitHub account.
  2. Decide the name and region of your stack (your own Grafana environment). The stack name becomes the URL (https://your-stack-name.grafana.net). Choosing a region close to you makes the display faster.
  3. When creation finishes, you can log in to your stack's Grafana. The following operations are done on this Grafana screen.

Setting up the PDC agent

1. Create a PDC network and token (Grafana Cloud side)

  1. Open Connections > Private data source connections from the Grafana left menu.
  2. Create a network with Add new network (for example, name it raspi-factory).
  3. On the Configuration Details tab of the created network, press Create a new token to issue a token.
  4. Note down the following three values shown on screen.
Item on screenVariable name on this pageExample
tokenGCLOUD_PDC_SIGNING_TOKENglc_eyJvIjoi… (long string)
clusterGCLOUD_PDC_CLUSTERprod-ap-northeast-0, etc.
gcloud-hosted-grafana-idGCLOUD_HOSTED_GRAFANA_ID123456, etc.
The token is shown only once when created. Also, anyone with this token can connect an agent to your network, so do not publish it on pages, GitHub or elsewhere.

2. Install the agent (Raspberry Pi side)

The PDC agent requires OpenSSH 9.2 or later. Raspberry Pi OS Bookworm or later meets this requirement.

$ ssh -V
OpenSSH_9.2p1 Debian-2+deb12u3, OpenSSL 3.0.15 3 Sep 2024

Download the agent for ARM64 (64-bit OS) and place it in /usr/local/bin.

$ cd ~
$ wget https://github.com/grafana/pdc-agent/releases/latest/download/pdc-agent_Linux_arm64.tar.gz
$ tar xzf pdc-agent_Linux_arm64.tar.gz
$ sudo install -m 755 pdc-agent_Linux_arm64/pdc /usr/local/bin/pdc
$ pdc -version
If you are using a 32-bit OS, the ARM64 version will not run. Confirm that uname -m returns aarch64.

3. Start manually and check the connection

Start it with the three values you noted (a single-line command).

$ pdc -token <GCLOUD_PDC_SIGNING_TOKEN> -cluster <GCLOUD_PDC_CLUSTER> -gcloud-hosted-grafana-id <GCLOUD_HOSTED_GRAFANA_ID>

If the log shows This is Grafana Private Data Source Connect!, the connection succeeded. You can also confirm on the Private data source connections screen in Grafana Cloud that the agent is connected (Connected). Once confirmed, stop it with Ctrl+C.

If it cannot connect: the PDC agent connects outbound via SSH (port 22) and HTTPS (port 443). If outbound port 22 is blocked by your company firewall or proxy, it cannot connect, so check with your network administrator.

4. Start automatically as a service

Write values such as the token in a separate configuration file and make it unreadable by other users.

$ sudo nano /etc/default/pdc-agent
/etc/default/pdc-agent
GCLOUD_PDC_SIGNING_TOKEN=glc_YOUR_TOKEN_HERE
GCLOUD_PDC_CLUSTER=YOUR_CLUSTER_HERE
GCLOUD_HOSTED_GRAFANA_ID=YOUR_ID_HERE
$ sudo chmod 600 /etc/default/pdc-agent
$ sudo nano /etc/systemd/system/pdc-agent.service
/etc/systemd/system/pdc-agent.service
[Unit]
Description=Grafana Private Data Source Connect agent
After=network-online.target mariadb.service
Wants=network-online.target

[Service]
EnvironmentFile=/etc/default/pdc-agent
ExecStart=/usr/local/bin/pdc -token ${GCLOUD_PDC_SIGNING_TOKEN} -cluster ${GCLOUD_PDC_CLUSTER} -gcloud-hosted-grafana-id ${GCLOUD_HOSTED_GRAFANA_ID}
User=pi
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now pdc-agent.service
$ journalctl -u pdc-agent -f

It will now connect to Grafana Cloud automatically even after the Raspberry Pi restarts.

Adding the data source (MariaDB)

  1. Open Connections > Data sources > Add new data source from the Grafana left menu and select MySQL (MariaDB is also connected as MySQL).
  2. Enter the following.
ItemSettingDescription
Host URL127.0.0.1:3306MariaDB address as seen from the Raspberry Pi
Database nametestDB 
Username/Passwordgrafana/grafana_passRead-only user
Private data source connectraspi-factorySelect the PDC network you created (this is important)
  1. Press Save & test at the bottom; if Database Connection OK appears, the connection succeeded.
If you do not select "Private data source connect", Grafana Cloud tries to connect to its own 127.0.0.1 and fails.

Creating the dashboard

  1. Select Dashboards > New > New dashboard > Add visualization from the left menu and choose the MySQL data source you created.
  2. Switch the query editor to Code and enter the following SQL.
Grafana query (Format: Time series)
SELECT
  ts     AS time,
  value  AS "PLC1"
FROM plc_log
WHERE device = 'PLC1'
  AND $__timeFilter(ts)
ORDER BY ts
  • $__timeFilter(ts) is a Grafana macro that is automatically replaced with the condition for the period selected at the top right (such as the last hour).
  • If the time column is named time, Grafana treats it as the horizontal axis.
  • Setting the refresh interval at the top right (e.g. 10s) updates the graph automatically.

Save the panel and the dashboard, and you are done. From a smartphone too, you can see the same dashboard by logging in to https://your-stack-name.grafana.net.

Setting up alerts (optional)

From the Alert tab in the panel edit screen, you can create alert rules such as "notify by email when the value exceeds 30". Besides email, notification destinations (Contact points) include Slack, Microsoft Teams and more.

Operational notes

  • Number of users: the free tier allows up to 3 active users per month. If more people need to view it, consider dashboard sharing (snapshots) or a paid plan.
  • Query load: each time the dashboard is opened, SQL is sent through the tunnel to MariaDB on the Raspberry Pi. As data grows, always add an index on the ts column and do not make the refresh interval too short.
  • Check company rules: factory data will be displayed in a cloud outside the company. Check your company's information security rules before introducing it.
  • Updating the agent: the PDC agent is updated irregularly. To update, replace pdc with the new one using the same steps and run sudo systemctl restart pdc-agent.

Summary

Just by installing the PDC agent on the Raspberry Pi, MariaDB data could be visualized from the Grafana Cloud free tier without opening ports.
If you keep recording PLC data in MariaDB, you can check equipment operating status in real time from the office or on the go.

Related pages

Initial Setup and Server Construction

Initial setup and server construction

Setup steps for static IP, Apache, PHP and MariaDB

Metabase Setup

Metabase setup

Runs the BI tool Metabase on the Raspberry Pi and graphs MariaDB data

KEYENCE Host Link communication

KEYENCE Host Link communication

Host Link communication with KEYENCE PLCs from Python

What Is a Raspberry Pi?

What is a Raspberry Pi

Introduces the history, specs of current models and PLC integration configurations

Reference

Raspberry Pi is a trademark of Raspberry Pi Ltd. Grafana is a trademark of Grafana Labs.

Comments