Prometheus exporter

ProxySQL 2.1+ includes a built in Prometheus exporter. This exporter let’s 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 in which metrics endpoint is going to be exposed.
    • Default value: 6070
  • admin-prometheus_memory_metrics_interval:
    • Description: Internal interval in 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 this 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
...
}

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.n
“`

In case this has occurred the service will need to be re-activated as follows:

  1. Switch the service off: SET admin-restapi_enabled='false'; LOAD ADMIN VARIABLES TO RUNTIME;.
  2. Change the port to a new desired free one: SET admin-restapi_port='new_free_port_number'.
  3. Switch the service on again: SET admin-restapi_enabled='false'; LOAD ADMIN VARIABLES TO RUNTIME;.

Performance considerations:

Most of the metrics are collected by ProxySQL within each of it’s 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, 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 have 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.