Monitoring memcached with plink
- by kojiro
I need a telnet client that can take commands from a file or stdin so I can do some quick-and-dirty automatic monitoring of memcached. I thought plink would be good for this, but it seems to be doing something beyond what I need:
If I telnet into localhost 11211 and write stats, I get the memcached stats, like so:
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
stats
STAT pid 25099
STAT uptime 91182
STAT time 1349191864
STAT version 1.4.5
STAT pointer_size 64
STAT rusage_user 3.570000
STAT rusage_system 2.740000
STAT curr_connections 5
STAT total_connections 23
STAT connection_structures 11
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 82184
STAT bytes_written 7210
STAT limit_maxbytes 67108864
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
But with plink, I get an odd error. I'm using this command:
watch -n 30 plink -v -telnet -P 11211 127.0.0.1 <<< $'\nstats'
The first time through I get:
Looking up host "127.0.0.1"
Connecting to 127.0.0.1 port 11211
client: WILL NAWS
client: WILL TSPEED
client: WILL TTYPE
client: WILL NEW_ENVIRON
client: DO ECHO
client: WILL SGA
client: DO SGA
ERROR
STAT pid 25099
STAT uptime 91245
STAT time 1349191927
STAT version 1.4.5
…
END
But when watch repeats the command I just get:
Looking up host "127.0.0.1"
Connecting to 127.0.0.1 port 11211
client: WILL NAWS
client: WILL TSPEED
client: WILL TTYPE
client: WILL NEW_ENVIRON
client: DO ECHO
client: WILL SGA
client: DO SGA
Failed to connect to 127.0.0.1: Connection reset by peer
Connection reset by peer
FATAL ERROR: Connection reset by peer
What is plink doing here that is different from normal telnet? How should I be going about this? (I'm not married to plink, but I need a way to continuously send simple telnet commands to memcached without writing a full-fledged perl script.)