memcache.php stats like apc.php

by Harun Yayli on Wednesday, May 21st, 2008 at 5:15 pm under Memcached, PHP, Programming

For a long time I was looking for a nice web interface like the apc.php (comes with the apc’s source) that displays whole nine yards of stats. The only good tool is memcache-tool from the danga guys. It’s quite complete but I guess I’m too lazy to go on the command line.

Anyways, I decided to rip write my own. Totally based on the original apc.php (I even recycled some functions) and apart from completeness, here is a memcache.php that you can get stats and dump from multiple memcache servers.
Here is a screenshot:


And here is the the source code.

As usual, this piece of software comes with the warnings:
- Don’t expect something complete, might have bugs and security problems etc.
- Do not install on a prod environment unless you’re sure!
- Feel free to add stuff to it, I’ll put it to google code or sf.net soon.
- Feel free to request features. (no I’m not planning a backup tool , there is memcache-tool for that)
- Enjoy!

Update: Small parse error is fixed

Recent Entries

51 Responses to “memcache.php stats like apc.php”

  1. James McGlinn Says:

    That’s very useful, thanks for publishing it.

    By the way you have an extra comma (,) in the source code around line 486.

  2. Vinu Thomas Says:

    Hey Harun,
    Just a small problem with the code – it throws an error while running. The comma on line 486 has to be a semi-colon. Changing that fixes the problem.

    Cool Script btw !

  3. Lukas Says:

    Have you talked to the pecl/memcache maintainers to get this script included into the package just like with pecl/apc?

  4. Jason Says:

    Nice script!

    There is a parse error on line 488, “menu_entry(2,’Variables’), ” should be “menu_entry(2,’Variables’);”

  5. daniel Says:

    Hi, this is pretty cool, thanks for sharing!
    regards, dz

  6. Glen Says:

    Do you know of anything like this for Postgres?

  7. Harun Yayli Says:

    @James McGlinn, @Vinu Thomas, @Jason,
    Thanks for noticing, parse error should be fixed now.

  8. Harun Yayli Says:

    @Lukas
    Good idea. I’ll contact them to contribute the code to the pecl/memcache.

  9. Harun Yayli Says:

    @Glen
    Hmm.. No I’m not a Postres user at all.

  10. Trophaeum Says:

    No chance for a txt/tarball download? Pasting a phps file is always so ugly :(

  11. Harun Yayli Says:

    @Trophaeum
    Done :)

  12. Glen Says:

    What about a mysql version then?

  13. Harun Yayli Says:

    @Glen
    There are way too many tools for mysql. Mysql Administrator is really great too (http://www.mysql.com/products/tools/administrator/). I don’t really have a good idea that is not covered by MysqlAdministrator.

  14. Michael Says:

    Awesome script. Thanks so much.

  15. Michael Says:

    BTW, I made one small change to the codebase
    I changed this line:
    Header(“WWW-Authenticate: Basic realm=\”APC Login\”");

    to this:
    Header(“WWW-Authenticate: Basic realm=\”Memcache Login\”");

    I actually have APC devices in my network and thought it was a little confusing. Anyway thanks so much. This is much easier to keep dibs on my memory servers than using the command line all the time.

  16. Michael Gauthier Says:

    Thanks,

    I’ve added a flush cache link, fixed the ‘evicted’ text and made HTTP auth optional. Where do I send the patch?

  17. Harun Yayli Says:

    @michael.

    Thank you. I’ve recently corrected those too.
    You can contact me by email. see the About page.

  18. steve Says:

    great script. perfect for keeping an eye on memcached!

  19. Meskalyn Says:

    Thanks for this script. Very usefull to check all of our memcache servers…

  20. Patryk Says:

    Could you please include this line into HTML code? Thanks.

  21. Patryk Says:

    Hm… where did the code it go? Nvm. Here’s a pastebin link:
    http://pastebin.ca/1203462

  22. Matthew Says:

    thank u r information

    it very useful

  23. Chad Says:

    How do you use this? I uploaded it, went to the page and it asks for a username/password.

  24. Unseen Says:

    What does “hits & misses” mean?

  25. kris Says:

    im kind of a novice.. can anybody tell me how to installl it on my server?

  26. Ryan Says:

    Shouldn’t the default screen Hit Rate reflect the total of all the memcached servers? If you have server1 with a hit rate of 50 requests per second and server2 with a hit rate of 100 requests per second, should the total be 150 requests per second instead of the average of 75 (which seems to be what your scritp is doing)?

  27. Dawid W?gli?ski Says:

    Much thanks for this script!

  28. askwan Says:

    cool! useful!
    thank’s !

  29. Gustavo Says:

    Hello, Memcache running and hearing default port 11211, not a firewall issue also, but I’m receiving a Cant connect to:mymemcache-server1:11211
    Gracias
    Gustavo

  30. Nightfly Says:

    Perfect! Thanks!

  31. Blu Says:

    I have memcache running on localhost (Windows XP box) and provide Admin login and password, I still get

    Rejected!

    Wrong Username or Password!

    I tried running memcached with -u – that didn’t help either…

  32. Jagat Says:

    Thanks A Lot For Sharing. Great Tool.

  33. tanaydin Says:

    hi there… there is a bug about gziped values… they shown as binary chars…

  34. Aaron Jackson Says:

    Thanks very much, this is just what I was looking for

  35. Matthew Clark Says:

    It ould be nice to implement server display names.

    For exaple, instead of:
    $MEMCACHE_SERVERS[] = array(‘server:port’)

    How about
    $MEMCACHE_SERVERS[] = array(‘server:port’, ‘Nisplay Name’)

    Also, it seems the pie chart doesn’t render correctly; I have six memcached instances running, and if the total use is, say, 2MB out of a total 256MB, the pie chart shows 99.9% usage (all orange) but the text stats are correct.

    Otherwise, very nice, clean tool! Good job!

  36. Matthew Clark Says:

    Woops, my last comment contained a typo. I meant this:

    For exaple, instead of:
    $MEMCACHE_SERVERS[] = ‘server:port’

    How about
    $MEMCACHE_SERVERS[] = array(‘server:port’, ‘Display Name’)

  37. dkblinux98 Says:

    Thanks for the tool. It was just what I needed after a new memcached implementation.

  38. Sitekeeper Says:

    Great tool, keep up the good work..

  39. Tomas Says:

    Awesome! Just what I was looking for.
    Many Thanks!!

  40. Frank Says:

    Can it also show the memcached version, just like the PHP version you already, it’s a nice debug fact

  41. zhuli Says:

    it is a good job!
    i like this tool!

  42. asb Says:

    Adding multiple memcached instances as an array does not work. Neither

    $MEMCACHE_SERVERS[] = array(
    “localhost:11211″,
    “localhost:11212″,
    “localhost:11213″,
    “localhost:11214″,
    “localhost:11215″,
    “localhost:11216″,
    “localhost:11217″,
    “localhost:11218″,
    “localhost:11219″,
    );

    nor

    $MEMCACHE_SERVERS[] = array(
    ‘localhost:11211′,
    ‘localhost:11212′,
    ‘localhost:11213′,
    ‘localhost:11214′,
    ‘localhost:11215′,
    ‘localhost:11216′,
    ‘localhost:11217′,
    ‘localhost:11218′,
    ‘localhost:11219′,
    );

    results i useful output. Message on memcache.php:

    “Cant connect to:Array:”

  43. Redakteur Says:

    Thanks, very helpful. I used a small function to make it work with unix sockets.

    function gethostport($server) {
    if(strpos($server, ‘unix:/’)===0){
    $host = $server;
    $port = 0;
    }
    else{
    $strs = explode(‘:’,$server);
    $host = $strs[0];
    $port = $strs[1];
    }
    return array($host, $port);
    }

  44. Alex F Says:

    Thanks for this! It was tough to find a memcached monitor.

  45. Wein-Bertram Says:

    Thanks for sharing, will implement it tonight – this memcache.php is exactly what I was looking for.
    Cheers Bertram

  46. Patrick Says:

    Awesome script – saves me a whoooooooole lot of leg work! Great job!

  47. Atoms Says:

    Publish code to github, it will be easy to stay tuned for updates also for forks…

  48. FGM Says:

    Hello,

    Thank you for this tool I’m using often. I have done some changes to improve readability of the slab dumb, but since comments are not allowed, I’ve posted them on my git server: http://git.osinet.eu/gitweb?p=tools/memcache_ui.gi

  49. FGM Says:

    Hello,

    Thank you for this tool I’m using often. I have done some changes to improve readability of the slab dumb, but since comments are not allowed to have attachments, I’ve posted them on my git server: http://git.osinet.eu/gitweb?p=tools/memcache_ui.git

  50. flo Says:

    Thank you very much.

    @Redakteur: Great job, I use the the socket as well and it is working fine.

  51. jorge Says:

    Wwow, excellent tool!, thank you so much =D.
    I’m using it, and is very helpful, thanks =D
    The best wishes for you =)

Leave a Reply

authimage