InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Bash shell scripting

  • Bash - add a number to a variable
  • Bash - append text to a variable
  • Bash - how to check if a variable is set
  • Bash - how to compare file timestamps
  • Bash - how to find last command exit status code
  • Bash - how to get main program and current file dir location
  • Bash - how to redirect stderr to stdout or file
  • Bash - how to run custom commands at script exit
  • Bash - how to stop at error
  • Bash - how to use functions - quick tutorial
  • Bash - iterate over array
  • Bash - local and global variables
  • Bash - newline and other escape character in string
  • Bash - pass all arguments from one script to another
  • Bash - set default value if a variable is empty
  • Bash - variables in double quotes vs without quotes
  • Bash associative array tutorial
  • Bash check if file begins with a string
  • Bash shell - check if file or directory exists
  • Can global variables be modified in bash function?
  • Find memcache request hit rate on linux command line
  • How to return a value from bash function
  • Iterate over specific file extension in a dir in shell script
  • Linux - Yesterday's Date in YYYYMMDD format
  • bash - extract urls from xml sitemap
  • bash - how to use regex in if condition
 
  • Home
  • > Tutorials
  • > Bash shell scripting

Find memcache request hit rate on linux command line

By admin | Last updated on Mar 20, 2016

Memcached gives you stats like total hits so far and total miss. It can also tell you total uptime. This can be used to find total hit rate (request, hit and miss) since the start time of the memcached. Here are quick instruction to find memcache hit rate (since beginning or last 1 min) on Ubuntu Linux. I’m using memcached version 1.4.14 for the purpose of this article.

Total hit rate since beginning

To find total hit rate since beginning, save the following bash script to a file rate.sh and then run it.

#!/bin/bash
STATS=$(printf "stats\n" | nc localhost 11211)
gethits1=$(echo "$STATS" | grep "get_hits" | cut -d" " -f3 | tr -d '\n')
uptime1=$(echo "$STATS" | grep "uptime" | cut -d" " -f3)
hitratesincebeginning=$(echo "$gethits1 $uptime1" | awk '{printf "%.2f", ($1/$2)}')
echo "$hitratesincebeginning"

Here is how the output will look like:

0.26

Recent hit rate

To find the recent hit rate, we can use the same approach but we find the total hits for an interval of say 1 min. Then we can easily find the hit rate for that interval.

Here is the bash script we can use for this.

#!/bin/bash
STATS=$(printf "stats\n" | nc localhost 11211)
gethits1=$(echo "$STATS" | grep "get_hits" | cut -d" " -f3 | tr -d '\n')
uptime1=$(echo "$STATS" | grep "uptime" | cut -d" " -f3)
hitratesincebeginning=$(echo "$gethits1 $uptime1" | awk '{printf "%.2f", ($1/$2)}')
echo "$hitratesincebeginning"

sleep 60
STATS=$(printf "stats\n" | nc localhost 11211)
gethits2=$(echo "$STATS" | grep "get_hits" | cut -d" " -f3 | tr -d '\n')
uptime2=$(echo "$STATS" | grep "uptime" | cut -d" " -f3)
hitraterecent=$(echo "$gethits1 $uptime1 $gethits2 $uptime2" | awk '{printf "%.2f", (($3-$1)/($4-$2))}')
echo "$hitraterecent"

Here is how the output will look like:

0.26
2.00

This tells us that memcache has received avg 0.26 hit req/s since it was started and in last minute it received 2.00 hit req/s. The same approach can be used to find miss rate and overall requests (hit+miss) rate also.

Suggested posts:

  1. How to specify environment variable for a command on Linux
  2. Curl with download/upload rate limit – code snippets
  3. Command line – top IP list from apache access log
  4. Memcache – how to dump all keys and values on command line
  5. Custom terminal tab title and ssh on mac
  6. Using JSLint on command line on Ubuntu linux – quick start guide
  7. How to find mysql query rate on Linux
  8. How to install and monitor memcache for php on Ubuntu Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Bash shell scripting, Memcache, Tutorials

Follow InfoHeap

facebook
twitter
googleplus
  • Browse site
  • Article Topics
  • Article archives
  • Recent Articles
  • Contact Us
  • Omoney
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

Copyright © 2023 InfoHeap.

Powered by WordPress