MySQL Server
When integrating a MySQL data source using this handler, the configuration is defined in an .ini
format. Each section within the configuration file represents a different data source profile. Below is an example configuration and a breakdown of each field:
[example_mysql]
source = mysql.example.com
port = 3306
type = mysql
identifier = mysql-metrics
username = dbuser
password = secret
default_db = mydatabase
query = SELECT host, status, COUNT(*) as total FROM connections GROUP BY host, status;
Breakdown of Configuration Fields
-
[example_mysql]
This is the name of the configuration profile. It is an arbitrary label for internal reference within your configuration file. -
source
Specifies the hostname or IP address of the MySQL server.
Example:mysql.example.com
tells the handler where to connect for data. -
port
Defines the port number on which the MySQL server is listening.
Default MySQL port:3306
. -
type
Indicates the type of data source. For MySQL connections, this is always set tomysql
. -
identifier
This is a crucial field, as it determines the URL segment used to expose the metrics.
For example, withidentifier = mysql-metrics
, the metrics will be accessible via:http://<YOUR_HOST>/mysql-metrics/prometheus
This allows easy organisation and access to multiple data sources via different endpoints. -
username
The username used for authenticating with the MySQL database. -
password
The corresponding password for the provided username.
(Ensure this is stored securely and access to the configuration file is properly restricted.) -
default_db
Specifies the default database to use when connecting to MySQL.
Example:mydatabase
. -
query
This is the SQL query that will be executed against the database. It is used to collect and return metrics or data points.
Example query:SELECT host, status, COUNT(*) as total FROM connections GROUP BY host, status;
This example query counts the number of connections grouped by host and status.
Additionally, the
query
field supports referencing an external SQL file instead of embedding the query directly in the configuration. To do this, prefix the full file path with<<
.
Example:query =<</opt/sql/graphquery.sql
This improves maintainability, especially for complex or lengthy queries.
Summary
This configuration enables the integration of a MySQL data source for metric collection and monitoring. Each field plays a specific role in defining how the connection is established, authenticated, and how data is retrieved. The use of identifier allows for clear segmentation of metric endpoints, and the flexibility of the query field ensures both inline and external SQL scripts are supported.