MySQL
Integrating MySQL Metrics and Logs to KubeSense
KubeSense provides native monitoring for MySQL through the OpenTelemetry (OTEL) Collector, allowing you to capture key MySQL performance metrics and logs and visualize them in the KubeSense platform.
Prerequisites
Before you begin, ensure you have:
- A MySQL server running version 5.7 or newer
- You can check the server version with the SQL statement:
SELECT VERSION();
- You can check the server version with the SQL statement:
- A MySQL user with permissions required for metrics collection
CREATE USER 'kubesense'@'%' IDENTIFIED BY '<PASSWORD>'; GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'kubesense'@'%'; FLUSH PRIVILEGES; - KubeSense deployed with an OTEL Collector that can reach the MySQL server
- Install the OTEL Collector if not done already
- Ensure the OTEL collector can connect to the MySQL endpoint using the monitoring user
- For log collection, the OTEL collector must be able to read the MySQL log files
- Access to modify the KubeSense Helm values file
Collecting MySQL Metrics
Step 1: Update KubeSense Helm Values File
Add the MySQL receiver configuration to your KubeSense Helm values file, within the kubesensor section:
otel-collector:
config:
receivers:
mysql:
# The hostname (and optional port) of the MySQL server.
endpoint: <MYSQL_ENDPOINT>:3306
# The username used to access the MySQL instance.
username: kubesense
# The password used to access the MySQL instance.
password: <password>
# Frequency for collecting metrics.
collection_interval: 10s
# Delay applied before the receiver starts scraping.
initial_delay: 10s
# tls:
# insecure: false
# ca_file: /etc/ssl/certs/ca-certificates.crt
# cert_file: /etc/ssl/certs/mysql.crt
# key_file: /etc/ssl/certs/mysql.key
appendToPipelines:
metrics:
receivers:
- mysqlNote: Replace the endpoint, username, and password values with your actual MySQL server details. Ensure the endpoint is reachable from the OTEL collector pod.
Step 2: Apply the Configuration
Upgrade your KubeSense deployment with the updated values file:
helm upgrade kubesense kubesense/kubesense \
-f values.yaml \
--namespace kubesenseCollecting MySQL Logs
Step 1: Update KubeSense Helm Values File for Log Collection
Add the MySQL log collection configuration to your KubeSense Helm values file:
otel-collector:
config:
receivers:
filelog/mysql:
include: ["/var/log/mysql/*.log"]
start_at: beginning
operators:
- type: regex_parser
# Adjust the pattern to match your MySQL log format.
regex: '^(?P<ts>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z?)\s+(?P<level>[A-Z]+)\s+(?P<message>.*)$'
timestamp:
parse_from: attributes.ts
layout: '%Y-%m-%dT%H:%M:%S'
severity:
parse_from: attributes.level
on_error: send
- type: move
if: attributes.message != nil
from: attributes.message
to: body
- type: remove
if: attributes.level != nil
field: attributes.level
- type: add
field: attributes.source
value: mysql
processors:
batch/mysql:
send_batch_size: 10000
send_batch_max_size: 11000
timeout: 10s
service:
pipelines:
logs/mysql:
receivers:
- filelog/mysql
processors:
- batch
- resource
exporters:
- otlphttp/kubesense_logsNote: Update the include path and regex to match your MySQL log format. Common locations include /var/log/mysql/mysql.log, /var/log/mysql/error.log, or /var/log/mysql/slow.log. The OTEL collector must have read access to these files.
Step 2: Apply the Configuration
Upgrade your KubeSense deployment with the updated values file:
helm upgrade kubesense kubesense/kubesense \
-f values.yaml \
--namespace kubesenseMySQL Metrics Collected
KubeSense automatically collects and enriches the following key MySQL metrics:
| Metric Name | Type | Unit | Description |
|---|---|---|---|
| mysql_connections | gauge | count | Number of active client connections |
| mysql_threads_connected | gauge | count | Total number of open connections |
| mysql_threads_running | gauge | count | Number of currently running threads |
| mysql_queries | sum | count | Total queries executed since server start |
| mysql_slow_queries | sum | count | Total slow queries recorded |
| mysql_commands | sum | count | Total SQL commands executed |
| mysql_innodb_buffer_pool_size | gauge | bytes | Allocated InnoDB buffer pool size |
| mysql_innodb_buffer_pool_used | gauge | bytes | InnoDB buffer pool usage |
| mysql_bytes_received | sum | bytes | Total bytes received by the server |
| mysql_bytes_sent | sum | bytes | Total bytes sent by the server |
| mysql_uptime | gauge | seconds | Server uptime in seconds |
MySQL Log Attributes
When collecting MySQL logs, the following attributes are available:
| Name | Path | Type | Description |
|---|---|---|---|
| Timestamp | timestamp | timestamp | Log entry timestamp |
| Severity Text | severity_text | string | Severity label parsed from the log |
| Message | body | string | Log message body |
| Source | attributes.source | string | Source identifier (set to "mysql") |
Visualization in KubeSense
Once configured, MySQL metrics and logs appear within the KubeSense dashboards, enabling you to:
- Monitor MySQL workload and query throughput in real time
- Track connection usage and thread activity
- Analyze buffer pool utilization and data transfer volume
- Review MySQL logs alongside other platform telemetry
- Configure alerts for critical MySQL performance indicators
Configuration Parameters
Here's a breakdown of the MySQL receiver configuration:
| Parameter | Type | Required | Description |
|---|---|---|---|
endpoint | string | Yes | MySQL server endpoint (host:port) |
username | string | Yes | Username for MySQL authentication |
password | string | Yes | Password for MySQL authentication |
collection_interval | string | No | Metrics scrape frequency (default: 60s) |
initial_delay | string | No | Delay before the first scrape begins |
tls.* | string/boolean | No | TLS settings for secured MySQL connections |
Troubleshooting
Issue: Cannot connect to MySQL server
Solution: Verify the endpoint is reachable from the OTEL collector pod.
Issue: Authentication failed
Solution: Confirm the monitoring user credentials and privileges:
SHOW GRANTS FOR 'kubesense'@'%';Issue: Logs not being collected
Solution: Ensure the log path exists and is accessible:
kubectl exec -n kubesense <otel-collector-pod> -- ls -la /var/log/mysql/Issue: Metrics not appearing in dashboard
Solution: Check the OTEL collector logs for errors:
kubectl logs -n kubesense <kubesense-otel-collector-pod> -fBest Practices
- Security: Use a dedicated read-only monitoring user with scoped privileges
- Network: Ensure OTEL collector pods can reach the MySQL host over the required port
- Logging: Enable general and slow query logs for deeper visibility into query behavior
- Performance: Tune
collection_intervalandinitial_delayto balance load and timeliness - Lifecycle: Rotate MySQL logs regularly to avoid disk pressure on the collector nodes
Conclusion
With KubeSense and the OTEL collector, you can observe MySQL performance and logs alongside the rest of your infrastructure, enabling faster troubleshooting and a unified view of your database health.