镜缘浮影 小人本住在 苏州的城外 家里有屋又有田 生活乐无边

SSDB 状态详解

2016-06-21
wilmosfang
原文地址 http://soft.dog/2016/06/21/ssdb-info/

前言

SSDB 是一个高性能支持丰富数据结构的 NoSQL 数据库, 用于替代 Redis

在 SSDB 运维管理过程中,会经常需要了解数据库当前的状态,这里分享一下 SSDB 数据库状态的详细解释

Tip: SSDB 相关基础和 master-master 集群的构建,可以参考之前的一篇博客 SSDB基础

详细可以参考 命令行工具 ssdb-cli

Tip: 目前官方稳定版是 SSDB 1.9.2 , 最新版本为 SSDB 1.9.3


概要


环境

[root@h102 ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

[root@h102 ~]# uname -a
Linux h102.temp 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@h102 ~]#

下载安装

[root@h102 ssdb]# wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
--2016-06-21 13:51:06--  https://github.com/ideawu/ssdb/archive/master.zip
Resolving github.com... 192.30.252.131
Connecting to github.com|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/ideawu/ssdb/zip/master [following]
--2016-06-21 13:51:07--  https://codeload.github.com/ideawu/ssdb/zip/master
Resolving codeload.github.com... 192.30.253.121
Connecting to codeload.github.com|192.30.253.121|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1588248 (1.5M) [application/zip]
Saving to: “master.zip”

100%[================================================================================>] 1,588,248    257K/s   in 6.3s    

2016-06-21 13:51:15 (247 KB/s) - “master.zip” saved [1588248/1588248]

[root@h102 ssdb]# unzip master
Archive:  master.zip
7cbd1e7b4d76b0f3267717edc36affb23e800c95
   creating: ssdb-master/
  inflating: ssdb-master/.gitignore  
  inflating: ssdb-master/ChangeLog   
  inflating: ssdb-master/Dockerfile  
  inflating: ssdb-master/LICENSE     
  inflating: ssdb-master/Makefile    
  inflating: ssdb-master/README.md   
   creating: ssdb-master/api/
 ...
 ...
  inflating: ssdb-master/tools/ssdb_cli/cluster.cpy  
  inflating: ssdb-master/tools/ssdb_cli/exporter.cpy  
  inflating: ssdb-master/tools/ssdb_cli/flushdb.cpy  
  inflating: ssdb-master/tools/ssdb_cli/importer.cpy  
  inflating: ssdb-master/tools/ssdb_cli/nagios.cpy  
  inflating: ssdb-master/tools/ssdb_cli/util.cpy  
  inflating: ssdb-master/tools/test_slow_client.php  
  inflating: ssdb-master/tools/unittest.php  
 extracting: ssdb-master/version     
[root@h102 ssdb]# cd ssdb-master
[root@h102 ssdb-master]# make 

##### building snappy... #####
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking how to print strings... printf
checking for style of include used by make... GNU
checking for gcc... gcc
...
...
g++ -o ssdb-repair ssdb-repair.o ../src/net/link.o ../src/net/fde.o ../src/util/log.o ../src/util/bytes.o   "/usr/local/src/ssdb/ssdb-master/deps/leveldb-1.18/libleveldb.a" "/usr/local/src/ssdb/ssdb-master/deps/snappy-1.1.0/.libs/libsnappy.a" "/usr/local/src/ssdb/ssdb-master/deps/jemalloc-4.1.0/lib/libjemalloc.a" -pthread -lrt
g++ -o leveldb-import leveldb-import.o ../src/net/link.o ../src/net/fde.o ../src/util/log.o ../src/util/bytes.o   "/usr/local/src/ssdb/ssdb-master/deps/leveldb-1.18/libleveldb.a" "/usr/local/src/ssdb/ssdb-master/deps/snappy-1.1.0/.libs/libsnappy.a" "/usr/local/src/ssdb/ssdb-master/deps/jemalloc-4.1.0/lib/libjemalloc.a" -pthread -lrt
g++ -o ssdb-migrate ssdb-migrate.o ../api/cpp/libssdb-client.a ../src/util/libutil.a
make[1]: Leaving directory `/usr/local/src/ssdb/ssdb-master/tools'
[root@h102 ssdb-master]# 
[root@h102 ssdb-master]# echo $?
0
[root@h102 ssdb-master]# 
[root@h102 ssdb-master]# make install 
mkdir -p /usr/local/ssdb
mkdir -p /usr/local/ssdb/_cpy_
mkdir -p /usr/local/ssdb/deps
mkdir -p /usr/local/ssdb/var
mkdir -p /usr/local/ssdb/var_slave
cp -f ssdb-server ssdb.conf ssdb_slave.conf /usr/local/ssdb
cp -rf api /usr/local/ssdb
cp -rf \
		tools/ssdb-bench \
		tools/ssdb-cli tools/ssdb_cli \
		tools/ssdb-cli.cpy tools/ssdb-dump \
		tools/ssdb-repair \
		/usr/local/ssdb
cp -rf deps/cpy /usr/local/ssdb/deps
chmod 755 /usr/local/ssdb
chmod -R ugo+rw /usr/local/ssdb/*
rm -f /usr/local/ssdb/Makefile
[root@h102 ssdb-master]# echo $?
0
[root@h102 ssdb-master]#
[root@h102 ssdb-master]# /usr/local/ssdb/ssdb-server -h
ssdb-server 1.9.3
Copyright (c) 2012-2015 ssdb.io

Usage:
    /usr/local/ssdb/ssdb-server [-d] /path/to/ssdb.conf [-s start|stop|restart]
Options:
    -d    run as daemon
    -s    option to start|stop|restart the server
    -h    show this message
[root@h102 ssdb-master]#

启动

[root@h102 ssdb]# ./ssdb-server  -d ssdb.conf -s start 
ssdb-server 1.9.3
Copyright (c) 2012-2015 ssdb.io

[root@h102 ssdb]# ps faux | grep ssdb 
root     15737  0.0  0.0    208     8 pts/0    R+   14:54   0:00  |       \_ grep ssdb
root     15713  0.3  0.6 156252 11780 ?        Ssl  14:53   0:00 ./ssdb-server -d ssdb.conf -s start
[root@h102 ssdb]# 
[root@h102 ssdb]# netstat -ant | grep 8888
tcp        0      0 127.0.0.1:8888              0.0.0.0:*                   LISTEN      
[root@h102 ssdb]#

连接

[root@h102 ssdb]# ./ssdb-cli -h localhost -p 8888
which: no python2.7 in (/usr/local/rvm/gems/ruby-2.3.0/bin:/usr/local/rvm/gems/ruby-2.3.0@global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/root/bin)
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io

'h' or 'help' for help, 'q' to quit.

ssdb-server 1.9.3

ssdb localhost:8888>

貌似 1.9.3 的客户端有 python2.7 的环境要求,于是弹出了警告,我们今天主要是了解 ssdb 状态,暂时不理会此警告


info

ssdb 数据库很简单,在交互窗口中使用 info 命令就可以获得所有当前状态的统计值

由于我们并没有存入数据,所以几乎全为 0

ssdb 127.0.0.1:8888> info 
version
	1.9.3
links
	1
total_calls
	9
dbsize
	941
binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 23
serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
data_key_range
	    kv  : "1" - "n"
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
leveldb.stats
	                               Compactions
	Level  Files Size(MB) Time(sec) Read(MB) Write(MB)
	--------------------------------------------------
	  0        1        0         0        0         0
	  1        1        0         0        0         0
	
17 result(s) (0.004 sec)
(0.004 sec)
ssdb 127.0.0.1:8888>

info cmd

我们要获取命令的使用统计,可以通过 info cmd

ssdb 127.0.0.1:8888> info cmd
version
	1.9.3
links
	1
total_calls
	10
dbsize
	941
binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 23
serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
cmd.zincr
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_set_kv_status
	calls: 0	time_wait: 0	time_proc: 0
cmd.sync140
	calls: 0	time_wait: 0	time_proc: 0
cmd.ttl
	calls: 0	time_wait: 0	time_proc: 0
cmd.qfix
	calls: 0	time_wait: 0	time_proc: 0
cmd.qtrim_front
	calls: 0	time_wait: 0	time_proc: 0
cmd.qget
	calls: 0	time_wait: 0	time_proc: 0
cmd.qrlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_zset
	calls: 0	time_wait: 0	time_proc: 0
cmd.get
	calls: 0	time_wait: 0	time_proc: 0
cmd.auth
	calls: 0	time_wait: 0	time_proc: 0
cmd.getbit
	calls: 0	time_wait: 0	time_proc: 0
cmd.del_allow_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.getset
	calls: 0	time_wait: 0	time_proc: 0
cmd.qtrim_back
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_zdel
	calls: 0	time_wait: 0	time_proc: 0
cmd.hlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.dbsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.hkeys
	calls: 0	time_wait: 0	time_proc: 0
cmd.zsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_exists
	calls: 0	time_wait: 0	time_proc: 0
cmd.hdecr
	calls: 0	time_wait: 0	time_proc: 0
cmd.zset
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrrange
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_get
	calls: 0	time_wait: 0	time_proc: 0
cmd.hvals
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_hget
	calls: 0	time_wait: 0	time_proc: 0
cmd.list_deny_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrank
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_del_kv_node
	calls: 0	time_wait: 0	time_proc: 0
cmd.bitcount
	calls: 0	time_wait: 0	time_proc: 0
cmd.compact
	calls: 0	time_wait: 0	time_proc: 0
cmd.zdel
	calls: 0	time_wait: 0	time_proc: 0
cmd.hscan
	calls: 0	time_wait: 0	time_proc: 0
cmd.zclear
	calls: 0	time_wait: 0	time_proc: 0
cmd.zavg
	calls: 0	time_wait: 0	time_proc: 0
cmd.getrange
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpush_front
	calls: 0	time_wait: 0	time_proc: 0
cmd.get_kv_range
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpush
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.qrange
	calls: 0	time_wait: 0	time_proc: 0
cmd.hget
	calls: 0	time_wait: 0	time_proc: 0
cmd.qlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpop
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpop_back
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_set_kv_range
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_zsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.setx
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_hexists
	calls: 0	time_wait: 0	time_proc: 0
cmd.hincr
	calls: 0	time_wait: 0	time_proc: 0
cmd.ignore_key_range
	calls: 0	time_wait: 0	time_proc: 0
cmd.strlen
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpop_front
	calls: 0	time_wait: 0	time_proc: 0
cmd.zremrangebyscore
	calls: 0	time_wait: 0	time_proc: 0
cmd.setbit
	calls: 0	time_wait: 0	time_proc: 0
cmd.keys
	calls: 0	time_wait: 0	time_proc: 0
cmd.zcount
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrscan
	calls: 0	time_wait: 0	time_proc: 0
cmd.list_allow_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.clear_binlog
	calls: 0	time_wait: 0	time_proc: 0
cmd.get_key_range
	calls: 0	time_wait: 0	time_proc: 0
cmd.flushdb
	calls: 0	time_wait: 0	time_proc: 0
cmd.qset
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_zget
	calls: 0	time_wait: 0	time_proc: 0
cmd.rkeys
	calls: 0	time_wait: 0	time_proc: 0
cmd.setnx
	calls: 0	time_wait: 0	time_proc: 0
cmd.decr
	calls: 0	time_wait: 0	time_proc: 0
cmd.del_deny_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.set
	calls: 0	time_wait: 0	time_proc: 0
cmd.zsum
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_add_kv_node
	calls: 0	time_wait: 0	time_proc: 0
cmd.add_allow_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.hclear
	calls: 0	time_wait: 0	time_proc: 0
cmd.hsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.del
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_migrate_kv_data
	calls: 0	time_wait: 0	time_proc: 0
cmd.scan
	calls: 0	time_wait: 0	time_proc: 0
cmd.hexists
	calls: 0	time_wait: 0	time_proc: 0
cmd.qback
	calls: 0	time_wait: 0	time_proc: 0
cmd.zlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.zkeys
	calls: 0	time_wait: 0	time_proc: 0
cmd.zfix
	calls: 0	time_wait: 0	time_proc: 0
cmd.zget
	calls: 0	time_wait: 0	time_proc: 0
cmd.qslice
	calls: 0	time_wait: 0	time_proc: 0
cmd.rscan
	calls: 0	time_wait: 0	time_proc: 0
cmd.hrlist
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrange
	calls: 0	time_wait: 0	time_proc: 0
cmd.zdecr
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_set
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_hset
	calls: 0	time_wait: 0	time_proc: 0
cmd.qfront
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_zexists
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_kv_node_list
	calls: 0	time_wait: 0	time_proc: 0
cmd.zpop_front
	calls: 0	time_wait: 0	time_proc: 0
cmd.qpush_back
	calls: 0	time_wait: 0	time_proc: 0
cmd.hgetall
	calls: 0	time_wait: 0	time_proc: 0
cmd.dump
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_del
	calls: 0	time_wait: 0	time_proc: 0
cmd.ping
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_hdel
	calls: 0	time_wait: 0	time_proc: 0
cmd.zscan
	calls: 0	time_wait: 0	time_proc: 0
cmd.incr
	calls: 0	time_wait: 0	time_proc: 0
cmd.exists
	calls: 0	time_wait: 0	time_proc: 0
cmd.countbit
	calls: 0	time_wait: 0	time_proc: 0
cmd.expire
	calls: 0	time_wait: 0	time_proc: 0
cmd.substr
	calls: 0	time_wait: 0	time_proc: 0
cmd.zremrangebyrank
	calls: 0	time_wait: 0	time_proc: 0
cmd.hrscan
	calls: 0	time_wait: 0	time_proc: 0
cmd.zpop_back
	calls: 0	time_wait: 0	time_proc: 0
cmd.add_deny_ip
	calls: 0	time_wait: 0	time_proc: 0
cmd.hset
	calls: 0	time_wait: 0	time_proc: 0
cmd.info
	calls: 10	time_wait: 0	time_proc: 2
cmd.qsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.set_kv_range
	calls: 0	time_wait: 0	time_proc: 0
cmd.multi_hsize
	calls: 0	time_wait: 0	time_proc: 0
cmd.version
	calls: 0	time_wait: 0	time_proc: 0
cmd.qclear
	calls: 0	time_wait: 0	time_proc: 0
cmd.zrrank
	calls: 0	time_wait: 0	time_proc: 0
cmd.hdel
	calls: 0	time_wait: 0	time_proc: 0
cmd.zexists
	calls: 0	time_wait: 0	time_proc: 0
255 result(s) (0.004 sec)
(0.004 sec)
ssdb 127.0.0.1:8888> 

状态详解

version

版本信息

当前数据库的版本

version
	1.9.3

连接数

当前服务器的连接数

links
	1

total_calls

被调用总次数

total_calls
	9

dbsize

数据库大小(字节数)

数据库预估的大小(可能和硬盘占用差异非常大) . 如果服务器开启了压缩, 这个大小是压缩后的大小

dbsize
	941

binlogs

当前实例的写操作状态.

binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 23
  • capacity: binlog 队列的最大长度
  • min_seq: 当前队列中的最小 binlog 序号
  • max_seq: 当前队列中的最大 binlog 序号

replication

当此服务器有 master 或 slave 的时候才会有此信息,所以此信息并不一定出现(当为一台单点 ssdb 时就没有)

作为 master 时,信息格式如下

replication
    client 192.168.1.123:45105
        type     : mirror
        status   : SYNC
        last_seq : 309191438

可以有多条 replication 记录. 每一条表示一个连接进来的 slave(client)

  • client host:port, 远端 slave 的 host:port
  • type: 类型, sync/mirror
  • status: 当前同步状态, DISCONNECTED/INIT/OUT_OF_SYNC/COPY/SYNC
  • last_seq: 上一条发送或者收到的 binlog 的序号

作为 slave 时,信息格式如下

replication
    slaveof 192.168.1.123:8888
        id         : svc_rabbit_1
        type       : mirror
        status     : SYNC
        last_seq   : 309368166
        copy_count : 0
        sync_count : 45988698

一条表示一个当前服务器所连接的 master(slaveof).

  • slaveof host:port, 远端 master 的 host:port
  • type: 类型, sync/mirror
  • status: 当前同步状态, DISCONNECTED/INIT/OUT_OF_SYNC/COPY/SYNC
  • last_seq: 上一条发送或者收到的 binlog 的序号
  • slaveof.id: master 的 id (这是从 slave’s 角度来看的, 永远不需要在 master 上配置它自己的 id)
  • slaveof.copy_count: 在全量同步时, 已经复制的 key 的数量
  • slaveof.sync_count: 发送或者收到的 binlog 的数量

关于status:

  • DISCONNECTED: 与 master 断开了连接, 一般是网络中断
  • INIT: 初始化状态
  • OUT_OF_SYNC: 由于短时间内在 master 有大量写操作, 导致 binlog 队列淘汰, slave 丢失同步点, 只好重新复制全部的数据
  • COPY: 正在复制基准数据的过程中, 新的写操作可能无法及时地同步
  • SYNC: 同步状态是健康的

serv_key_range

serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""

不同数据类型的 key 在 SSDB 中是排序的, 所以这个信息表示不同数据类型的最小 key 和最大 key

data_key_range

data_key_range
	    kv  : "1" - "n"
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""

不同数据类型的 key 在 SSDB 中是排序的, 所以这个信息表示不同数据类型的最小 key 和最大 key

leveldb.stats

这个信息显示了 LevelDB 每一层级的文件数量和文件总大小. 越小的层级如果文件越少, 那么数据库就越健康(查询更快速)

leveldb.stats
                                   Compactions
    Level  Files Size(MB) Time(sec) Read(MB) Write(MB)
    --------------------------------------------------
      0        0        0       214        0      3285
      1        3       95      2070    22656     22292
      2       57     1479     12672   142498    142157
      3      152     3729     45799   568780    566911

info cmd

ssdb 127.0.0.1:8888> info cmd
version
	1.9.3
links
	1
total_calls
	11
dbsize
	941
binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 23
serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
cmd.zincr
	calls: 0	time_wait: 0	time_proc: 0
cmd.cluster_set_kv_status
	calls: 0	time_wait: 0	time_proc: 0
...
...
cmd.hdel
	calls: 0	time_wait: 0	time_proc: 0
cmd.zexists
	calls: 0	time_wait: 0	time_proc: 0
255 result(s) (0.009 sec)
(0.009 sec)
ssdb 127.0.0.1:8888> 
  • cmd.* : 代表某子类命令的操作
  • calls: 该命令总共处理了多少次
  • time_wait: 命令在被处理前等待的总共时间(单位毫秒)
  • time_proc: 命令处理总共消耗的时间(单位毫秒)

通过上面的三个值可以分别计算出此命令的 平均等待时间平均处理时间


命令汇总

  • wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
  • unzip master
  • cd ssdb-master
  • make
  • make install
  • echo $?
  • /usr/local/ssdb/ssdb-server -h
  • ./ssdb-server -d ssdb.conf -s start
  • ps faux | grep ssdb
  • netstat -ant | grep 8888
  • ./ssdb-cli -h localhost -p 8888

原文地址 http://soft.dog/2016/06/21/ssdb-info/

评论