Created
April 30, 2014 10:40
-
-
Save rgs/f24d46abebd61a99b91e to your computer and use it in GitHub Desktop.
A perl function to get the amount of wasted memory on a memcached server
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
sub wasted_memory { | |
my ($host, $port) = @_; | |
my @slabstats = `echo stats slabs | nc $host $port`; | |
my %perslab; | |
my $total_malloced = 0; | |
my $total_wasted = 0; | |
for (@slabstats) { | |
if (/STAT total_malloced ([0-9]+)/) { | |
$total_malloced = $1; | |
next; | |
} | |
/STAT ([0-9]+):(\w+) ([0-9]+)/ or next; | |
$perslab{$1}{$2} = $3; | |
} | |
for my $slabnum (keys %perslab) { | |
$total_wasted += $perslab{$slabnum}{wasted} = ( $perslab{$slabnum}{total_chunks} * $perslab{$slabnum}{chunk_size} ) - $perslab{$slabnum}{mem_requested}; | |
} | |
return ($total_malloced, $total_wasted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment