redis效能監控工具redis-stat安裝初探

chenfeng發表於2018-05-29
redis-stat是一個用Ruby寫成的,用於對Redis進行效能監控的工具,可以以web方式進行圖形展示。

安裝步驟:

一.準備軟體和要求:
redis-stat安裝系統要求ruby版本必須大於1.9.2,否則會報錯,推薦原始碼方式安裝ruby2.2.7版本


下載ruby 2.2.7
# wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.7.tar.gz


解壓:
#tar zxvf ruby-2.2.7.tar.gz -C /root/ruby


編譯安裝:
#cd /root/ruby/ruby-2.2.7
#./configure
#make
#make install
[root@test bin]# which ruby
/usr/local/bin/ruby
[root@test bin]# ruby -v
ruby 2.2.7p470 (2017-03-28 revision 58194) [x86_64-linux]


gem版本:
#gem -v
[root@test ruby-2.2.7]# gem -v
2.4.5.2


二.安裝redis-stat:
#cd /home/
需要安裝git工具:
#yum install git  
#git clone https://github.com/junegunn/redis-stat.git
#cd /home/redis-stat/bin
#./redis-stat --help
#有個報錯,no such file to load -- redis-stat (LoadError),需要用gem安裝
#gem install redis-stat


安裝完後執行依然報錯:
[root@test bin]# ./redis-stat 
/usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- readline (LoadError)
        from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from /usr/local/lib/ruby/gems/2.2.0/gems/redis-stat-0.4.14/lib/redis-stat.rb:17:in `'
        from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `require'
        from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in `rescue in require'
        from /usr/local/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in `require'
        from ./redis-stat:4:in `'
[root@test bin]# 
需要安裝rb-readline
[root@test bin]# gem install rb-readline
Fetching: rb-readline-0.5.5.gem (100%)
Successfully installed rb-readline-0.5.5
Parsing documentation for rb-readline-0.5.5
Installing ri documentation for rb-readline-0.5.5
Done installing documentation for rb-readline after 3 seconds
1 gem installed


再次執行後命令正常:
[root@test bin]# ./redis-stat --help
usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]


    -a, --auth=PASSWORD              Password
    -v, --verbose                    Show more info
        --style=STYLE                Output style: unicode|ascii
        --no-color                   Suppress ANSI color codes
        --csv[=CSV_FILE]             Print or save the result in CSV
        --es=ELASTICSEARCH_URL       Send results to ElasticSearch: [http://]HOST[:PORT][/INDEX]


        --server[=PORT]              Launch redis-stat web server (default port: 63790)
        --daemon                     Daemonize redis-stat. Must be used with --server option.


        --version                    Show version
        --help                       Show this message

幫助資訊解釋如下:
-a, --auth=PASSWORD                 設定密碼
    -v, --verbose                   顯示更多資訊
        --style=STYLE               輸出編碼型別: unicode|ascii
        --no-color                  取消ANSI顏色編碼
        --csv=OUTPUT_CSV_FILE_PATH  以CSV格式儲存結果
        --es=ELASTICSEARCH_URL      把結果傳送到 ElasticSearch: [http://]HOST[:PORT][/INDEX]
        --server[=PORT]             執行redis-stat的web server (預設埠號: 63790),可以自己指定埠啟動
        --daemon                    使得redis-stat成為程式。必須使用 --server 選項      
        --version                   顯示版本號
        --help                      顯示幫助資訊




監控例項執行一例:
[root@test bin]# ./redis-stat 10.10.13.189 6379 1 10 --verbose
┌────────────────────────┬──────────────┐
│                        │ 10.10.13.189 │
├────────────────────────┼──────────────┤
│          redis_version │        4.0.2 │
│             redis_mode │   standalone │
│             process_id │        13270 │
│      uptime_in_seconds │     19379512 │
│         uptime_in_days │          224 │
│                   role │       master │
│       connected_slaves │            0 │
│            aof_enabled │            0 │
│ rdb_bgsave_in_progress │            0 │
│     rdb_last_save_time │   1508202924 │
└────────────────────────┴──────────────┘


┌────────┬──┬──┬──┬───┬─────┬──────┬──────┬────┬────┬─────┬─────┬─────┬────┬─────┬───┬──────┬─────┬────┬─────┬────┬─────┬─────┬─────┬────┬───┐
     time us sy cl bcl rej/s    mem    rss frag keys cmd/s   cmd exp/s  exp evt/s evt hit%/s hit/s  hit mis/s  mis aofcs aofbs  chsv psch psp 
├────────┼──┼──┼──┼───┼─────┼──────┼──────┼────┼────┼─────┼─────┼─────┼────┼─────┼───┼──────┼─────┼────┼─────┼────┼─────┼─────┼─────┼────┼───┤
 16:27:16  -  - 13   0     - 1.63GB 1.79GB 1.10  520     - 2.85G     - 317k     -   0      -     - 941M     - 552k    0B    0B 6.02M    1   0 
└────────┴──┴──┴──┴───┴─────┴──────┴──────┴────┴────┴─────┴─────┴─────┴────┴─────┴───┴──────┴─────┴────┴─────┴────┴─────┴─────┴─────┴────┴───┘
Elapsed: 0.12 sec.




[root@test bin]# ./redis-stat --verbose --server=8090 5 10.10.13.189:6379 10.10.13.190:6379 &
[1] 29049


備註:設定--server=8090後,redis-stat會在後臺啟動一個web server,埠號為8090。


[root@test bin]# == Sinatra/1.3.6 has taken the stage on 8090 for production with backup from Thin
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:8090, CTRL+C to stop


[root@test bin]# ┌────────────────────────┬───────────────────┬───────────────────┐
│                        │ 10.10.13.189:6379 │ 10.10.13.190:6379 │
├────────────────────────┼───────────────────┼───────────────────┤
│          redis_version │             4.0.2 │             4.0.2 │
│             redis_mode │        standalone │        standalone │
│             process_id │             13270 │             13382 │
│      uptime_in_seconds │          19380042 │          19379995 │
│         uptime_in_days │               224 │               224 │
│                   role │            master │            master │
│       connected_slaves │                 0 │                 1 │
│            aof_enabled │                 0 │                 0 │
│ rdb_bgsave_in_progress │                 0 │                 0 │
│     rdb_last_save_time │        1508202924 │        1510540281 │
└────────────────────────┴───────────────────┴───────────────────┘


[root@test bin]# 
┌────────┬──┬──┬───┬───┬─────┬──────┬──────┬────┬────┬─────┬─────┬─────┬────┬─────┬───┬──────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬────>
     time us sy  cl bcl rej/s    mem    rss frag keys cmd/s   cmd exp/s  exp evt/s evt hit%/s hit/s   hit mis/s   mis aofcs aofbs  chsv psch>
├────────┼──┼──┼───┼───┼─────┼──────┼──────┼────┼────┼─────┼─────┼─────┼────┼─────┼───┼──────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────>
 16:36:06  -  - 496   0     - 3.66GB 4.02GB 2.20  559     - 95.7G     - 317k     -   0      -     - 5.58G     - 5.89G    0B    0B 20.2G    1>
└────────┴──┴──┴───┴───┴─────┴──────┴──────┴────┴────┴─────┴─────┴─────┴────┴─────┴───┴──────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴────>
[root@test bin]# 

[root@test bin]# 
 16:36:11  5 10 493   0     0 3.65GB 4.02GB 2.20  528 5.06k 95.7G     0 317k     0   0   0.78  3.20 5.58G   409 5.89G    0B    0B 20.2G    1>
 16:36:16  7 15 492   0     0 3.65GB 4.02GB 2.20  537 5.73k 95.7G  0.40 317k     0   0   0.36  1.60 5.58G   437 5.89G    0B    0B 20.2G    1>
 16:36:21  5 15 492   0     0 3.65GB 4.02GB 2.20  528 5.22k 95.7G     0 317k     0   0   0.70  2.80 5.58G   399 5.89G    0B    0B 20.2G    1>
 16:36:26  6 15 509   0     0 3.65GB 4.02GB 2.20  527 5.28k 95.7G     0 317k     0   0   1.00  4.00 5.58G   396 5.89G    0B    0B 20.2G    1>
 16:36:31  9 20 509   0     0 3.65GB 4.02GB 2.20  528 8.16k 95.7G     0 317k     0   0   0.35  2.20 5.58G   623 5.89G    0B    0B 20.2G    1>
 16:36:36  9 20 510   0     0 3.65GB 4.02GB 2.20  525 8.65k 95.7G     0 317k     0   0   0.36  2.40 5.58G   660 5.89G    0B    0B 20.2G    1>
 16:36:41  5 15 510   0     0 3.65GB 4.02GB 2.20  533 5.70k 95.7G     0 317k     0   0   0.63  2.80 5.58G   445 5.89G    0B    0B 20.2G    1>
 16:36:46  4 15 508   0     0 3.65GB 4.02GB 2.20  526 4.42k 95.7G     0 317k     0   0   1.10  3.80 5.58G   342 5.89G    0B    0B 20.2G    1>
 16:36:51  6 10 509   0     0 3.65GB 4.02GB 2.20  536 5.10k 95.7G     0 317k     0   0   1.00  4.00 5.58G   395 5.89G    0B    0B 20.2G    1>
 16:36:56  5 10 510   0     0 3.65GB 4.02GB 2.20  529 4.89k 95.7G  0.20 317k     0   0   0.90  3.40 5.58G   374 5.89G    0B    0B 20.2G    1>
 16:37:01  5 15 510   0     0 3.65GB 4.02GB 2.20  528 5.29k 95.7G     0 317k     0   0   0.68  2.80 5.58G   409 5.89G    0B    0B 20.2G    1>
 16:37:06  8 20 511   0     0 3.65GB 4.02GB 2.20  545 7.99k 95.7G     0 317k     0   0   0.49  3.00 5.58G   615 5.89G    0B    0B 20.2G    1>
 16:37:11  6 15 511   0     0 3.65GB 4.02GB 2.20  538 5.37k 95.7G     0 317k     0   0   0.52  2.20 5.58G   424 5.89G    0B    0B 20.2G    1>
 16:37:16  5 15 509   0     0 3.66GB 4.02GB 2.20  556 5.49k 95.7G  0.20 317k     0   0   0.99  4.20 5.58G   421 5.89G    0B    0B 20.2G    1>
 16:37:21  8 20 508   0     0 3.66GB 4.02GB 2.20  545 7.72k 95.7G     0 317k     0   0   0.57  3.40 5.58G   588 5.89G    0B    0B 20.2G    1>
 16:37:26  7 20 507   0     0 3.65GB 4.02GB 2.20  527 8.24k 95.7G     0 317k     0   0   0.70  4.40 5.58G   628 5.89G    0B    0B 20.2G    1>
 16:37:31  6 15 508   0     0 3.65GB 4.02GB 2.20  538 6.67k 95.7G     0 317k     0   0   0.35  1.80 5.58G   507 5.89G    0B    0B 20.2G    1>
 16:37:36  5 15 507   0     0 3.65GB 4.02GB 2.20  528 5.33k 95.7G     0 317k     0   0   1.46  6.00 5.58G   404 5.89G    0B    0B 20.2G    1>
 16:37:41  6 15 497   0     0 3.65GB 4.02GB 2.20  525 6.32k 95.7G     0 317k     0   0   0.49  2.40 5.58G   483 5.89G    0B    0B 20.2G    1>
 16:37:46  5 15 495   0     0 3.65GB 4.02GB 2.20  525 5.11k 95.7G     0 317k     0   0   0.66  2.60 5.58G   391 5.89G    0B    0B 20.2G    1>
 16:37:51  8 20 486   0     0 3.65GB 4.02GB 2.20  525 7.67k 95.7G     0 317k     0   0   0.38  2.20 5.58G   577 5.89G    0B    0B 20.2G    1>
 16:37:56  5 10 486   0     0 3.65GB 4.02GB 2.20  523 5.15k 95.7G     0 317k     0   0   0.44  1.80 5.58G   404 5.89G    0B    0B 20.2G    1>
 16:38:01  5 10 488   0     0 3.65GB 4.02GB 2.20  538 4.33k 95.7G     0 317k     0   0   0.89  3.00 5.58G   332 5.89G    0B    0B 20.2G    1>
 16:38:06  6 15 490   0     0 3.65GB 4.01GB 2.20  525 6.10k 95.7G     0 317k     0   0   0.50  2.40 5.58G   477 5.89G    0B    0B 20.2G    1>
 16:38:11  5 15 488   0     0 3.65GB 4.02GB 2.20  534 5.86k 95.7G     0 317k     0   0   0.45  2.00 5.58G   442 5.89G    0B    0B 20.2G    1>
 16:38:16  6 15 490   0     0 3.65GB 4.02GB 2.20  528 5.85k 95.7G  0.20 317k     0   0   0.58  2.60 5.58G   447 5.89G    0B    0B 20.2G    1>
 16:38:21  6 20 487   0     0 3.65GB 4.02GB 2.20  530 6.65k 95.7G     0 317k     0   0   0.56  2.80 5.58G   501 5.89G    0B    0B 20.2G    1>
 16:38:26  5 15 486   0     0 3.65GB 4.02GB 2.20  524 5.80k 95.7G     0 317k     0   0   0.66  3.00 5.58G   449 5.89G    0B    0B 20.2G    1>
 16:38:31  5 10 486   0     0 3.65GB 4.02GB 2.20  529 4.78k 95.7G     0 317k     0   0   0.70  2.60 5.58G   370 5.89G    0B    0B 20.2G    1>
 16:38:36  5 15 484   0     0 3.65GB 4.02GB 2.20  524 6.40k 95.7G     0 317k     0   0   0.20  1.00 5.58G   492 5.89G    0B    0B 20.2G    1>
 16:38:41  5 15 483   0     0 3.65GB 4.02GB 2.20  527 4.39k 95.7G     0 317k     0   0   0.64  2.20 5.58G   342 5.89G    0B    0B 20.2G    1>
 16:38:46  5 15 483   0     0 3.65GB 4.02GB 2.20  532 5.84k 95.7G     0 317k     0   0   0.68  3.00 5.58G   439 5.89G    0B    0B 20.2G    1>
 16:38:51  5 10 486   0     0 3.65GB 4.01GB 2.20  528 4.93k 95.7G     0 317k     0   0   0.51  2.00 5.58G   388 5.89G    0B    0B 20.2G    1>
 16:38:56  6 15 486   0     0 3.65GB 4.01GB 2.20  528 6.38k 95.7G     0 317k     0   0   0.34  1.60 5.58G   470 5.89G    0B    0B 20.2G    1>
 16:39:01  4 10 488   0     0 3.65GB 4.01GB 2.20  524 4.31k 95.7G     0 317k     0   0   0.51  1.80 5.58G   351 5.89G    0B    0B 20.2G    1>
 16:39:06  6 15 489   0     0 3.66GB 4.01GB 2.20  563 5.29k 95.7G     0 317k     0   0   0.56  2.20 5.58G   391 5.89G    0B    0B 20.2G    1>
 16:39:11  7 20 490   0     0 3.65GB 4.01GB 2.20  526 7.76k 95.7G     0 317k     0   0   0.40  2.40 5.58G   604 5.89G    0B    0B 20.2G    1>
 16:39:16  6 20 488   0     0 3.65GB 4.01GB 2.20  529 7.54k 95.7G  0.20 317k     0   0   0.56  3.20 5.58G   563 5.89G    0B    0B 20.2G    1>
 16:39:21  6 20 490   0     0 3.65GB 4.01GB 2.20  525 7.11k 95.7G     0 317k     0   0   0.36  2.00 5.58G   546 5.89G    0B    0B 20.2G    1>
 16:39:26  5 15 489   0     0 3.65GB 4.01GB 2.20  525 5.42k 95.7G     0 317k     0   0   0.38  1.60 5.58G   419 5.89G    0B    0B 20.2G    1>
 16:39:31  8 20 498   0     0 3.65GB 4.01GB 2.20  526 8.05k 95.7G     0 317k     0   0   0.47  2.80 5.58G   597 5.89G    0B    0B 20.2G    1>
 16:39:36  8 15 500   0     0 3.66GB 4.01GB 2.20  530 6.56k 95.7G     0 317k     0   0   0.36  1.80 5.58G   492 5.89G    0B    0B 20.2G    1>
 16:39:41  8 20 508   0     0 3.65GB 4.01GB 2.20  530 8.36k 95.7G     0 317k     0   0   0.34  2.20 5.58G   649 5.89G    0B    0B 20.2G    1>
 16:39:46  5 15 507   0     0 3.65GB 4.01GB 2.20  525 4.70k 95.7G     0 317k     0   0   0.33  1.20 5.58G   363 5.89G    0B    0B 20.2G    1>
 16:39:51  6 10 509   0     0 3.65GB 4.01GB 2.20  539 4.75k 95.7G     0 317k     0   0   1.15  4.20 5.58G   361 5.89G    0B    0B 20.2G    1>
 16:39:56  6 15 509   0     0 3.65GB 4.01GB 2.20  526 5.83k 95.7G     0 317k     0   0   0.69  3.20 5.58G   463 5.89G    0B    0B 20.2G    1>
 16:40:01  5 20 513   0     0 3.65GB 4.01GB 2.20  526 6.70k 95.7G     0 317k     0   0   0.49  2.40 5.58G   483 5.89G    0B    0B 20.2G    1>
├────────┼──┼──┼───┼───┼─────┼──────┼──────┼────┼────┼─────┼─────┼─────┼────┼─────┼───┼──────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────>
     time us sy  cl bcl rej/s    mem    rss frag keys cmd/s   cmd exp/s  exp evt/s evt hit%/s hit/s   hit mis/s   mis aofcs aofbs  chsv psch>
├────────┼──┼──┼───┼───┼─────┼──────┼──────┼────┼────┼─────┼─────┼─────┼────┼─────┼───┼──────┼─────┼─────┼─────┼─────┼─────┼─────┼─────┼────>
 16:40:06  8 15 511   0     0 3.65GB 4.01GB 2.20  533 6.12k 95.7G  0.80 317k     0   0   0.30  1.40 5.58G   469 5.89G    0B    0B 20.2G    1>
 16:40:11  8 20 511   0     0 3.66GB 4.01GB 2.20  527 7.15k 95.7G  0.20 317k     0   0   0.41  2.20 5.58G   541 5.89G    0B    0B 20.2G    1>
 16:40:16  5 15 511   0     0 3.65GB 4.01GB 2.20  527 6.60k 95.7G     0 317k     0   0   0.47  2.40 5.58G   503 5.89G    0B    0B 20.2G    1>
 16:40:21  6 15 510   0     0 3.65GB 4.01GB 2.20  536 4.52k 95.7G     0 317k     0   0   0.63  2.20 5.58G   349 5.89G    0B    0B 20.2G    1>
└────────┴──┴──┴───┴───┴─────┴──────┴──────┴────┴────┴─────┴─────┴─────┴────┴─────┴───┴──────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴────>^C
 16:40:26  5 15 508   0     0 3.65GB 4.01GB 2.20  537 5.27k 95.7G     0 317k     0   0   0.54  2.20 5.58G   403 5.89G    0B    0B 20.2G    1>
└────────┴──┴──┴───┴───┴─────┴──────┴──────┴────┴────┴─────┴─────┴─────┴────┴─────┴───┴──────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴────>ps


web圖形介面展示如下:

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2155289/,如需轉載,請註明出處,否則將追究法律責任。

相關文章