学会使用mongostat监控mongodb状态
<DIV><DIV class=post-header>MongoDB Monitoring: mongostat
<DIV id=single-date class=date>There are a number of built in tools and commands which can be used to get important information from MongoDB but because it is relatively new, it can be difficult to know what you need to be doing from an operational perspective to ensure that everything runs smoothly.</DIV>
<DIV class=date>This is the 5th in <A href="http://blog.boxedice.com/mongodb-monitoring/" target=_blank><STRONG><FONT color=#555555>a series of 6 posts</FONT></STRONG></A> about MongoDB monitoring based on <A href="http://www.slideshare.net/boxedice/monitoring-mongodb-mongosv" target=_blank><STRONG><FONT color=#555555>a talk I gave at the MongoSV 2010 conference</FONT></STRONG></A>. <A href="http://blog.boxedice.com/mongodb-monitoring/" target=_blank><STRONG><FONT color=#555555>View the series index here</FONT></STRONG></A>.</DIV>
<DIV class=date><STRONG>MongoDB Monitoring dashboard + alerting</STRONG></DIV>
<DIV class=date>We provide a <A href="http://www.mongodbmonitoring.com/" target=_blank><STRONG><FONT color=#555555>MongoDB monitoring</FONT></STRONG></A> service to keep an eye on the health and performance of your MongoDB database cluster automatically and with alerting. <A href="http://www.mongodbmonitoring.com/" target=_blank><STRONG><FONT color=#555555>Find out more here</FONT></STRONG></A>.</DIV>
<DIV class=date><STRONG>mongostat</STRONG></DIV>
<DIV class=date>This is a tool that is included with the standard MongoDB distribution package which allows you to view statistics about your database servers in real time. <A href="http://boxedice.files.wordpress.com/2011/01/mongostat.png" target=_blank><IMG class="aligncenter size-full wp-image-1772" title="mongostat screenshot" alt="mongostat screenshot" src="http://boxedice.files.wordpress.com/2011/01/mongostat.png?w=600&h=99" width=600 height=99></A></DIV>
<DIV class=date>If you are running <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongod</FONT> locally on its standard 27017 port then you can just start <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongostat</FONT> and it will automatically connect. Otherwise, you can specify one or many hostnames + ports to connect to. The screenshot above shows all the servers in our MongoDB cluster.</DIV>
<DIV class=date>Most of the columns are self explanatory (e.g. <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>insert</FONT> = inserts per second) and <A href="http://www.mongodb.org/display/DOCS/mongostat" target=_blank><STRONG><FONT color=#555555>noted in the documentation</FONT></STRONG></A> but a few are worth mentioning specifically:</DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>flushes</FONT> – this shows how many times data has been <A href="http://www.mongodb.org/display/DOCS/fsync+Command" target=_blank><STRONG><FONT color=#555555>flushed to disk</FONT></STRONG></A>. MongoDB only physically writes data to disk every 60 seconds (by default). This has the effect of increasing performance but can decrease durability because a hard crash inbetween flushes will result in that data not being written, and therefore lost. v1.8 solves this with the option for <A href="http://www.mongodb.org/display/DOCS/Durability+and+Repair" target=_blank><STRONG><FONT color=#555555>durability</FONT></STRONG></A> but this stat shows how often <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongod</FONT> is flushing data to disk. </DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>faults</FONT> – the faults column shows you the number of Linux page faults per second. This is when Mongo accesses something that is mapped to the virtual address space but not in physical memory. i.e. it results in a read from disk. High values here indicate you may not have enough RAM to store all necessary data and disk accesses may start to become the bottleneck. </DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>locked %</FONT> – shows the % of time in a global write lock. When this is happening no other queries will complete until the lock is given up, or the lock owner yields. This is indicative of a large, global operation like a remove() or dropping a collection and can result in slow performance. </DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>% idx miss</FONT> – this is like we saw in the <A href="http://blog.boxedice.com/2010/12/29/mongodb-monitoring-db-serverstatus/" target=_blank><STRONG><FONT color=#555555>server status</FONT></STRONG></A> output except instead of an aggregate total, you can see queries hitting (or missing) the index in real time. This is useful if you’re debugging specific queries in development or need to track down a server that is performing badly. </DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>qr|qw</FONT> – when MongoDB gets too many queries to handle in real time, it queues them up. This is represented in <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongostat</FONT> by the read and write queue columns. When this starts to increase you will see slowdowns in executing queries as they have to wait to run through the queue. You can alleviate this by stopping any more queries until the queue has dissipated. Queues will tend to spike if you’re doing a lot of write operations alongside other write heavy ops, such as large ranged removes. </DIV>
<DIV class=date><FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongostat</FONT> is useful because it shows what is happening in your cluster right now. This is particularly handy to quickly find out which member of your replica sets is master right now – the final column shows this. If you start seeing slowdowns or suspect a problem with MongoDB, <FONT style="BACKGROUND-COLOR: #f3f3f3" size=3 face=Consolas>mongostat</FONT> should be your first point of call to quickly locate where the problem is.</DIV>
<DIV class=date><STRONG>Stay tuned</STRONG></DIV>
<DIV class=date>This is the 5th post in a series of 6 on MongoDB Monitoring. <A href="http://blog.boxedice.com/mongodb-monitoring/" target=_blank><STRONG><FONT color=#555555>View the full post index</FONT></STRONG></A> and don’t </DIV></DIV></DIV>
页:
[1]