mongostat是一個命令行工具,可以連接到mongodb server,然後顯示出server的狀態。
下面演示一個簡單的使用:
直接在primary server上運行命令,不帶參數
root@vm1:~# mongostat connected to: 127.0.0.1 insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time *0 1 11 *0 19 3|0 1 1.28g 3.17g 1.13g 0 kaimei:73.4% 0 0|0 0|0 69k 7k 42 rs1 PRI 13:15:32 *0 2 16 *0 32 3|0 0 1.28g 3.17g 1.13g 0 kaimei:22.2% 0 0|0 0|1 38k 8k 42 rs1 PRI 13:15:33 *0 2 148 *0 151 2|0 0 1.28g 3.17g 1.13g 0 kaimei:62.6% 0 0|0 1|0 58k 52k 42 rs1 PRI 13:15:34 *0 1 112 *0 150 2|0 0 1.28g 3.17g 1.13g 0 kaimei:52.9% 0 0|0 0|0 70k 41k 42 rs1 PRI 13:15:35 *0 2 58 *0 48 2|0 0 1.28g 3.17g 1.13g 0 kaimei:44.2% 0 0|0 0|1 49k 21k 42 rs1 PRI 13:15:36
這樣就會默認每秒執行一次調用(文檔中稱為call),並把結果顯示成一行。
有些參數可以使用。
sleeptime 參數,比如下面:
root@vm1:~# mongostat 10 connected to: 127.0.0.1 insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time *0 1 34 *0 57 3|0 0 1.28g 3.17g 1.13g 0 kaimei:52.6% 0 0|0 1|0 47k 13k 42 rs1 PRI 13:18:19 *0 1 8 *0 14 3|0 0 1.28g 3.17g 1.13g 0 kaimei:52.6% 0 0|0 0|0 42k 3k 42 rs1 PRI 13:18:29 *0 1 62 *0 100 3|0 0 1.28g 3.17g 1.13g 0 kaimei:54.8% 0 0|0 1|0 46k 24k 42 rs1 PRI 13:18:39 *0 1 11 *0 19 3|0 0 1.28g 3.17g 1.13g 0 kaimei:52.2% 0 0|0 0|0 43k 5k 42 rs1 PRI 13:18:49
-n 代表執行call的次數,比如
oot@vm1:~# mongostat -n 2 connected to: 127.0.0.1 insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time *0 2 5 *0 8 1|0 0 1.28g 3.17g 1.13g 0 kaimei:24.7% 0 0|0 1|0 20k 4k 42 rs1 PRI 13:21:14 *0 1 54 *0 84 3|0 0 1.28g 3.17g 1.13g 0 kaimei:59.9% 0 0|0 0|0 61k 22k 42 rs1 PRI 13:21:15
也可以將-n 和 sleeptime組合使用
mongostat -n 10 10
意思是每隔10秒call一次,一共10次後退出
-v參數可以輸出關於mongostat命令的詳細信息,比如:
root@vm1:~# mongostat -v -n 2
Wed Dec 11 13:27:11.727 creating new connection to:127.0.0.1:27017
Wed Dec 11 13:27:11.727 BackgroundJob starting: ConnectBG
Wed Dec 11 13:27:11.728 connected connection!
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl time
*0 1 10 *0 23 3|0 0 1.28g 3.17g 1.13g 0 kaimei:26.7% 0 0|0 0|1 37k 6k 42 rs1 PRI 13:27:12
*0 2 65 *0 121 3|0 0 1.28g 3.17g 1.12g 0 kaimei:66.0% 0 0|0 1|0 49k 28k 42 rs1 PRI 13:27:13
--discover 可以獲得整個replica-set成員的狀態信息。比如:
mongostat --discover
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn set repl tim\
e
localhost *0 2 24 *0 34 9|0 0 1.28g 3.17g 1.13g 0 kaimei:39.9% 0 0|0 1|0 46k 14k 43 rs1 PRI 13:29:1\
1
localhost *0 1 5 *0 4 1|0 0 1.28g 3.17g 1.13g 0 kaimei:55.1% 0 0|0 0|0 52k 3k 43 rs1 PRI 13:29:1\
2
vm1:27017 no data
vm3:27017 no data
vm4:27017 no data
localhost *0 2 5 *0 8 10|0 0 1.28g 3.17g 1.13g 0 kaimei:26.5% 0 0|0 1|0 21k 10k 44 rs1 PRI 13:29:1\
3
vm1:27017 *0 2 5 *0 8 10|0 0 1.28g 3.17g 1.13g 0 kaimei:26.6% 0 0|0 1|0 21k 10k 44 rs1 PRI 13:29:1\
3
vm3:27017 *0 *0 *2 *0 0 4|0 0 1.28g 3.12g 485m 0 local:0.1% 0 0|0 0|0 304b 4k 14 rs1 SEC 13:29:1\
3
vm4:27017 *0 *0 *2 *0 0 4|0 0 1.28g 3.13g 485m 0 local:0.2% 0 0|0 0|0 304b 4k 14 rs1 SEC 13:29:1\
3