---
title: "Monitor ProxySQL with Datadog"
description: "Learn how to monitor the health and performance of your ProxySQL load balancers with Datadog."
author: "Jordan Obey"
date: 2020-05-05
tags: ["infrastructure monitoring", "proxysql", "load balancing", "cache", "sql"]
blog_type_id: the-monitor
locale: en
---

[ProxySQL](https://proxysql.com/) is a MySQL/MariaDB protocol–compliant load balancer and reverse proxy with native support for a range of popular backends including [ClickHouse](https://www.datadoghq.com/blog/monitor-clickhouse.md), [Amazon Aurora](https://www.datadoghq.com/blog/monitor-aurora-using-datadog.md), and [Amazon RDS](https://docs.datadoghq.com/integrations/amazon_rds.md). ProxySQL efficiently distributes queries to your database servers and caches results, improving resource management and boosting database performance. You can also [configure ProxySQL for high availability](https://www.percona.com/blog/2017/01/19/setup-proxysql-for-high-availability-not-single-point-failure/) to reduce downtime.

Because ProxySQL is the primary gateway for queries to your database, it's important to monitor it carefully. If ProxySQL performs poorly, you'll see increased latency and performance degradation across the parts of your stack that depend on it. With Datadog's integration, you can ensure ProxySQL continues running smoothly by visualizing, monitoring, and alerting on dozens of key metrics like memory usage and query throughput. Those metrics are included in our out-of-the-box [ProxySQL dashboard](https://app.datadoghq.com/screen/integration/30319/proxysql-overview?from_ts=1588334918427&to_ts=1588338518427&live=true) to make it easy to track the performance and resource usage of your proxy.

![an out-of-the-box ProxySQL dashboard](https://web-assets.dd-static.net/42588/1776302149-monitor-proxysql-with-datadog-proxysql-dash.png)

## Keep track of ProxySQL query cache efficiency

ProxySQL is commonly used as a query cache to expedite transactions between clients and your database servers. You can enable query caching by providing a value (in milliseconds) for the `cache_ttl` property in [ProxySQL's `mysql_query_rules`](https://github.com/sysown/proxysql/wiki/Main-(runtime)#mysql_query_rules)). ProxySQL will store results of queries for that time period. If it later receives the same query, it can quickly return those cached results instead of retrieving them from the database (which can be time intensive).

Monitoring metrics related to your query cache can help you verify that it is optimizing performance and that ProxySQL is running as expected. Datadog's ProxySQL integration provides you with the resource and performance metrics you need to ensure the query cache works efficiently.

### Correlate cache reads and writes   

For any cache, you'll want to verify that reads from it and writes to it are successful. With Datadog, you can monitor your cache read success rate by graphing the count of cache reads that were successful (`proxsql.query_cache.get_ok.count`) divided by the total amount of cache reads (`proxysql.query_cache.get.count`).

![proxysql_01v2](https://web-assets.dd-static.net/42588/1776302154-monitor-proxysql-with-datadog-proxysql_01v2.png)

You can also correlate incoming writes (`proxysql.query_cache.set.count`) with the number of entries currently stored in the cache (`proxysql.query_cache.entries`) to see how effectively data is being written/updated to your cache. If you see a discrepancy (e.g., few entries in your query cache despite a high number of writes), it means data is not being properly written to your query cache and could mean your ProxySQL instances are misconfigured, or indicate a larger problem that needs your attention.

## Ensure loads are balanced correctly 

Monitoring ProxySQL is important because, as load balancer, it is meant to evenly distribute workloads among backend servers. If a subset of your backend servers become overwhelmed with a higher volume of requests, they can become unstable and fail, which can lead to higher application latency or even downtime. You can use the `proxysql.pool.queries` metric to track the number of queries routed toward each connected backend server (identified by the tags `srv_host` and `srv_post`). You can then use a toplist (shown in the image below) to see if any backends are overtaxed, letting you know when to [reconfigure query rules](https://github.com/sysown/proxysql/wiki/ProxySQL-Configuration#mysql-query-rules) to better route traffic or whether to take other steps to troubleshoot.

![proxysql_02](https://web-assets.dd-static.net/42588/1776302158-monitor-proxysql-with-datadog-proxysql_02.png)

## Verify ProxySQL is connected to clients and servers

Because ProxySQL is a gateway between MySQL/MariaDB servers and clients, you will want to make sure it maintains its connections to both. Once you've enabled the ProxySQL integration, the Datadog Agent will start collecting both client and server connection metrics like the number of connection creations and failures per second so you can ensure ProxySQL has healthy connections and performs as expected. You can use [anomaly detection](https://docs.datadoghq.com/monitors/monitor_types/anomaly.md) to alert you to any unexpected drops or spikes in either aborted client or server connections so you can start troubleshooting immediately.

![proxysql_03](https://web-assets.dd-static.net/42588/1776302163-monitor-proxysql-with-datadog-proxysql_03.png)

## Monitor the rate of slow queries 

One critical metric to pay close attention to as you monitor ProxySQL is its rate of slow queries (`proxysql.slow_queries`) per second. Slow queries (i.e., a query that takes longer than the ProxySQL global variable [`mysql-long_query_time`](https://github.com/sysown/proxysql/wiki/Global-variables#mysql-long_query_time) to execute) can negatively affect the performance of your database and lead to excessive resource usage because ProxySQL needs more CPU and memory to execute them. You can graph the rate of slow queries in your dashboard and set up an alert to notify you if it exceeds a given threshold. If you are notified of a high rate of slow queries you can investigate, for example, by collecting [slow query logs from your MySQL backend](https://docs.datadoghq.com/integrations/mysql.md#log-collection) to see which queries you need to optimize.

## Start monitoring ProxySQL with Datadog 

Datadog's [new integration](https://docs.datadoghq.com/integrations/proxysql.md) means you can easily monitor the health and performance of your ProxySQL load balancers and ensure that queries to your backend databases are being served efficiently. In addition to the 1,000+ technologies integrated with Datadog, you can monitor ProxySQL alongside your backend database, whether you're using [MySQL or MariaDB](https://docs.datadoghq.com/integrations/mysql.md), [ClickHouse DB](https://www.datadoghq.com/blog/monitor-clickhouse.md), or [Amazon RDS](https://www.datadoghq.com/blog/postgresql-rds-monitoring-datadog.md).

If you'd like to start using Datadog, you can sign up today for a 14-day <!-- Sign-up trigger (free trial) omitted -->.