Grafana is an open-source platform for dashboards, visualizations, and alerts. It queries your data in place through data sources, including built-in PostgreSQL and MySQL data sources, and is available self-managed or as Grafana Cloud.
How does the integration work?
Appwrite native PostgreSQL and MySQL databases are standard managed engines that Appwrite provisions in your project's region, each with its own hostname, credentials, and TLS. Grafana connects to them through its built-in PostgreSQL or MySQL data source with no Appwrite-specific configuration, so you can chart application data and alert on it next to your other metrics.
Grafana holds its data source connections open for the life of the process, so it connects to the direct engine port or a session-mode pooler, never the default transaction-mode pooler.
Native PostgreSQL and MySQL databases run in every Appwrite Cloud region and are available on paid plans.
How to implement
To connect Grafana to an Appwrite native database, there are several steps you must complete:
Step 1: Create a native database
Create an account on Appwrite Cloud if you haven't already. In your project, go to Databases, click Create database, and select PostgreSQL or MySQL from the Native databases group. Pick a specification and click Create database. The database becomes ready within a few minutes.
For PostgreSQL, open the database and click Credentials to copy the host and database name from the Details tab. For MySQL, read them from the database object with mysql.get() and an API key that has the databases.read scope.
Step 2: Limit what dashboards can do
Grafana can run any SQL its data source user is allowed to run. On PostgreSQL, don't connect as admin, which owns the database. Create a role for Grafana, such as grafana_ro, from the database's Roles tab in the Console, then grant it only the SELECT privileges your dashboards need from the SQL editor or psql.
On MySQL, keep panel queries read-only and don't save write statements in dashboards. On either engine, restrict network access to your Grafana hosts with an IP allowlist. For Grafana Cloud, add your stack's outbound IP ranges to the allowlist.
Step 3: Add the data source
In Grafana, open Connections > Data sources > Add data source and select PostgreSQL or MySQL:
| Field | Value |
|---|---|
| Host URL | db-<hash>.<region>.appwrite.center:5432 |
| Database name | <database> |
| Username | grafana_ro |
| Password | The reporting role's password |
| TLS/SSL Mode | require |
Appwrite terminates TLS at the edge, so require works without uploading a certificate.
| Field | Value |
|---|---|
| Host URL | db-<hash>.<region>.appwrite.center:3306 |
| Database | default |
| Username | admin.<hash> |
| Password | <password> |
Under Connection limits, keep Max open and Max idle modest so Grafana doesn't exhaust the database's connection budget, then select Save & test. To manage the data source as code, provision it from YAML with type: postgres or type: mysql and read the password from an environment variable through secureJsonData.
Step 4: Build a panel
Create a dashboard, add a panel backed by the new data source, and switch the query editor to code mode. For example, plot daily sign-ups from a users table:
SELECT date_trunc('day', created_at) AS time, count(*) AS signupsFROM usersGROUP BY 1ORDER BY 1SELECT CAST(DATE(created_at) AS DATETIME) AS time, COUNT(*) AS signupsFROM usersGROUP BY CAST(DATE(created_at) AS DATETIME)ORDER BY time;MySQL 8.4 enables ONLY_FULL_GROUP_BY, so the selected time expression must match the grouped one.
Grafana maps the time column to the panel's time axis and signups to the value.
Read more about Grafana and Appwrite Databases
If you would like to learn more about Grafana and Appwrite Databases, we have some resources that you should visit:
