### Add Helm Repository and Install sql-exporter Source: https://github.com/burningalchemist/sql_exporter/blob/master/helm/README.md Add the sql_exporter Helm repository and install the chart with the release name 'sql-exporter'. ```bash helm repo add sql_exporter https://burningalchemist.github.io/sql_exporter/ helm install sql_exporter/sql-exporter ``` -------------------------------- ### Example Query with NOLOCK Hint Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md This query demonstrates the use of the NOLOCK hint to avoid blocking. Use with caution as it can lead to reading uncommitted data. ```sql SELECT database_id, name, state_desc FROM sys.databases WITH (NOLOCK) WHERE state_desc = 'ONLINE'; ``` -------------------------------- ### PgBouncer Metric Configuration Example Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Configure metrics for PgBouncer by setting 'no_prepared_statement: true' and specifying the query to retrieve database information. ```yaml metrics: - metric_name: max_connections no_prepared_statement: true type: gauge values: [max_connections] key_labels: - name - database - force_user - pool_mode - disabled - paused - current_connections - reserve_pool - min_pool_size - pool_size - port query: | SHOW DATABASES; ``` -------------------------------- ### Helm Chart Collector Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md Example of how to configure collector files within a Helm chart deployment for sql_exporter. ```yaml collectorFiles: mssql_standard.collector.yml: | # Contents of mssql_standard.collector.yml config: target: data_source_name: "sqlserver://username:password@hostname:1433?database=master" collector_files: - "*.collector.yml" ``` -------------------------------- ### YAML Configuration for Adding Custom Metrics Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Extend existing collectors or define new ones with custom SQL queries. This example shows how to add a metric for table size. ```yaml collectors: - collector_name: pg_custom metrics: - metric_name: custom_table_size type: gauge help: 'Custom table sizes' values: [size_bytes] query: | SELECT pg_total_relation_size('my_table') as size_bytes; ``` -------------------------------- ### Deploy SQL Exporter with Helm Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-only/README.md Install the SQL Exporter using Helm, specifying a custom values file for TLS-only configuration. This command assumes the Helm chart is located two directories up. ```bash helm install sql-exporter ../../helm -f values-example.yaml ``` -------------------------------- ### Azure SQL MI Connection String with SQL Authentication Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Example connection string for Azure SQL Managed Instance using SQL authentication. Replace placeholders with your actual credentials and instance name. ```plaintext sqlserver://sqladmin:SecureP@ssw0rd@myinstance.database.windows.net:1433?database=master&encrypt=true ``` -------------------------------- ### SQL Query to Filter Specific Databases Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Example SQL snippet to filter out system databases from monitoring queries. Use this to focus on user-created databases. ```sql WHERE datname NOT IN ('postgres', 'template0', 'template1') ``` -------------------------------- ### Azure SQL MI Connection String with Azure AD Authentication Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Example connection string for Azure SQL Managed Instance using Azure AD authentication. The `fedauth=ActiveDirectoryPassword` parameter is required. ```plaintext sqlserver://myuser@domain.com:password@myinstance.database.windows.net:1433?database=master&encrypt=true&fedauth=ActiveDirectoryPassword ``` -------------------------------- ### Helm Install with Secret Access Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Deploy SQL Exporter using Helm, ensuring the service account, RBAC roles, and secret access are configured automatically. This command assumes you have a `values-override-static-config.yaml` file. ```bash helm install sql-exporter ./helm \ -f deployment/values-override-static-config.yaml \ -n your-namespace ``` -------------------------------- ### Generate Minimal Drivers and Build SQL Exporter Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Regenerates the drivers.go file with a minimal set of imported drivers and then builds the SQL Exporter binary. Useful for reducing binary size. ```shell make drivers-minimal make build ``` -------------------------------- ### SQL Server Connection String Formats Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md Demonstrates various connection string formats for SQL Server authentication, Windows Authentication, and Azure SQL Database. ```text sqlserver://username:password@hostname:1433?database=master ``` ```text sqlserver://hostname:1433?database=master&integrated security=SSPI ``` ```text sqlserver://username:password@server.database.windows.net:1433?database=dbname&encrypt=true ``` -------------------------------- ### Build SQL Exporter Binary Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Builds the SQL Exporter binary with all supported drivers included. This is the default build command. ```shell make build ``` -------------------------------- ### SQL Exporter Help Information Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Display help information for the SQL Exporter command-line interface. Shows available flags and their default values. ```shell $ ./sql_exporter -help Usage of ./sql_exporter: -config.file string SQL Exporter configuration file path. (default "sql_exporter.yml") -config.check Check configuration and exit. -web.listen-address string Address to listen on for web interface and telemetry. (default ":9399") -web.metrics-path string Path under which to expose metrics. (default "/metrics") [...] ``` -------------------------------- ### Bash Command to Test Collector Queries Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Execute a collector configuration file directly using `psql` to test the SQL queries defined within it. This is useful for debugging query logic. ```bash psql -h hostname -U sql_exporter -d postgres -f postgres_database.yml ``` -------------------------------- ### Verify SQL Exporter Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-auth/README.md Exec into the SQL Exporter pod to inspect its configuration file and confirm settings. ```bash kubectl exec -- cat /etc/sql_exporter/sql_exporter.yml ``` -------------------------------- ### Register SQL Exporter as a Windows Service (CMD) Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Register SQL Exporter as an automatic Windows service using CMD. Ensure the config.file parameter is set. ```cmd sc.exe create SqlExporterSvc binPath= "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" start= auto ``` -------------------------------- ### Verify SQL Exporter Deployment and Metrics Endpoint Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-only/README.md Check the status of the SQL Exporter pods and then test the metrics endpoint by port-forwarding the service and using curl to fetch metrics over HTTPS. The '-k' flag for curl is used to skip certificate verification for local testing. ```bash # Check pod status kubectl get pods -l app.kubernetes.io/name=sql-exporter # Test metrics endpoint (with TLS) kubectl port-forward svc/sql-exporter 9399:9399 curl -k https://localhost:9399/metrics ``` -------------------------------- ### Enable Ingress for sql-exporter Source: https://github.com/burningalchemist/sql_exporter/blob/master/helm/README.md Enable ingress creation for the sql-exporter chart by setting the 'ingress.enabled' value to true. Note that using ingress is not recommended by maintainers due to potential DDoS attack vectors. ```yaml #Values ingress: enabled: true ``` -------------------------------- ### Verify SQL Exporter Pod and Metrics Endpoint Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/auth-only/README.md Check the status of the SQL Exporter pod and test the metrics endpoint by port-forwarding and using curl with basic authentication credentials. ```bash # Check pod status kubectl get pods -l app.kubernetes.io/name=sql-exporter # Test metrics endpoint (with auth) kubectl port-forward svc/sql-exporter 9399:9399 curl -u prometheus:your-secure-password http://localhost:9399/metrics ``` -------------------------------- ### Multiple Database Connections Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Configure multiple database connections using the 'jobs' list instead of 'target'. This allows for different collectors and static configurations per job. ```yaml jobs: - job_name: db_targets collectors: [pricing_data_freshness, pricing_*] enable_ping: true # Optional, true by default. Set to `false` in case you connect to pgbouncer or a data warehouse static_configs: - targets: pg1: 'pg://db1@127.0.0.1:25432/postgres?sslmode=disable' pg2: 'postgresql://username:password@pg-host.example.com:5432/dbname?sslmode=disable' labels: # Optional, arbitrary key/value pair for all targets cluster: cluster1 ``` -------------------------------- ### SQL Query for Checking User Existence Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Use this SQL query to verify if a specific user exists in the SQL Server instance. ```sql SELECT * FROM sys.sql_logins WHERE name = 'sql_exporter'; ``` -------------------------------- ### MySQL TCP vs. Unix Socket Connections Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Illustrates the difference between TCP and Unix socket connections for MySQL databases using URL-format DSNs. ```plaintext mysql://user:pass@localhost/dbname - for TCP connection mysql:/var/run/mysqld/mysqld.sock - for Unix socket connection ``` -------------------------------- ### Create Shared Secret with TLS + Password (kubectl) Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-auth/README.md Use this command to create a Kubernetes secret containing TLS certificates and a password for basic authentication. Ensure you replace `path/to/cert.crt`, `path/to/cert.key`, `your-secure-password`, and `your-namespace` with your actual values. ```bash kubectl create secret generic sql-exporter-tls-auth \ --from-file=tls.crt=path/to/cert.crt \ --from-file=tls.key=path/to/cert.key \ --from-literal=password='your-secure-password' \ --namespace=your-namespace ``` -------------------------------- ### Bash Command to Test PostgreSQL Connection Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Use the `psql` command-line tool to test the connection to your PostgreSQL database as the monitoring user. This helps verify credentials and network accessibility. ```bash psql -h hostname -U sql_exporter -d postgres -c "SELECT version();" ``` -------------------------------- ### Configure SQL Exporter with Templated DSN from Secret Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Configure SQL Exporter to build a full DSN using a template. The `key` parameter specifies which secret field to use, and `template` defines the DSN structure with `DSN_VALUE` as a placeholder for the secret's content. ```yaml config: target: data_source_name: 'k8ssecret://db-creds?key=APP_DB_CONNECTION&template=postgres://DSN_VALUE?application_name=sql-exporter&sslmode=require' collectors: - collector1 ``` -------------------------------- ### Test Metrics Endpoint with TLS and Basic Auth Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-auth/README.md Forward the SQL Exporter's metrics port to your local machine and use `curl` to access the metrics endpoint, providing the username and password for authentication. The `-k` flag is used to ignore certificate validation for self-signed certificates. ```bash # Test metrics endpoint (with TLS + auth) kubectl port-forward svc/sql-exporter 9399:9399 curl -k -u prometheus:your-secure-password https://localhost:9399/metrics ``` -------------------------------- ### Create Monitoring User for Azure SQL MI Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md SQL script to create a login and user for monitoring Azure SQL Managed Instance. Grants necessary server-level and database-level permissions. ```sql -- In master database CREATE LOGIN sql_exporter WITH PASSWORD = 'SecurePassword123!'; -- Grant server-level permissions GRANT VIEW SERVER STATE TO sql_exporter; GRANT VIEW ANY DEFINITION TO sql_exporter; -- For each monitored database USE [YourDatabase]; CREATE USER sql_exporter FOR LOGIN sql_exporter; GRANT VIEW DATABASE STATE TO sql_exporter; ``` -------------------------------- ### Test SQL Server Connection with sqlcmd Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md Bash commands to test SQL Server connectivity and query execution using the sqlcmd utility, both locally and remotely. ```bash # Using sqlcmd (if available in pod) sqlcmd -S hostname -U sql_exporter -P 'password' -d master -Q "SELECT @@VERSION;" # Test from outside sqlcmd -S hostname,1433 -U sql_exporter -P 'password' -Q "SELECT * FROM sys.dm_os_performance_counters WHERE counter_name = 'Page life expectancy';" ``` -------------------------------- ### Reset Drivers to Default Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Regenerates the drivers.go file to include the default set of drivers, reverting any minimal driver changes. ```shell make drivers-all ``` -------------------------------- ### Minimum Permissions for SQL Exporter Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md SQL script to create a login, user, and grant necessary server and database state permissions for sql_exporter. ```sql -- Create login and user CREATE LOGIN sql_exporter WITH PASSWORD = 'SecurePassword123!'; CREATE USER sql_exporter FOR LOGIN sql_exporter; -- Grant VIEW SERVER STATE permission GRANT VIEW SERVER STATE TO sql_exporter; GRANT VIEW ANY DEFINITION TO sql_exporter; -- For database-specific metrics USE [YourDatabase]; CREATE USER sql_exporter FOR LOGIN sql_exporter; GRANT VIEW DATABASE STATE TO sql_exporter; ``` -------------------------------- ### SQL Permissions for Monitoring User Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md SQL commands to create a monitoring user and grant necessary permissions for sql_exporter to access PostgreSQL statistics views. Ensure you use a strong password. ```sql -- Create monitoring user CREATE USER sql_exporter WITH PASSWORD 'secure_password'; -- Grant connection GRANT CONNECT ON DATABASE postgres TO sql_exporter; -- Grant read access to statistics views GRANT pg_monitor TO sql_exporter; -- PostgreSQL 10+ -- For PostgreSQL 9.6 and earlier: GRANT SELECT ON pg_stat_database TO sql_exporter; GRANT SELECT ON pg_stat_activity TO sql_exporter; GRANT SELECT ON pg_stat_replication TO sql_exporter; ``` -------------------------------- ### Create Secret with Partial DSN Credentials Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Store only credentials and connection details in a secret, to be combined with a template later. The key `APP_DB_CONNECTION` is used here. ```bash kubectl create secret generic db-creds \ --from-literal=APP_DB_CONNECTION='user:password@host:5432/database' ``` -------------------------------- ### Register SQL Exporter as a Windows Service (PowerShell) Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Register SQL Exporter as an automatic Windows service using PowerShell. Ensure the config.file parameter is set. ```powershell New-Service -name "SqlExporterSvc" ` -BinaryPathName "%SQL_EXPORTER_PATH%\sql_exporter.exe --config.file %SQL_EXPORTER_PATH%\sql_exporter.yml" ` -StartupType Automatic ` -DisplayName "Prometheus SQL Exporter" ``` -------------------------------- ### Verify Azure SQL MI Permissions Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md SQL queries to verify that the monitoring user has been granted the correct server-level and database-level permissions. ```sql -- Check granted permissions SELECT * FROM sys.server_permissions WHERE grantee_principal_id = USER_ID('sql_exporter'); -- Test DMV access SELECT COUNT(*) FROM sys.dm_os_performance_counters; SELECT COUNT(*) FROM sys.dm_os_wait_stats; ``` -------------------------------- ### Create Secret with Full DSN Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Use this command to store a complete DSN string in a Kubernetes secret. The `data_source_name` key is used by default. ```bash kubectl create secret generic postgres-db \ --from-literal=data_source_name='postgres://user:password@host:5432/mydb?sslmode=require' ``` -------------------------------- ### Deploy Azure SQL Exporter with Helm Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Deploys the SQL exporter using Helm, specifying collector files and ServiceMonitor configuration. The `values-azure-sql-mi.yaml` file should contain the collector configurations. ```yaml # values-azure-sql-mi.yaml # Include collector files via collectorFiles or inline in template collectorFiles: mssql_mi_properties.collector.yml: | # Contents from file mssql_mi_clerk.collector.yml: | # Contents from file # ... other collectors serviceMonitor: enabled: true interval: 30s ``` ```bash helm install sql-exporter ../../helm -f values-azure-sql-mi.yaml ``` -------------------------------- ### PostgreSQL Connection String Format Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Standard format for PostgreSQL connection strings used by sql_exporter. Includes placeholders for credentials and host information. ```plaintext postgres://username:password@hostname:5432/database?sslmode=disable ``` -------------------------------- ### SQL Exporter Global and Target Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Defines global settings and a specific target for SQL Exporter. Use for setting scrape timeouts, connection limits, and specifying data sources and collectors for a target database. ```yaml # Global settings and defaults. global: # Subtracted from Prometheus' scrape_timeout to give us some headroom and prevent Prometheus from # timing out first. scrape_timeout_offset: 500ms # Minimum interval between collector runs: by default (0s) collectors are executed on every scrape. min_interval: 0s # Maximum number of open connections to any one target. Metric queries will run concurrently on # multiple connections. max_connections: 3 # Maximum number of idle connections to any one target. max_idle_connections: 3 # Maximum amount of time a connection may be reused to any one target. Infinite by default. max_connection_lifetime: 10m # Expose per-query `query_duration_seconds` and `query_rows_returned` gauges, labelled with the # `query` name (and `target` in multi-target mode). Off by default to keep the metric surface stable. enable_query_metrics: false # The target to monitor and the list of collectors to execute on it. target: # Target name (optional). Setting this field enables extra metrics e.g. `up` and `scrape_duration` with # the `target` label that are always returned on a scrape. name: "prices_db" # Data source name always has a URI schema that matches the driver name. In some cases (e.g. MySQL) # the schema gets dropped or replaced to match the driver expected DSN format. data_source_name: 'sqlserver://prom_user:prom_password@dbserver1.example.com:1433' # Collectors (referenced by name) to execute on the target. # Glob patterns are supported (see for syntax). collectors: [pricing_data_freshness, pricing_*] # In case you need to connect to a backend that only responds to a limited set of commands (e.g. pgbouncer) or # a data warehouse you don't want to keep online all the time (due to the extra cost), you might want to disable `ping` # enable_ping: true # Collector definition files. # Glob patterns are supported (see for syntax). collector_files: - "*.collector.yml" ``` -------------------------------- ### Create Database Secret for Azure SQL MI Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Creates a Kubernetes secret to store Azure SQL MI credentials. Ensure the DSN format is correct and the namespace is set. ```bash kubectl create secret generic azuresql-mi-credentials \ --from-literal=dsn='username:password@myinstance.database.windows.net:1433/master?encrypt=true' \ --namespace=monitoring ``` -------------------------------- ### PromQL Alert for Low Page Life Expectancy Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Set up an alert for when Page Life Expectancy drops below 300 seconds. ```promql mssql_page_life_expectancy{instance="$instance"} < 300 ``` -------------------------------- ### Configure Rate Limiting for HTTP Requests Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md To enable rate limiting for incoming HTTP requests, specify rate limiting settings in a configuration file passed via the --web.config.file parameter. The interval defines the time between requests, and burst permits a number of requests within that interval. ```yaml ... rate_limit: interval: "1s" # time interval between two requests, set to 0 to disable rate limiter burst: 20 # and permits a burst of up to 20 requests. ... ``` -------------------------------- ### Add Wait Statistics Collector Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md YAML configuration to add a collector for monitoring SQL Server wait statistics, specifically tracking wait time by wait type. ```yaml collectors: - collector_name: mssql_waits metrics: - metric_name: mssql_wait_time_ms type: counter help: 'Wait time by wait type' key_labels: - wait_type values: - wait_time_ms query: | SELECT wait_type, wait_time_ms FROM sys.dm_os_wait_stats WHERE wait_type NOT LIKE 'SLEEP%' AND wait_type NOT LIKE 'BROKER%' ORDER BY wait_time_ms DESC; ``` -------------------------------- ### PromQL Alert for Log Size Utilization Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Alert when the log file size exceeds 80% of its allocated limit. ```promql (mssql_log_size_mb / mssql_log_size_limit_mb) > 0.8 ``` -------------------------------- ### PromQL Alert for Deadlocks Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Trigger an alert when deadlocks are detected over a 5-minute interval. ```promql rate(mssql_deadlocks_total{instance="$instance"}[5m]) > 0 ``` -------------------------------- ### PromQL Alert for High CPU Usage Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Configure Prometheus to alert when CPU usage exceeds 80% for 5 minutes. ```promql avg(mssql_cpu_usage_percent{instance="$instance"}) > 80 ``` -------------------------------- ### Configure SQL Exporter to Use Full DSN from Secret Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Configure the SQL Exporter to use a DSN stored directly in a Kubernetes secret. No template is needed if the full DSN is present. ```yaml config: target: data_source_name: 'k8ssecret://postgres-db' collectors: - collector1 ``` -------------------------------- ### Create Kubernetes TLS Secret Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-only/README.md Use this command to create a Kubernetes secret of type 'tls' containing your certificate and private key. Ensure the secret is created in the same namespace as your deployment. ```bash kubectl create secret tls sql-exporter-tls \ --cert=path/to/cert.crt \ --key=path/to/cert.key \ --namespace=your-namespace ``` -------------------------------- ### Verify SQL Exporter Pod Status Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-auth/README.md Check the status of the SQL Exporter pods to ensure they are running correctly after deployment. ```bash # Check pod status kubectl get pods -l app.kubernetes.io/name=sql-exporter # Check pod is ready kubectl describe pod ``` -------------------------------- ### Enable Custom TLS Certificates for MySQL Connections Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md For MySQL connections, use custom TLS certificates by setting 'tls=custom' in the DSN. Provide the path to the CA certificate using 'tls-ca' for self-signed or private CA certificates. For mTLS, specify client certificate and key paths with 'tls-cert' and 'tls-key'. ```sql mysql://user:password@hostname:port/dbname?tls=custom&tls-ca=/path/to/ca.pem ``` ```sql mysql://user:password@hostname:port/dbname?tls=custom&tls-cert=/path/to/client-cert.pem&tls-key=/path/to/client-key.pem ``` -------------------------------- ### Helm Chart Collector Files Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Configure collector files for sql_exporter using the Helm chart's `collectorFiles` option. This method is recommended for managing collector configurations. ```yaml collectorFiles: postgres_database.yml: | # Contents of postgres_database.yml postgres_server.yml: | # Contents of postgres_server.yml config: target: data_source_name: "postgres://username:password@hostname:5432/postgres?sslmode=disable" collector_files: - "*.collector.yml" ``` -------------------------------- ### HashiCorp Vault Reference Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Reference HashiCorp Vault secrets for database credentials. Specify the mount path, secret path, and optionally a JSON key. ```plaintext hashivault:///?key= ``` -------------------------------- ### Create Shared Secret for Self-Signed Certificates (kubectl) Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/tls-auth/README.md This command sequence generates self-signed TLS certificates and then creates a Kubernetes secret with these certificates and a password. This is useful for testing or development environments. ```bash openssl req -x509 -newkey rsa:4096 -keyout tls.key -out tls.crt -days 365 -nodes kubectl create secret generic sql-exporter-tls-auth \ --from-file=tls.crt=tls.crt \ --from-file=tls.key=tls.key \ --from-literal=password='your-secure-password' \ --namespace=your-namespace ``` -------------------------------- ### YAML Configuration for Custom Collection Interval Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Adjust the collection interval for a specific collector using the `min_interval` setting in the YAML configuration. This allows fine-grained control over metric refresh rates. ```yaml collectors: - collector_name: pg_database min_interval: 60s # Collect every minute metrics: # ... metric definitions ``` -------------------------------- ### Configure Collector Intervals in YAML Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Adjust the `min_interval` for different collectors to optimize performance and data freshness. Static data collectors can have longer intervals, while performance counters require more frequent updates. ```yaml collectors: - collector_name: mssql_mi_properties min_interval: 300s # Static data, check every 5 minutes - collector_name: mssql_mi_perf min_interval: 15s # Performance counters, frequent updates - collector_name: mssql_mi_wait min_interval: 30s # Wait stats, moderate frequency - collector_name: mssql_mi_size min_interval: 60s # Database sizes, check every minute ``` -------------------------------- ### Azure SQL MI Connection String Format Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Specifies the connection string format for Azure SQL Managed Instance. Ensure `encrypt=true` is used for TLS and connect to the `master` database for instance-level queries. ```plaintext sqlserver://username:password@instance-name.database.windows.net:1433?database=master&encrypt=true ``` -------------------------------- ### Create Kubernetes Secret for Auth Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/auth-only/README.md Create a Kubernetes secret to store the plaintext password for basic authentication. This secret is used by the SQL Exporter pod. ```bash kubectl create secret generic sql-exporter-auth \ --from-literal=password='your-secure-password' \ --namespace=your-namespace ``` -------------------------------- ### Azure SQL Database Permissions Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md SQL script for granting permissions in Azure SQL Database, requiring login creation in master and user creation/grants in each monitored database. ```sql -- In master database CREATE LOGIN sql_exporter WITH PASSWORD = 'SecurePassword123!'; -- In each monitored database CREATE USER sql_exporter FOR LOGIN sql_exporter; GRANT VIEW DATABASE STATE TO sql_exporter; ``` -------------------------------- ### Azure-Specific Metric: Storage Utilization Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/azure-sql-mi/README.md Define a custom Prometheus metric to monitor storage utilization percentage for Azure SQL Managed Instance. This query calculates the percentage of used space relative to the total allocated size for database files. ```yaml - metric_name: azure_sql_mi_storage_percent type: gauge help: 'Storage utilization percentage' query: | SELECT (SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS bigint)) * 8192.0 / SUM(size) * 8192.0) * 100 as storage_percent FROM sys.database_files; ``` -------------------------------- ### Kubernetes Secrets Reference Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Reference Kubernetes secrets for database credentials in SQL Exporter configurations. Requires RBAC permissions. ```plaintext k8ssecret://[namespace/]secret-name?key=field&template=dsn_template ``` -------------------------------- ### Configure SQL Exporter to Use Cross-Namespace Secret Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/k8s-secret/README.md Reference a secret located in a different Kubernetes namespace. Note that this requires additional ClusterRole permissions not included by default and is not recommended for production. ```yaml config: target: data_source_name: 'k8ssecret://monitoring/db-secret' # From 'monitoring' namespace collectors: - collector1 ``` -------------------------------- ### Filter Specific Databases SQL Query Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md SQL snippet to exclude system databases from size calculations, focusing on 'ONLINE' user databases. ```sql WHERE database_id > 4 -- Skip master, tempdb, model, msdb AND state_desc = 'ONLINE' ``` -------------------------------- ### MSSQL WinSSPI Authentication Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Use WinSSPI for authentication with MSSQL when SQL Exporter runs in the same Windows domain. No additional credentials are required. ```plaintext sqlserver://@:?authenticator=winsspi ``` -------------------------------- ### GCP Secrets Manager Reference Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Reference GCP secrets for database credentials. Specify the secret name, project ID, and optionally a JSON key. ```plaintext gcpsecretsmanager://?project_id=&key= ``` -------------------------------- ### Monitor Always On Availability Groups Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md YAML configuration to add a collector for monitoring the health of Always On Availability Group replicas, including primary replica status. ```yaml collectors: - collector_name: mssql_availability_groups metrics: - metric_name: mssql_ag_replica_health type: gauge help: 'Always On AG replica health' key_labels: - ag_name - replica_server_name - synchronization_state values: - is_primary_replica query: | SELECT ag.name as ag_name, ar.replica_server_name, rs.synchronization_state_desc as synchronization_state, CASE WHEN ar.replica_server_name = @@SERVERNAME AND rs.role_desc = 'PRIMARY' THEN 1 ELSE 0 END as is_primary_replica FROM sys.dm_hadr_availability_replica_states rs JOIN sys.availability_replicas ar ON rs.replica_id = ar.replica_id JOIN sys.availability_groups ag ON ag.group_id = ar.group_id; ``` -------------------------------- ### MSSQL NTLM Authentication Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Use NTLM for Windows credential authentication with MSSQL. Provide Windows username and password, potentially prefixed with the domain. ```plaintext sqlserver://:@:?authenticator=ntlm ``` -------------------------------- ### Enable Remote Admin Connections Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/mssql/README.md This T-SQL command enables remote connections to the SQL Server instance. It is often required for external tools to connect. ```sql sp_configure 'remote admin connections', 1; ``` -------------------------------- ### Helm Chart Static Config Configuration Source: https://github.com/burningalchemist/sql_exporter/blob/master/examples/postgres/README.md Configure collectors directly within the Helm chart's static configuration. This method allows inline collector definitions. ```yaml config: target: data_source_name: "postgres://username:password@hostname:5432/postgres?sslmode=disable" collectors: - pg_database - pg_stat_activity collectors: # Inline collector definitions from postgres_database.yml and postgres_server.yml ``` -------------------------------- ### Filtering Metrics by Job Name in Prometheus Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Use the 'jobs[]' query parameter in Prometheus configuration to filter which jobs are scraped by the SQL Exporter. This is useful for advanced use cases like different scraping intervals. ```yaml params: jobs[]: - db_targets1 - db_targets2 ``` -------------------------------- ### AWS Secrets Manager Reference Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Reference AWS secrets for database credentials. Specify the secret name, region, and optionally a JSON key. ```plaintext awssecretsmanager://?region=&key= ``` -------------------------------- ### SQL Exporter Custom Collector Definition Source: https://github.com/burningalchemist/sql_exporter/blob/master/README.md Defines a custom collector for SQL Exporter to export Prometheus gauge metrics. Use this to create reusable metric definitions based on SQL queries. ```yaml # This collector will be referenced in the exporter configuration as `pricing_data_freshness`. collector_name: pricing_data_freshness # A Prometheus metric with (optional) additional labels, value and labels populated from one query. metrics: - metric_name: pricing_update_time type: gauge help: 'Time when prices for a market were last updated.' key_labels: # Populated from the `market` column of each row. - Market static_labels: # Arbitrary key/value pair portfolio: income values: [LastUpdateTime] # Static metric value (optional). Useful in case we are interested in string data (key_labels) only. It's mutually # exclusive with `values` field. # static_value: 1 # Timestamp value (optional). Should point at the existing column containing valid timestamps to return a metric # with an explicit timestamp. # timestamp_value: CreatedAt query: | SELECT Market, max(UpdateTime) AS LastUpdateTime FROM MarketPrices GROUP BY Market ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.