Last active
October 11, 2019 19:11
Star
You must be signed in to star a gist
quick 1-time script to parse pdns_recursor cache hit ratio and qps across a range of hosts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# Usage: | |
# | |
# $ ruby pdns-recursor-cache-stats.rb | |
# | |
# Might need to use sudo or run as root to access the pdns_recursor control socket | |
# | |
uptime = 0 | |
cache_hits = 0 | |
cache_misses = 0 | |
packetcache_hits = 0 | |
packetcache_misses = 0 | |
#ARGF.each_line do |l| | |
%x(rec_control get-all).each_line do |l| | |
key, val = l.split(/\s+/) | |
uptime = val.to_i if key == 'uptime' | |
cache_hits = val.to_i if key == 'cache-hits' | |
cache_misses = val.to_i if key == 'cache-misses' | |
packetcache_hits = val.to_i if key == 'packetcache-hits' | |
packetcache_misses = val.to_i if key == 'packetcache-misses' | |
end | |
hostname = %x(hostname).chomp | |
# calculate total cache hit ratio | |
total_cache_hits = (cache_hits + packetcache_hits) | |
total_cache_misses = (cache_misses + packetcache_misses) | |
total_queries = (total_cache_hits + total_cache_misses) | |
cache_hit_ratio = (total_cache_hits.to_f / total_queries) * 100 | |
#puts format('cache-hit-ratio: %.1f%%', cache_hit_ratio) | |
# calculate average queries per second | |
avg_qps = (total_queries.to_f / uptime.to_f) | |
#puts format('avg-qps: %.2f', avg_qps) | |
# CSV out; HOSTNAME,CACHE_HIT_PERCENTAGE,AVG_QPS | |
puts format('%s,%.1f,%.2f', hostname, cache_hit_ratio, avg_qps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment