Path

Use the Add a database wizard in Database Observability to generate the Grafana Alloy configuration for MySQL, then deploy it to your Alloy host.

Estimated time: 3 min

Configure Grafana Alloy

In this milestone, you’ll use the Add a database wizard in Database Observability to generate the Grafana Alloy configuration for your MySQL database, then deploy it on the machine where Alloy runs. Alloy collects both metrics and structured logs from your database and forwards them to Grafana Cloud.

Before you begin, install Grafana Alloy 1.17.0 or later on a host that can reach both your MySQL server and Grafana Cloud. Refer to Install Grafana Alloy for your platform. Database Observability is generally available, so you don’t need a --stability.level flag.

The wizard offers two deployment methods. This path uses Manual configuration, which works with any Alloy you run yourself. If your collector is enrolled in Fleet Management, you can choose Fleet Management instead and Grafana Cloud pushes the configuration to it for you.

To start the wizard and choose how to deploy, complete the following steps:

  1. Open Observability > Database > Configuration.

  2. On the Setup tab, click Add a database.

  3. Select MySQL.

  4. Click Next.

  5. Select Manual configuration.

  6. Click Next.

You’ve chosen MySQL and manual deployment. The wizard now asks for the details it needs to generate your configuration.

To generate the configuration, complete the following steps:

  1. Enter a Database name. It becomes the Alloy component identifier, so use only letters, numbers, and underscores.

  2. Leave DSN storage method set to environment variable, then click Auto-fill from pipeline name to set the Environment variable name Alloy reads the connection string from. Note the name — you’ll set this variable on the Alloy host.

  3. Optionally set an Instance label to identify this database in Grafana Cloud. If you leave it empty, the instance is identified by the host:port from your connection string.

  4. Click Next.

  5. Review the generated configuration on Deploy configuration, then click Copy to clipboard (or Download as .alloy file).

You’ve generated a complete Alloy configuration: the MySQL exporter, the database_observability.mysql component, relabeling, and the Grafana Cloud metrics and logs writers, all wired together.

To deploy the configuration on the host where Alloy runs, complete the following steps:

  1. Paste the copied configuration into your Alloy configuration file, for example config.alloy. If the file already contains Database Observability blocks for this database, replace them so the database isn’t collected twice.

  2. In the database_observability.mysql block, add the settings that let Alloy maintain the Performance Schema consumers and actor tracking you granted privileges for in the previous milestone:

    Alloy
    database_observability.mysql "mysql_mysql_primary" {
      // ...generated attributes...
    
      allow_update_performance_schema_settings = true
    
      query_samples {
        auto_enable_setup_consumers = true
      }
    
      setup_actors {
        auto_update_setup_actors = true
      }
    }

    Skip this step if you chose to manage consumers and tracking manually.

  3. Set the environment variables the configuration reads. The DSN variable name is the one the wizard generated (DB_MYSQL_ + your database name in uppercase + _DSN):

    Bash
    export DB_MYSQL_MYSQL_PRIMARY_DSN='db-o11y:YOUR_DB_O11Y_PASSWORD@tcp(YOUR_DB_HOST:YOUR_DB_PORT)/'
    export GCLOUD_HOSTED_METRICS_URL='YOUR_PROMETHEUS_REMOTE_WRITE_URL'
    export GCLOUD_HOSTED_METRICS_ID='YOUR_PROMETHEUS_INSTANCE_ID'
    export GCLOUD_HOSTED_LOGS_URL='YOUR_LOKI_WRITE_URL'
    export GCLOUD_HOSTED_LOGS_ID='YOUR_LOKI_INSTANCE_ID'
    export GCLOUD_RW_API_KEY='YOUR_GRAFANA_CLOUD_TOKEN'

    Replace:

    • YOUR_DB_O11Y_PASSWORD, YOUR_DB_HOST, YOUR_DB_PORT — the db-o11y password and your MySQL host and port (default 3306)
    • YOUR_PROMETHEUS_REMOTE_WRITE_URL / YOUR_PROMETHEUS_INSTANCE_ID — from your stack’s Prometheus details in Grafana Cloud
    • YOUR_LOKI_WRITE_URL / YOUR_LOKI_INSTANCE_ID — from your stack’s Loki details in Grafana Cloud
    • YOUR_GRAFANA_CLOUD_TOKEN — a Grafana Cloud access policy token with write permissions

    How you set variables depends on how you run Alloy. For the Linux service, add them to its environment file (/etc/default/alloy on Debian-based systems, /etc/sysconfig/alloy on RedHat or SUSE-based systems); for containers, pass them in the container environment.

  4. Restart Alloy so it loads the new configuration. On Linux with systemd:

    Bash
    sudo systemctl restart alloy

    Check the Alloy logs for errors connecting to MySQL or to Grafana Cloud.

You’ve deployed the Database Observability configuration to Alloy. Alloy now connects to MySQL as db-o11y, scrapes Performance Schema metrics, and streams query telemetry to Grafana Cloud.

In the next milestone, you’ll verify that telemetry is flowing to Grafana Cloud.