Grafana Cloud

Labels reference

Labels identify and organize your database telemetry data. This reference documents all labels used by Database Observability, their requirements, and best practices.

Required labels

These labels must be configured correctly for Database Observability to function.

job

The job label identifies Database Observability telemetry.

RequirementValue
RequiredYes
Must beintegrations/db-o11y
WhereBoth metrics and logs

Configuration:

Alloy
loki.relabel "mydb" {
  forward_to = [loki.write.default.receiver]

  rule {
    target_label = "job"
    replacement  = "integrations/db-o11y"
  }
}

discovery.relabel "mydb" {
  targets = database_observability.postgres.mydb.targets

  rule {
    target_label = "job"
    replacement  = "integrations/db-o11y"
  }
}

Warning

If job is not exactly integrations/db-o11y, the Database Observability dashboards cannot find your data.

instance

The instance label uniquely identifies each database server.

RequirementValue
RequiredYes
Formathostname:port
Must matchSame value in both metrics and logs

Configuration:

Alloy
loki.relabel "mydb" {
  forward_to = [loki.write.default.receiver]

  rule {
    target_label = "instance"
    replacement  = "db.example.com:5432"
  }
}

discovery.relabel "mydb" {
  targets = database_observability.postgres.mydb.targets

  rule {
    target_label = "instance"
    replacement  = "db.example.com:5432"
  }
}

Best practices:

DoDon’t
Use FQDN: orders-db.prod.example.com:3306Use IP addresses (they can change)
Include port: mydb:5432Omit port: mydb
Be consistent across all databasesUse different formats for different databases

For AWS RDS/Aurora:

Use the instance endpoint, not the cluster endpoint:

Alloy
// Correct - instance endpoint
instance = "mydb-instance.abcd1234.us-east-1.rds.amazonaws.com:5432"

// Incorrect - cluster endpoint (changes during failover)
instance = "mydb-cluster.cluster-abcd1234.us-east-1.rds.amazonaws.com:5432"

System-managed labels

These labels are set automatically by Alloy. Do not modify them.

LabelDescription
server_idUnique server identifier, used internally to associate telemetry
opOperation type for log entries (query_sample, query_association, wait_event, explain_plan_output, create_statement, health_status)

Warning

Do not override server_id or op in relabel rules. Modifying these labels prevents Database Observability from querying and correlating your data.

Database-specific labels

These labels come from the database itself and are automatically added by exporters.

PostgreSQL labels

LabelSourceDescription
datnamepg_stat_statementsDatabase name
usenamepg_stat_statementsUser who executed query
queryidpg_stat_statementsUnique query identifier

MySQL labels

LabelSourceDescription
schemaperformance_schemaDatabase schema name
digestperformance_schemaStatement digest (query identifier)
userperformance_schemaDatabase user

Add these labels in both loki.relabel and discovery.relabel to organize and filter databases. Values must match across both components.

LabelPurposeExample values
appApplication that uses the databaseorder-service, user-api
teamTeam responsible for the databasecheckout, platform
environmentDeployment stageproduction, staging, dev
regionGeographic region or data centerus-east-1, eu-west-1
clusterDatabase cluster (for replicated setups)orders-primary, orders-replica
providerInfrastructure provideraws, gcp, azure, self-managed

Example:

Alloy
rule {
  target_label = "app"
  replacement  = "order-service"
}

For complete configuration examples showing custom labels in context, refer to Monitor multiple databases.

Environment variables

For dynamic labels, use environment variables:

Alloy
rule {
  target_label = "environment"
  replacement  = sys.env("DEPLOYMENT_ENV")
}

rule {
  target_label = "region"
  replacement  = sys.env("AWS_REGION")
}

Label name and value restrictions

RestrictionDetails
Name charactersLetters, numbers, underscores. Must match [a-zA-Z_][a-zA-Z0-9_]*
Value charactersAny UTF-8 string
CaseCase-sensitive; use lowercase for consistency
EmptyEmpty values are ignored