美文网首页
redis 服务监控

redis 服务监控

作者: 饱饱想要灵感 | 来源:发表于2023-02-06 12:01 被阅读0次

    数据统计 --stat

    --stat 可以实时获取redis的重要统计信息,虽然info命令中的统计信息更全,但是能实时看到一些增量的数据对redis的运维还是有一些帮助的

    $ redis-cli --stat
    ------- data ------ --------------------- load -------------------- - child -
    keys       mem      clients blocked requests            connections
    506        1015.00K 1       0       24 (+0)             7
    506        1015.00K 1       0       25 (+1)             7
    506        3.40M    51      0       60461 (+60436)      57
    506        3.40M    51      0       146425 (+85964)     107
    507        3.40M    51      0       233844 (+87419)     157
    507        3.40M    51      0       321715 (+87871)     207
    508        3.40M    51      0       408642 (+86927)     257
    508        3.40M    51      0       497038 (+88396)     257
    

    默认每秒打印一次数据统计, 可以用-i <interval>修改间隔

    扫描大键 -–bigkeys

    --bigkeys 使用了scan命令对redis的键进行采样,从中找到占用内存较大的键值,这些键可能是系统的瓶颈

    $ redis-cli --bigkeys
    
    # Scanning the entire keyspace to find biggest keys as well as
    # average sizes per key type.  You can use -i 0.1 to sleep 0.1 sec
    # per 100 SCAN commands (not usually needed).
    
    [00.00%] Biggest string found so far 'key-419' with 3 bytes
    [05.14%] Biggest list   found so far 'mylist' with 100004 items
    [35.77%] Biggest string found so far 'counter:__rand_int__' with 6 bytes
    [73.91%] Biggest hash   found so far 'myobject' with 3 fields
    
    -------- summary -------
    
    Sampled 506 keys in the keyspace!
    Total key length in bytes is 3452 (avg len 6.82)
    
    Biggest string found 'counter:__rand_int__' has 6 bytes
    Biggest   list found 'mylist' has 100004 items
    Biggest   hash found 'myobject' has 3 fields
    
    504 strings with 1403 bytes (99.60% of keys, avg size 2.78)
    1 lists with 100004 items (00.20% of keys, avg size 100004.00)
    0 sets with 0 members (00.00% of keys, avg size 0.00)
    1 hashs with 3 fields (00.20% of keys, avg size 3.00)
    0 zsets with 0 members (00.00% of keys, avg size 0.00)
    

    监控延迟情况 -–latency

    例子:

    [root@Redis ~]# redis-cli --latency
    min: 0, max: 1, avg: 0.07 (824 samples)
    

    --latency-history

    –latency的执行结果只有一条,如果想以分时段的形式了解延迟信息,可以使用 --latency-history 选项:

    $ redis-cli -h 127.0.0.1 -p 6379 --latency-history
    min: 0, max: 2, avg: 0.27 (1301 samples) -- 15.01 seconds range
    min: 0, max: 2, avg: 0.27 (1301 samples) -- 15.00 seconds range
    .
    .
    .
    min: 0, max: 1, avg: 0.28 (1308 samples) -- 15.00 seconds range
    

    默认每15秒输出一次,可以通过参数 -i(单位秒) 控制时间间隔,比如:

    $ redis-cli -h 127.0.0.1 -p 6379 --latency-history -i 1
    min: 0, max: 1, avg: 0.27 (92 samples) -- 1.00 seconds range
    min: 0, max: 1, avg: 0.23 (91 samples) -- 1.00 seconds range
    

    --latency-dist

    --latency-dist选项会使用统计图表的形式从控制台输出延迟统计信息

    $ redis-cli --latency-dist
    

    rdb文件远程备份 –-rdb

    获取指定redis实例的rdb文件,保存到本地。

    $ redis-cli --rdb /tmp/dump.rdb
    SYNC sent to master, writing 13256 bytes to '/tmp/dump.rdb'
    Transfer finished with success.
    

    监视Redis执行的命令 monitor

    $ redis-cli monitor
    OK
    1460100081.165665 [0 127.0.0.1:51706] "set" "foo" "bar"
    1460100083.053365 [0 127.0.0.1:51707] "get" "foo"
    

    monitor可以使用管道传递输出,我们能使用诸如grep之类的工具监视特定的模式。

    模拟从机模式 --slave

    --slave是把当前客户端模拟成当前redis节点的从节点,可以用来获当前redis节点的更新操作

    合理的利用这个选项可以记录当前连接Redis节点的更新操作,这些更新操作可能是实际开发业务时需要的数据。

    第一个客户端使用–slave选项,可以看到它会一直处于等待状态:

    [root@Redis ~]# redis-cli --slave
    SYNC with master, discarding 1765 bytes of bulk transfer...
    SYNC done. Logging commands from master.
    "PING"
    

    当另一台客户端进行一些数据操作时:

    127.0.0.1:6379> set baobao good
    OK
    127.0.0.1:6379> del baobao
    (integer) 1
    

    设置–-slave选项的客户端会出现这些操作的指示:

    [root@Redis ~]# redis-cli --slave
    SYNC with master, discarding 1765 bytes of bulk transfer...
    SYNC done. Logging commands from master.
    "PING"
    "PING"
    "PING"
    "PING"
    "PING"
    "SELECT","0"
    "set","baobao","good"
    "PING"
    "PING"
    "del","baobao"
    

    相关文章

      网友评论

          本文标题:redis 服务监控

          本文链接:https://www.haomeiwen.com/subject/qaltkdtx.html