Finding cache hit ratio

What is your cache hit ratio. This is a simple bash script to see your cache hit ratio.

  1. Data caches that hold often-referenced application data.
  2. Code caches that retain often-executed SQL or procedural code.
  3. Metadata caches that keep reference data such as object structure information, security information, and more.
#!/bin/bash
user=<username>
pass=<password>
SOCKET=$1

while [ 1 ] ; do
READ_REQ=$( mysql -u$user -p$pass -S ${SOCKET} -NBe "SHOW GLOBAL STATUS LIKE 'Key_read_requests'" | awk '{print $2}' )
READS=$( mysql -u$user -p$pass -S ${SOCKET} -NBe "SHOW GLOBAL STATUS LIKE 'Key_reads'" | awk '{print $2}' )
TOTAL=$( echo "${READ_REQ} + ${READS}" | bc )
HIT_RATIO=$( echo "scale=6; ( ${READS} / ${TOTAL}) * 100" | bc -l )
MISS_RATIO=$( echo "scale=6; ( ${READ_REQ} / ${TOTAL}) * 100" | bc -l )
echo "Total Requests: ${TOTAL} - Key Hits: ${HIT_RATIO} - Key Misses: ${MISS_RATIO}"
sleep 1;
done

Example Output:
Total Requests: 12257352 – Key Hits: 7.696400 – Key Misses: 92.303500
Total Requests: 12270080 – Key Hits: 7.691600 – Key Misses: 92.308300
Total Requests: 12283029 – Key Hits: 7.686000 – Key Misses: 92.313900
Total Requests: 12283031 – Key Hits: 7.686000 – Key Misses: 92.313900
Total Requests: 12297598 – Key Hits: 7.680100 – Key Misses: 92.319800
Total Requests: 12316584 – Key Hits: 7.671900 – Key Misses: 92.328000
Total Requests: 12344366 – Key Hits: 7.658700 – Key Misses: 92.341200
Total Requests: 12359157 – Key Hits: 7.652800 – Key Misses: 92.347100

VN:F [1.8.4_1055]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)
You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.

Twitter Delicious Facebook Digg Stumbleupon Favorites More
Designed by: MySQL How 2

Switch to our mobile site