Created
September 25, 2014 23:05
-
-
Save paulomcnally/a9d4507eeef517c64a05 to your computer and use it in GitHub Desktop.
perl memcached.stats.pl [port]
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
$port=$ARGV[0]; | |
if ($port eq '') { | |
print "Message: Can't find \"port\" argument.\n"; | |
exit 1; } | |
$arg1="echo \"stats\" \| nc 192.168.59.103"; | |
$cmd1=${arg1}.' '.${port}; | |
$arg2="echo \"stats\" \| netcat 192.168.59.103"; | |
$cmd2=${arg2}.' '.${port}; | |
$cmd=${cmd1}.' || '.${cmd2}; | |
@out=`$cmd`; | |
$exit=`echo $?`; | |
if ( $exit != 0 ) | |
{ | |
print "Message: Wrong port or memcached stopped or some problems with executing \"nc\" or \"netcat\" command. \n"; | |
exit 1; | |
} | |
for ($i=0; $i<@out; $i++) { | |
if ($out[$i] =~ /threads/) { | |
@t=split(" ",$out[$i]); | |
$stat1=$t[2]; | |
} | |
if ($out[$i] =~ /curr_connections/) { | |
@t=split(" ",$out[$i]); | |
$stat2=$t[2]; | |
} | |
if ($out[$i] =~ /total_connections/) { | |
@t=split(" ",$out[$i]); | |
$stat3=$t[2]; | |
} | |
if ($out[$i] =~ /connection_structures/) { | |
@t=split(" ",$out[$i]); | |
$stat4=$t[2]; | |
} | |
if ($out[$i] =~ /curr_items/) { | |
@t=split(" ",$out[$i]); | |
$stat5=$t[2]; | |
} | |
if ($out[$i] =~ /total_items/) { | |
@t=split(" ",$out[$i]); | |
$stat6=$t[2]; | |
} | |
if ($out[$i] =~ /bytes/) { | |
@t=split(" ",$out[$i]); | |
$stat7=$t[2]; | |
} | |
if ($out[$i] =~ /limit_maxbytes/) { | |
@t=split(" ",$out[$i]); | |
$stat8=$t[2]; | |
} | |
if ($out[$i] =~ /evictions/) { | |
@t=split(" ",$out[$i]); | |
$stat9=$t[2]; | |
} | |
if ($out[$i] =~ /listen_disabled_num/) { | |
@t=split(" ",$out[$i]); | |
$stat10=$t[2]; | |
} | |
} | |
$stat8=sprintf "%.2f", $stat7/($stat8/100.0); | |
$stat7=sprintf "%.2f", $stat7/1024/1024.0; | |
print "Message.Threads: Used threads: $stat1\n"; | |
print "Statistic.Threads: $stat1\n"; | |
print "Message.Current_connections: Current connections: $stat2\n"; | |
print "Statistic.Current_connections: $stat2\n"; | |
print "Message.Total_connections: Total connections: $stat3\n"; | |
print "Statistic.Total_connections: $stat3\n"; | |
print "Message.Connection_structures: Connection structures: $stat4\n"; | |
print "Statistic.Connection_structures: $stat4\n"; | |
print "Message.Current_items: Current items: $stat5\n"; | |
print "Statistic.Current_items: $stat5\n"; | |
print "Message.Total_items: Total items: $stat6\n"; | |
print "Statistic.Total_items: $stat6\n"; | |
print "Message.Used_for_caching: Used for caching: $stat7 MB\n"; | |
print "Statistic.Used_for_caching: $stat7\n"; | |
print "Message.Cache_usage_ratio: Memcache cache usage ratio: $stat8 %\n"; | |
print "Statistic.Cache_usage_ratio: $stat8\n"; | |
print "Message.Evictions: Evictions: $stat9\n"; | |
print "Statistic.Evictions: $stat9\n"; | |
print "Message.Denied_connections: Denied connections: $stat10\n"; | |
print "Statistic.Denied_connections: $stat10\n"; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment