NEW

Grafana Integration

Visualize your time series data with Grafana dashboards. MynaDB integrates seamlessly with Grafana through multiple datasource options, including InfluxDB-compatible endpoints, native SQL via the MySQL protocol, and a built-in monitoring dashboard for operational visibility.

Datasource Setup

Follow these steps to connect Grafana to MynaDB using the InfluxDB datasource plugin:

  1. Open Grafana and navigate to datasources
    Go to Configuration → Data Sources → Add data source in your Grafana instance.
  2. Select the InfluxDB datasource type
    Search for InfluxDB in the datasource list and select it. MynaDB exposes InfluxDB-compatible query endpoints.
  3. Configure the connection URL
    Set the URL to your MynaDB instance HTTP address:
    text
    http://your-mynadb-host:7000
  4. Set the database name
    Enter your database (catalog) name in the Database field. This corresponds to the :db parameter used in MynaDB write and query endpoints (e.g., mydb).
  5. Configure authentication (if enabled)
    If MynaDB authentication is enabled, toggle Basic Auth and provide the username and password configured in your config.toml under [auth].
  6. Save and test
    Click Save & Test. Grafana will verify the connection to MynaDB.

InfluxDB-Compatible Endpoints

MynaDB exposes several query endpoints that Grafana can use depending on your preferred query language:

Endpoint Protocol Description
/api/v2/query Flux InfluxDB v2-compatible Flux query endpoint. Use this when Grafana is configured with the InfluxDB datasource in Flux mode.
/api/v1/query InfluxQL InfluxDB v1-compatible InfluxQL query endpoint. Suitable for legacy dashboards or simpler query syntax.
/query/:db Native SQL MynaDB native SQL endpoint powered by Apache DataFusion. Provides the full power of SQL including JOINs, window functions, and CTEs.

Built-in Dashboard

MynaDB ships with a Grafana-style monitoring dashboard accessible from the Admin Console. This built-in dashboard provides real-time operational visibility without requiring a separate Grafana installation.

The dashboard includes the following panels:

Access the built-in dashboard at:

text
http://your-mynadb-host:7000/admin/dashboard

Example Queries in Grafana

When using Grafana with MynaDB's native SQL endpoint, you can use Grafana's built-in template variables to create dynamic, time-aware dashboards. Below are common query patterns.

Time-filtered aggregation

sql
SELECT
  time_bucket('$__interval', time) AS time,
  avg(cpu_usage) AS avg_cpu,
  max(cpu_usage) AS max_cpu
FROM mydb.default.system_metrics
WHERE $__timeFilter(time)
GROUP BY time_bucket('$__interval', time)
ORDER BY time

Multi-host comparison

sql
SELECT
  time_bucket('$__interval', time) AS time,
  host,
  avg(memory_used_percent) AS avg_memory
FROM mydb.default.system_metrics
WHERE $__timeFilter(time)
  AND host IN ($host)
GROUP BY time_bucket('$__interval', time), host
ORDER BY time

Ingestion rate monitoring

sql
SELECT
  time_bucket('$__interval', time) AS time,
  count(*) / EXTRACT(EPOCH FROM INTERVAL '$__interval') AS points_per_second
FROM mydb.default.measurements
WHERE $__timeFilter(time)
GROUP BY time_bucket('$__interval', time)
ORDER BY time

Top-N query with variable

sql
SELECT
  host,
  avg(cpu_usage) AS avg_cpu,
  max(cpu_usage) AS peak_cpu
FROM mydb.default.system_metrics
WHERE $__timeFilter(time)
GROUP BY host
ORDER BY avg_cpu DESC
LIMIT $topN

The following Grafana macros are supported:

Macro Description Example Expansion
$__timeFilter(time) Expands to a time range filter based on the dashboard's selected time range time >= 1704067200000000000 AND time <= 1704153600000000000
$__interval Auto-calculated aggregation interval based on the dashboard time range and panel width 1m, 5m, 1h
$__from / $__to Start and end timestamps of the selected dashboard time range 1704067200000

MySQL Datasource Alternative

As an alternative to the InfluxDB datasource, you can connect Grafana to MynaDB using the MySQL datasource. MynaDB implements the MySQL wire protocol on port 7002, allowing standard MySQL clients and tools (including Grafana) to execute SQL queries directly.

Setup steps

  1. Enable MySQL protocol in MynaDB
    Ensure the MySQL protocol is enabled in your config.toml:
    toml
    [server]
    mysql_enabled = true
    mysql_port = 7002
  2. Add a MySQL datasource in Grafana
    Go to Configuration → Data Sources → Add data source and select MySQL.
  3. Configure the connection
    text
    Host:     your-mynadb-host:7002
    Database: mydb
    User:     admin      (if auth is enabled)
    Password: secret     (if auth is enabled)
  4. Save and test the connection
    Click Save & Test to verify connectivity.

Advantages of the MySQL datasource

Example MySQL datasource query

sql
SELECT
  UNIX_TIMESTAMP(time) AS time_sec,
  avg(value) AS avg_value,
  measurement
FROM cpu
WHERE time BETWEEN FROM_UNIXTIME($__from / 1000) AND FROM_UNIXTIME($__to / 1000)
GROUP BY time_bucket('$__interval', time), measurement
ORDER BY time_sec