Show InfluxDB data in Grafana
The InfluxDB connection writes process variables to an InfluxDB bucket. This page shows how to read that bucket in the Grafana of your logiccloud installation and how to show the result in an HMI page.
Before you start
Section titled “Before you start”- Your runtime writes data to an InfluxDB bucket. You know the bucket from the InfluxDB connection.
- You need the right to add a data source in Grafana:
| Your role in logiccloud | Role in Grafana | Can add data sources |
|---|---|---|
| Superadmin | Admin | Yes |
Manage users (manage-users) | Admin of your own organization, if the installation has enabled this | Yes |
Manage projects (manage-projects) | Editor | No, but can build dashboards |
| All others | Viewer | No |
logiccloud sets the Grafana role again every 5 minutes. A role that you change in Grafana itself does not stay. After your role in logiccloud changes, wait 5 minutes and reload Grafana.
Which InfluxDB do you use?
Section titled “Which InfluxDB do you use?”Grafana runs in the logiccloud installation, not in your browser. The URL that you enter in the data source must be reachable from there.
| Your InfluxDB | User interface | URL for the Grafana data source |
|---|---|---|
| The InfluxDB of a single-customer installation | https://influxdb.<host of your installation> | http://influxdb.control.svc.cluster.local:8086 |
| Your own InfluxDB | Your address | The public address of your InfluxDB |
An InfluxDB in a local network without a public address cannot be used.
The organization is the same value as in your InfluxDB connection. In the InfluxDB of a single-customer installation it is primary, unless your administrator created another one.
1. Create a read token in InfluxDB
Section titled “1. Create a read token in InfluxDB”- Open the InfluxDB user interface.
- Open Load Data > API Tokens and select Generate API Token > Custom API Token.
- Select Read for the bucket that the runtime writes to, and for no other bucket. Do not select Write.
- Copy the token. InfluxDB shows it only once.
2. Add the data source in Grafana
Section titled “2. Add the data source in Grafana”-
Open Grafana at
https://grafana.<host of your installation>and sign in with your logiccloud account. -
Open Connections > Data sources and select Add new data source.
-
Select InfluxDB.
-
Enter these values:
Field Value Query language Flux URL The URL from the table in Which InfluxDB do you use? Organization The organization in InfluxDB Token The token from step 1 Default Bucket The bucket that the runtime writes to -
Select Save & test. Grafana reports that the data source works and that it found 1 bucket.
3. Check the buckets
Section titled “3. Check the buckets”Open Explore, select your data source and run this query:
buckets()The result lists the buckets that the token can read. Your bucket must be in the list.
4. Build a panel
Section titled “4. Build a panel”Create a dashboard and add a panel. This query reads one logged variable. Replace the bucket and the tag name:
from(bucket: "my-bucket") |> range(start: v.timeRangeStart, stop: v.timeRangeStop) |> filter(fn: (r) => r._field == "MyTagName") |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)Save the dashboard.
5. Show the panel in an HMI page
Section titled “5. Show the panel in an HMI page”- In Grafana, open the panel menu and select Share > Link. Copy the link.
- In the HMI editor, add a Grafana chart and paste the link as
Url.
Users who open the HMI page see the panel with their own Grafana role. A Viewer can see it.
Troubleshooting
Section titled “Troubleshooting”| What you see | Cause | What to do |
|---|---|---|
| Add new data source is disabled | Your Grafana role is Editor or Viewer. | Ask an administrator for the role Manage users, wait 5 minutes and reload Grafana. If the installation has not enabled the setting, ask a superadmin to add the data source for you. |
An existing data source lists only buckets that you do not know, for example default | The token of that data source cannot read your bucket. A token reads only the buckets that it was created for. | Add a new data source with your own read token (steps 1 and 2). |
could not find bucket "<name>" | The bucket name is wrong, or the token cannot read this bucket. | Run buckets() (step 3). If your bucket is not in the list, create a new token. |
Save & test reports unauthorized | The token or the organization is wrong. | Check both values in the InfluxDB user interface. |
Save & test reports a timeout or connection refused | Grafana cannot reach the URL. | Check the URL in Which InfluxDB do you use?. |