diff options
author | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
---|---|---|
committer | Antonin Kral <a.kral@bobek.cz> | 2010-08-11 12:38:57 +0200 |
commit | 7645618fd3914cb8a20561625913c20d49504a49 (patch) | |
tree | 8370f846f58f6d71165b7a0e2eda04648584ec76 /tools/stat.cpp | |
parent | 68c73c3c7608b4c87f07440dc3232801720b1168 (diff) | |
download | mongodb-7645618fd3914cb8a20561625913c20d49504a49.tar.gz |
Imported Upstream version 1.6.0
Diffstat (limited to 'tools/stat.cpp')
-rw-r--r-- | tools/stat.cpp | 115 |
1 files changed, 106 insertions, 9 deletions
diff --git a/tools/stat.cpp b/tools/stat.cpp index f66f3f1..05318a9 100644 --- a/tools/stat.cpp +++ b/tools/stat.cpp @@ -16,9 +16,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "stdafx.h" +#include "pch.h" #include "client/dbclient.h" #include "db/json.h" +#include "../util/httpclient.h" #include "tool.h" @@ -38,6 +39,7 @@ namespace mongo { _sleep = 1; _rowNum = 0; _showHeaders = true; + _http = false; add_hidden_options() ( "sleep" , po::value<int>() , "time to sleep between calls" ) @@ -45,9 +47,12 @@ namespace mongo { add_options() ("noheaders", "don't output column names") ("rowcount,n", po::value<int>()->default_value(0), "number of stats lines to print (0 for indefinite)") + ("http", "use http instead of raw db connection") ; addPositionArg( "sleep" , 1 ); + + _autoreconnect = true; } virtual void printExtraHelp( ostream & out ){ @@ -55,7 +60,55 @@ namespace mongo { out << "sleep time: time to wait (in seconds) between calls" << endl; } + virtual void printExtraHelpAfter( ostream & out ){ + out << "\n"; + out << " Fields\n"; + out << " inserts/s \t- # of inserts per second\n"; + out << " query/s \t- # of queries per second\n"; + out << " update/s \t- # of updates per second\n"; + out << " delete/s \t- # of deletes per second\n"; + out << " getmore/s \t- # of get mores (cursor batch) per second\n"; + out << " command/s \t- # of commands per second\n"; + out << " flushes/s \t- # of fsync flushes per second\n"; + out << " mapped \t- amount of data mmaped (total data size) megabytes\n"; + out << " visze \t- virtual size of process in megabytes\n"; + out << " res \t- resident size of process in megabytes\n"; + out << " faults/s \t- # of pages faults/sec (linux only)\n"; + out << " locked \t- percent of time in global write lock\n"; + out << " idx miss \t- percent of btree page misses (sampled)\n"; + out << " q t|r|w \t- lock queue lengths (total|read|write)\n"; + out << " conn \t- number of open connections\n"; + } + + BSONObj stats(){ + if ( _http ){ + HttpClient c; + HttpClient::Result r; + + string url; + { + stringstream ss; + ss << "http://" << _host; + if ( _host.find( ":" ) == string::npos ) + ss << ":28017"; + ss << "/_status"; + url = ss.str(); + } + + if ( c.get( url , &r ) != 200 ){ + cout << "error (http): " << r.getEntireResponse() << endl; + return BSONObj(); + } + + BSONObj x = fromjson( r.getBody() ); + BSONElement e = x["serverStatus"]; + if ( e.type() != Object ){ + cout << "BROKEN: " << x << endl; + return BSONObj(); + } + return e.embeddedObjectUserCheck(); + } BSONObj out; if ( ! conn().simpleCommand( _db , &out , "serverStatus" ) ){ cout << "error: " << out << endl; @@ -77,7 +130,9 @@ namespace mongo { double y = ( b.getFieldDotted( outof ).number() - a.getFieldDotted( outof ).number() ); if ( y == 0 ) return 0; - return x / y; + double p = x / y; + p = (double)((int)(p * 1000)) / 10; + return p; } void cellstart( stringstream& ss , string name , unsigned& width ){ @@ -101,12 +156,10 @@ namespace mongo { } void cell( stringstream& ss , string name , unsigned width , const string& val ){ - assert( val.size() <= width ); cellstart( ss , name , width ); ss << setw(width) << val << " "; } - string doRow( const BSONObj& a , const BSONObj& b ){ stringstream ss; @@ -120,6 +173,13 @@ namespace mongo { } } + if ( b["backgroundFlushing"].type() == Object ){ + BSONObj ax = a["backgroundFlushing"].embeddedObject(); + BSONObj bx = b["backgroundFlushing"].embeddedObject(); + BSONObjIterator i( bx ); + cell( ss , "flushes/s" , 6 , (int)diff( "flushes" , ax , bx ) ); + } + if ( b.getFieldDotted("mem.supported").trueValue() ){ BSONObj bx = b["mem"].embeddedObject(); BSONObjIterator i( bx ); @@ -127,10 +187,24 @@ namespace mongo { cell( ss , "vsize" , 6 , bx["virtual"].numberInt() ); cell( ss , "res" , 6 , bx["resident"].numberInt() ); } + + if ( b["extra_info"].type() == Object ){ + BSONObj ax = a["extra_info"].embeddedObject(); + BSONObj bx = b["extra_info"].embeddedObject(); + if ( ax["page_faults"].type() || ax["page_faults"].type() ) + cell( ss , "faults/s" , 6 , (int)diff( "page_faults" , ax , bx ) ); + } - cell( ss , "% locked" , 8 , percent( "globalLock.totalTime" , "globalLock.lockTime" , a , b ) ); - cell( ss , "% idx miss" , 8 , percent( "indexCounters.btree.accesses" , "indexCounters.btree.misses" , a , b ) ); + cell( ss , "locked %" , 8 , percent( "globalLock.totalTime" , "globalLock.lockTime" , a , b ) ); + cell( ss , "idx miss %" , 8 , percent( "indexCounters.btree.accesses" , "indexCounters.btree.misses" , a , b ) ); + if ( b.getFieldDotted( "globalLock.currentQueue" ).type() == Object ){ + int r = b.getFieldDotted( "globalLock.currentQueue.readers" ).numberInt(); + int w = b.getFieldDotted( "globalLock.currentQueue.writers" ).numberInt(); + stringstream temp; + temp << r+w << "|" << r << "|" << w; + cell( ss , "q t|r|w" , 10 , temp.str() ); + } cell( ss , "conn" , 5 , b.getFieldDotted( "connections.current" ).numberInt() ); { @@ -142,7 +216,7 @@ namespace mongo { << setfill('0') << setw(2) << t.tm_min << ":" << setfill('0') << setw(2) << t.tm_sec; - cell( ss , "time" , 8 , temp.str() ); + cell( ss , "time" , 10 , temp.str() ); } if ( _showHeaders && _rowNum % 20 == 0 ){ @@ -154,6 +228,13 @@ namespace mongo { return ss.str(); } + virtual void preSetup(){ + if ( hasParam( "http" ) ){ + _http = true; + _noconnection = true; + } + } + int run(){ _sleep = getParam( "sleep" , _sleep ); if ( hasParam( "noheaders" ) ) { @@ -167,11 +248,26 @@ namespace mongo { while ( _rowCount == 0 || _rowNum < _rowCount ){ sleepsecs(_sleep); - BSONObj now = stats(); + BSONObj now; + try { + now = stats(); + } + catch ( std::exception& e ){ + cout << "can't get data: " << e.what() << endl; + continue; + } + if ( now.isEmpty() ) return -2; - cout << doRow( prev , now ) << endl; + try { + cout << doRow( prev , now ) << endl; + } + catch ( AssertionException& e ){ + cout << "\nerror: " << e.what() << "\n" + << now + << endl; + } prev = now; } @@ -183,6 +279,7 @@ namespace mongo { int _rowNum; int _rowCount; bool _showHeaders; + bool _http; }; } |