Skip to content
Visualize a Service in Managed Grafana

Visualize a Service in Managed Grafana

Connect an Exoscale Managed Grafana service to a Managed PostgreSQL service and to the services that hold its telemetry, then build dashboards on them. Grafana reads three kinds of sources here: the PostgreSQL service itself for SQL queries, a Managed OpenSearch service for its logs, and a Managed Thanos service for its metrics.

Add the data sources by hand, as shown below, rather than through the datasource integration. The integration connects to PostgreSQL as avnadmin, so Grafana users can modify the database. The reasons are in The datasource integration.

Prerequisites

  • A running Managed Grafana service. Sign in as avnadmin, the user that can add data sources. Read the address and the password with:

    exo dbaas show GRAFANA_SERVICE -z ZONE --uri
    exo dbaas user reveal-secrets GRAFANA_SERVICE avnadmin -z ZONE
  • For logs, a logs integration to Managed OpenSearch. See Send logs to Managed OpenSearch.

  • For metrics, a metrics integration to Managed Thanos. See Send metrics to Managed Thanos.

The IP filters of the PostgreSQL, OpenSearch and Thanos services do not need to list the Grafana service: Grafana reaches them while their filters allow only your own address.

To add a data source in Grafana, click Connections in the left-side menu, then Add new connection, search for the data source type, select it and click Add new data source. Fill in the fields listed below, then click Save & test.

Add PostgreSQL with a Read-Only User

Grafana sends whatever SQL a panel or an Explore query contains. Give it a user that can only read.

  1. Create the user:

    exo dbaas user create SERVICE_NAME grafana_reader -z ZONE
  2. Connected as avnadmin with psql, grant it read access to the public schema, including the tables created later:

    CREATE ROLE readonly NOLOGIN;
    GRANT CONNECT ON DATABASE defaultdb TO readonly;
    GRANT USAGE ON SCHEMA public TO readonly;
    GRANT SELECT ON ALL TABLES IN SCHEMA public TO readonly;
    ALTER DEFAULT PRIVILEGES FOR ROLE avnadmin IN SCHEMA public GRANT SELECT ON TABLES TO readonly;
    GRANT readonly TO grafana_reader;

    For other schemas and databases, see Create read-only users.

  3. Read the host, the port and the password:

    exo api get-dbaas-service-pg SERVICE_NAME -z ZONE -q '"uri-params".[host, port]'
    exo dbaas user reveal-secrets SERVICE_NAME grafana_reader -z ZONE
  4. Add a PostgreSQL data source:

    FieldValue
    Host URLHOST:PORT
    Database namedefaultdb
    Usernamegrafana_reader
    PasswordThe password of grafana_reader
    TLS/SSL Moderequire

Parameters:

  • SERVICE_NAME: name of the Managed PostgreSQL service.
  • ZONE: zone the service runs in, for example ch-gva-2.
  • HOST, PORT: the two values returned by the get-dbaas-service-pg command.

Save & test answers Database Connection OK. Through this data source SELECT queries return data, an INSERT fails with permission denied for table and a DROP TABLE fails with must be owner of table.

If you created extensions such as pg_stat_statements in the public schema, the GRANT SELECT ON ALL TABLES statement prints a no privileges were granted warning for their views. The warning is harmless.

Note

After a change to the Grafana service settings, each connection that Grafana had open left a LOG: SSL error: unexpected eof while reading line in the PostgreSQL log. It does not mean that a query failed.

Add the Logs from OpenSearch

  1. Read the host, the port and the password of the OpenSearch service:

    exo api get-dbaas-service-opensearch OPENSEARCH_SERVICE -z ZONE -q '"uri-params".[host, port]'
    exo dbaas user reveal-secrets OPENSEARCH_SERVICE avnadmin -z ZONE
  2. Add an OpenSearch data source:

    FieldValue
    URLhttps://HOST:PORT
    Basic authOn, with User avnadmin and its password
    Index name[INDEX_PREFIX-]YYYY-MM-DD
    PatternDaily
    Time field nametimestamp
    VersionClick Get Version and Save
    Message field nameMESSAGE

Parameters:

  • OPENSEARCH_SERVICE: name of the Managed OpenSearch service.
  • INDEX_PREFIX: the index prefix set on the logs integration, for example my-postgresql.

Important

Change Time field name. Its default, @timestamp, does not exist in the indices that the logs integration writes; the time field there is timestamp. With @timestamp, Save & test warns No field named @timestamp found.

With Index name set to INDEX_PREFIX-* and no pattern, queries work but Save & test reports Index not found. The daily pattern above passes the test with Index OK. Time field name OK.

avnadmin can read and write every index of the OpenSearch service. For a narrower account, see OpenSearch access control.

Add the Metrics from Thanos

Add a Prometheus data source with the query endpoint of the Thanos service:

FieldValue
Prometheus server URLhttps://THANOS_HOST:THANOS_PORT, from the query-frontend-uri of the Thanos service
Basic authenticationUser avnadmin and its password

Send metrics to Managed Thanos shows how to read the address and the password, and lists the metrics and their labels. Integrate Grafana shows the same form with screenshots. Save & test answers Successfully queried the Prometheus API.

The Datasource Integration

A datasource integration from Grafana to a PostgreSQL or OpenSearch service creates the data source for you:

echo '{"integration-type":"datasource","source-service":"GRAFANA_SERVICE","dest-service":"SERVICE_NAME"}' | \
  exo api create-dbaas-integration -z ZONE

It adds a data source named aiven-pg-SERVICE_NAME or aiven-opensearch-SERVICE_NAME. Those data sources have three problems:

Warning

The PostgreSQL data source connects as avnadmin. Any Grafana user who can edit a panel or use Explore can change the database through it: CREATE TABLE, INSERT and DROP TABLE sent through Grafana all succeed.

  • Your changes do not last. Pointing the data source at a read-only user works until the next change to the Grafana service settings: within seconds of such a change, the data source is back to avnadmin. Data sources added by hand are left untouched.
  • The OpenSearch data source does not work as created. Save & test reports No version set, queries fail with An error occurred within the plugin, and its time field is @timestamp.

Thanos cannot be a target: the API refuses the integration with Service integration datasource is not available for this service (HTTP 403).

To remove a datasource integration, delete it with exo api delete-dbaas-integration INTEGRATION_ID -z ZONE. Grafana drops its data source at the same time.

Related Pages

Last updated on