Is there any command line or php script which returns the memcached total memory usage?
Asked
Active
Viewed 4.1k times
5 Answers
41
As Mike said, you can look at the line including the "STAT bytes" to see memory usage:
$ echo "stats" | nc -w 1 <host> <port> | awk '$2 == "bytes" { print $2" "$3 }'

quanta
- 50,327
- 19
- 152
- 213
-
1Leaving that for future reference: The default host/port is: 127.0.0.1:11211 – Moritur Feb 08 '17 at 12:25
-
So just type in console: echo "stats" | nc -w 1 localhost 11211 | awk '$2 == "bytes" { print $2" "$3 }' – jobima Apr 17 '20 at 08:11
-
1More verbose `echo "stats" | nc -w 1 localhost 11211 | awk '$2 ~ "bytes" { print $2" - "$3/1024/1024 " MB" }'` – user3148949 Dec 04 '21 at 06:21
19
memcache's default port is 11211 so if memcache is local
telnet localhost 11211
Then run the stats command and that will spit out memory usage
stats

Mike
- 21,910
- 7
- 55
- 79
-
1Thanks for the telnet tip, but what should I really read in there? I see STAT bytes 9857275 STAT curr_items 43599 STAT total_items 1048925 and I have the impression that my memcached is never filling up... – Stefano Dec 06 '11 at 22:13
-
6
4
I personally use PhpMemcacheAdmin
http://code.google.com/p/phpmemcacheadmin/
It creates an easy to use GUI. Of course you'll need to have PHP support.

jaredsten
- 203
- 1
- 7
-
The site has moved to : http://blog.elijaa.org/phpmemcachedadmin-download-version-1-2-2/ – Michal Przybylowicz Aug 16 '16 at 11:34
-
2Moved again to https://github.com/wp-cloud/phpmemcacheadmin :) – vikramaditya234 Jun 04 '19 at 05:02
1
Another alternative to answer @mike,
echo "stats" | nc localhost 11211
#or
echo "stats settings" | nc localhost 11211

DarckBlezzer
- 173
- 1
- 1
- 7
0
If you are using php:
$m = new Memcached();
$m->addServer('localhost', 11211);
echo $m->getStats()['localhost:11211']['bytes'];

Eaten by a Grue
- 282
- 4
- 22