Prometheus exporter
ProxySQL 2.1+ includes a built in Prometheus exporter. This exporter lets you expose and consume relevant ProxySQL metrics through a friendly interface.
Admin variables
admin-restapi_enabled
:- Description: Enable or disables the metrics endpoint.
- Default value:
false
admin-restapi_port
:- Description: Port on which metrics endpoint is going to be exposed.
- Default value:
6070
admin-prometheus_memory_metrics_interval
:- Description: Internal interval at which memory metrics are going to be collected.
- Default value: 61
Configuration
ProxySQL automatically collects metrics during runtime regardless of the start of the metrics endpoint which is disabled by default. In order to enable it and expose these metrics you need to log into the admin console and enable the REST API:
SET admin-restapi_enabled='true';
LOAD ADMIN VARIABLES TO RUNTIME;
Optionally you can also customize the default values for the listening port and also the interval at which sensitive metrics are collected; however the default values should be ok in most cases:
SET admin-restapi_port='6070';
SET admin-prometheus_memory_metrics_interval='60';
LOAD ADMIN VARIABLES TO RUNTIME;
This can also be done by placing the following lines in your /etc/proxysql.cnf
config file:
admin_variables=
{
...
restapi_enabled=true
restapi_port=6070
prometheus_memory_metrics_interval=60
...
}
In order to see the metrics from the prometheus exporter you can either check it from command line like
curl http://127.0.0.1:6070/metrics # HELP exposer_transferred_bytes_total Transferred bytes to metrics services # TYPE exposer_transferred_bytes_total counter exposer_transferred_bytes_total 327245.000000 # HELP exposer_scrapes_total Number of times metrics were scraped # TYPE exposer_scrapes_total counter exposer_scrapes_total 13.000000 # HELP exposer_request_latencies Latencies of serving scrape requests, in microseconds # TYPE exposer_request_latencies summary exposer_request_latencies_count 13 exposer_request_latencies_sum 21090.000000 exposer_request_latencies{quantile="0.500000"} 1777.000000 exposer_request_latencies{quantile="0.900000"} 1840.000000 exposer_request_latencies{quantile="0.990000"} 1840.000000 ...
Or from you browser by entering http://127.0.0.1:6070/metrics
Important Notes
admin-restapi_port
collision:
Multiple instances of ProxySQL should have different restapi_ports
otherwise ProxySQL won’t be able to start the service responsible for exposing the metrics endpoint, this will be reflected in the logs with the following message:
Unable to start 'ProxySQL_RestAPI_Server', port '%port_number%' already in use.
In case this has occurred the service will need to be re-activated as follows:
- Switch the service off:
SET admin-restapi_enabled='false'; LOAD ADMIN VARIABLES TO RUNTIME;
. - Change the port to a new desired free one:
SET admin-restapi_port='new_free_port_number'
. - Switch the service on again:
SET admin-restapi_enabled='true'; LOAD ADMIN VARIABLES TO RUNTIME;
.
Performance considerations:
Most of the metrics are collected by ProxySQL within each of its internal modules in the form of local counters during regular operation, as done for stats exposed in the ProxySQL Admin interface. In other words, the Prometheus stats do not incur additional overhead for collection.
The Prometheus counters exposed through the RestAPI or the Admin Interface are updated ‘on-demand’, essentially, internal counters are scrapped and exposed when either endpoint is queried.
This is done for all metrics, with the exception of memory_metrics
, which defines their own internal interval, through the ‘admin-variable’ admin-prometheus_memory_metrics_interval
due to their higher performance hit.
Metrics polling is fast, and doesn’t affect normal ProxySQL operation at all, at least it has a negligible impact. Over time metrics will collect on your Prometheus Server and due to the nature and rate of the metrics being exposed we do not recommend sub-second scrapping_intervals
.
Naming:
Prometheus metrics names used by ProxySQL follow several conventions recommended by Prometheus style guide, and are also verified against promtool
checker. This ensures that all ProxySQL metrics are compatible with OpenMetrics format.