Microsoft SQL Server
When integrating a Microsoft SQL Server (MSSQL) data source using this handler, the configuration remains in .ini
format, with some fields consistent across database types, and some that are specific to MSSQL.
Here’s an example MSSQL configuration:
[example_mssql]
source = sqlserver.example.com
port = 1433
type = mssql
identifier = mssql-metrics
username = dbuser
password = secret
default_db = mydatabase
query = SELECT host_name, status, COUNT(*) as total FROM connections GROUP BY host_name, status;
Breakdown of Configuration Fields
-
[example_mssql]
This is the profile name for this specific data source. It’s an arbitrary label, used internally within your configuration file. -
source
The hostname or IP address of the Microsoft SQL Server instance.
Example:sqlserver.example.com
. -
port
The port number for connecting to MSSQL.
Default MSSQL port:1433
. -
type
Defines the data source type. For Microsoft SQL Server, this is set tomssql
. -
identifier
Specifies the URL segment for accessing this data source’s metrics endpoint.
For example, withidentifier = mssql-metrics
, the metrics will be available at:http://<YOUR_HOST>/mssql-metrics/prometheus
This is useful for exposing multiple data sources with clean, distinct endpoints. -
username
The username used to authenticate with the MSSQL database. -
password
The corresponding password for the username.
(As always, ensure secure storage and restricted access to configuration files.) -
default_db
Sets the default database that the handler will connect to on the SQL Server.
Example:mydatabase
. -
query
The SQL query to execute when retrieving data for metrics or analysis.
Example query:SELECT host_name, status, COUNT(*) as total FROM connections GROUP BY host_name, status;
In this example, the query groups connection data by
host_name
andstatus
, counting the total number of records for each group.Alternatively, the
query
field can reference an external SQL file rather than embedding the SQL inline. To do this, use the<<
prefix followed by the full path to the file.
Example:query =<</opt/sql/graphquery.sql
This is especially helpful for maintaining complex or frequently updated queries outside of the configuration file itself.