Memcached 统计(stats)

  • Telnet stats

    Memcached stats命令用于返回服务器统计信息,例如PID,版本,连接等。
    Memcached stats命令的基本语法如下所示-
    
    stats
    
    
    stats
    STAT pid 1120
    STAT uptime 15316
    STAT time 1605073360
    STAT version 1.4.15
    STAT libevent 2.0.21-stable
    STAT pointer_size 64
    STAT rusage_user 0.086050
    STAT rusage_system 0.172100
    STAT curr_connections 10
    STAT total_connections 11
    STAT connection_structures 11
    STAT reserved_fds 20
    STAT cmd_get 0
    STAT cmd_set 2
    STAT cmd_flush 0
    STAT cmd_touch 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 touch_hits 0
    STAT touch_misses 0
    STAT auth_cmds 0
    STAT auth_errors 0
    STAT bytes_read 93
    STAT bytes_written 48
    STAT limit_maxbytes 67108864
    STAT accepting_conns 1
    STAT listen_disabled_num 0
    STAT threads 4
    STAT conn_yields 0
    STAT hash_power_level 16
    STAT hash_bytes 524288
    STAT hash_is_expanding 0
    STAT bytes 77
    STAT curr_items 1
    STAT total_items 1
    STAT expired_unfetched 0
    STAT evicted_unfetched 0
    STAT evictions 0
    STAT reclaimed 0
    END
    
  • Java应用程序使用stats

    要从Memcached服务器获取统计信息,您需要使用Memcached getStats方法。
    
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import net.spy.memcached.MemcachedClient;
    
    public class MemcachedJava {
       public static void main(String[] args) {
    
          // Connecting to Memcached server on localhost
          MemcachedClient mcc = null;
          try {
             mcc = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
          } catch (IOException e) {
             // TODO 自动生成的 catch 块
             e.printStackTrace();
          }
          System.out.println("Connection to server sucessfully");
    
          System.out.println(mcc.getStats());
       }
    }
    
    在编译和执行程序时,您将看到以下输出-
    
    Connection to server sucessfully 
    {/127.0.0.1:11211={incr_hits=2, get_hits=20, delete_hits=1, evictions=0, pid=9920, cas_badval=0, curr_connections=22, cmd_flush=0, total_items=15, bytes_written=1569, cas_hits=1, accepting_conns=1, auth_errors=0, decr_hits=2, limit_maxbytes=67108864, decr_misses=0, reclaimed=3, cmd_get=21, curr_items=1, threads=4, cmd_set=16, bytes_read=856, conn_yields=0, version=1.4.5_4_gaa7839e, uptime=16345, listen_disabled_num=0, total_connections=25, get_misses=1, incr_misses=0, connection_structures=23, bytes=56, time=1605073576, auth_cmds=0, pointer_size=32, cas_misses=0, delete_misses=0}}