Zum Inhalt springen

Show InfluxDB data in Grafana

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.

  • 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 logiccloudRole in GrafanaCan add data sources
SuperadminAdminYes
Manage users (manage-users)Admin of your own organization, if the installation has enabled thisYes
Manage projects (manage-projects)EditorNo, but can build dashboards
All othersViewerNo

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.

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 InfluxDBUser interfaceURL for the Grafana data source
The InfluxDB of a single-customer installationhttps://influxdb.<host of your installation>http://influxdb.control.svc.cluster.local:8086
Your own InfluxDBYour addressThe 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. Open the InfluxDB user interface.
  2. Open Load Data > API Tokens and select Generate API Token > Custom API Token.
  3. Select Read for the bucket that the runtime writes to, and for no other bucket. Do not select Write.
  4. Copy the token. InfluxDB shows it only once.
  1. Open Grafana at https://grafana.<host of your installation> and sign in with your logiccloud account.

  2. Open Connections > Data sources and select Add new data source.

  3. Select InfluxDB.

  4. Enter these values:

    FieldValue
    Query languageFlux
    URLThe URL from the table in Which InfluxDB do you use?
    OrganizationThe organization in InfluxDB
    TokenThe token from step 1
    Default BucketThe bucket that the runtime writes to
  5. Select Save & test. Grafana reports that the data source works and that it found 1 bucket.

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.

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.

  1. In Grafana, open the panel menu and select Share > Link. Copy the link.
  2. 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.

What you seeCauseWhat to do
Add new data source is disabledYour 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 defaultThe 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 unauthorizedThe token or the organization is wrong.Check both values in the InfluxDB user interface.
Save & test reports a timeout or connection refusedGrafana cannot reach the URL.Check the URL in Which InfluxDB do you use?.