TheRobotLearns Platform · ProxySQL: from first install to production
Reading Monitor Statistics and Logs to Diagnose Backend Issues
Learning objectives
- Inspect DNS cache settings in global_variables using monitor DNS variable names.
- Query stats_mysql_global for MySQL_Monitor_dns_cache_queried, MySQL_Monitor_dns_cache_lookup_success, and MySQL_Monitor_dns_cache_record_updated.
- Interpret DNS cache metrics as query, cache-hit, and record-update counts.
- Explain that monitor tables are append-only logs and retention follows monitor history settings.
- Use success_time_us and error fields to distinguish successful from failed monitor checks.
- Interpret success_time_us zero as failure and NULL error as success in monitor checks.
Find DNS settings that control lookups
Historically, ProxySQL performed a DNS lookup for each client connection. A DNS lookup is blocking, and performance suffers when the DNS server is slow or misconfigured.
ProxySQL can cache DNS records and reuse them. That avoids a new lookup for each client connection for a given host. The DNS cache behaviour is controlled by variables whose names start with mysql-monitor_local_dns_. You can read those rows from global_variables.
This query lists the variables and their current values:
SELECT * FROM global_variables
WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';By default, DNS caching is enabled with these values: mysql-monitor_local_dns_cache_ttl 300000 ms, mysql-monitor_local_dns_cache_refresh_interval 60000 ms, and mysql-monitor_local_dns_resolver_queue_maxsize 128. The TTL value is the expiry time for each cached DNS record. The refresh interval controls how often monitor DNS cache entries, mysql_servers, and proxysql_servers are re-checked for new records. The resolver queue limit controls how much the DNS resolver queue can grow before starting new monitoring helper threads, up to 32 threads.
Takeaway: Read global_variables with mysql-monitor_local_dns_% to see the TTL, refresh interval, and resolver queue size.
Query the three DNS cache counters
A domain contains multiple mapped IPs, and ProxySQL balances load among them in a round-robin fashion on socket connection. DNS cache metrics are available through the stats_mysql_global table.
You can query the counters with a Variable_Name LIKE 'MySQL_Monitor_dns_cache_%' filter.
This query returns the DNS cache counters:
SELECT * FROM stats_mysql_global
WHERE Variable_Name LIKE 'MySQL_Monitor_dns_cache_%';The query returns three rows. MySQL_Monitor_dns_cache_queried is the count of times the DNS cache has been queried. MySQL_Monitor_dns_cache_lookup_success is the count of times a DNS record was found in the DNS cache on lookup. That finding is a cache hit. MySQL_Monitor_dns_cache_record_updated is the count of times DNS records were updated, added, removed, or modified.
The example values are 65, 60, and 30. Those values represent counts of times each action happened.
DNS records are checked after every refresh interval. Expired records are refreshed by issuing a DNS query. Cached records are also checked when mysql_servers and proxysql_servers are updated. If a domain contains multiple mapped IPs, ProxySQL balances load among them in a round-robin fashion on socket connection.
Takeaway: stats_mysql_global returns query, cache-hit, and record-update counts for DNS cache behaviour.
Interpret query, hit, and update counts
The example query returns DNS cache rows from stats_mysql_global: MySQL_Monitor_dns_cache_queried, MySQL_Monitor_dns_cache_lookup_success, and MySQL_Monitor_dns_cache_record_updated. These DNS cache counters represent times the DNS cache has been queried, times a DNS record was found in the DNS cache on lookup (cache hit), and times DNS records were updated (added, removed, or modified).
With the example values 65, 60, and 30, that means 65 DNS cache queries, 60 cache hits, and 30 record updates, where record updates include additions, removals, or modifications. The name gives the action, and the value gives the count for that action.
The related configuration variables in global_variables describe DNS cache behaviour:
mysql-monitor_local_dns_cache_ttlsets the TTL expiry time for each cached DNS record.mysql-monitor_local_dns_cache_refresh_intervalsets the interval at which monitor DNS cache entries,mysql_servers, andproxysql_serversare re-checked for new records.mysql-monitor_local_dns_resolver_queue_maxsizecontrols how much the DNS resolver queue can grow before starting new monitoring helper threads, up to 32 threads.
Setting mysql-monitor_local_dns_cache_ttl or mysql-monitor_local_dns_cache_refresh_interval to '0' disables DNS caching.
Takeaway: Read the metric name for the action, then read its value as the count of times that action happened.
Watch zero values that disable caching
DNS caching is available since ProxySQL 2.4.5. It stores DNS records locally and reuses them, so ProxySQL does not need a new DNS query for each client connection for a given host. Every DNS record has a time-to-live, and TTL specifies the expiry time of the record.
mysql-monitor_local_dns_cache_ttl and mysql-monitor_local_dns_cache_refresh_interval hold millisecond values. The default values are 300000 and 60000. The TTL value is the expiry time for each cached DNS record. The refresh interval controls how often monitor DNS cache entries, mysql_servers, and proxysql_servers are re-checked for new records.
DNS records are checked after every refresh interval. Expired records are refreshed by issuing a DNS query. Cached records are also checked when mysql_servers and proxysql_servers are updated. Setting either mysql-monitor_local_dns_cache_ttl or mysql-monitor_local_dns_cache_refresh_interval to '0' disables the DNS caching feature.
mysql-monitor_local_dns_resolver_queue_maxsize is different from the TTL and refresh interval. It determines how much the DNS resolver queue can grow before starting new monitoring helper threads, up to 32 threads. If a domain contains multiple mapped IPs, ProxySQL balances load among them in a round-robin fashion on socket connection.
Takeaway: A TTL or refresh value of '0' disables DNS caching in global_variables.
Check DNS cache settings and counters
SELECT * FROM global_variables
WHERE Variable_Name LIKE 'mysql-monitor_local_dns_%';
SELECT * FROM stats_mysql_global
WHERE Variable_Name LIKE 'MySQL_Monitor_dns_cache_%';The first query reads rows from global_variables where Variable_Name matches mysql-monitor_local_dns_%. You will see mysql-monitor_local_dns_cache_ttl, mysql-monitor_local_dns_cache_refresh_interval, and mysql-monitor_local_dns_resolver_queue_maxsize. The second query reads rows from stats_mysql_global where Variable_Name matches MySQL_Monitor_dns_cache_%. You will see MySQL_Monitor_dns_cache_queried, MySQL_Monitor_dns_cache_lookup_success, and MySQL_Monitor_dns_cache_record_updated.
Try it: config_layer_sim
Run the global_variables query with mysql-monitor_local_dns_%. Note the TTL, refresh interval, and resolver queue values. Run the stats_mysql_global query with MySQL_Monitor_dns_cache_%. Match queried to cache queries, lookup_success to cache hits, and record_updated to record updates.
Sources
Do more with an account
- Graded quizzes is available on your account.
- Saving your progress is available on your account.
- Hands-on labs is available on your account.
- AI tutoring is available on your account.