summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2010-06-09 13:20:35 -0400
committerEliot Horowitz <eliot@10gen.com>2010-06-09 13:20:35 -0400
commita12b7073003b9a1c9d19d7fe8d238952d3141779 (patch)
treed420f832acf9a6d801bb367e63ccb559bf5dd7fc /tools
parenteebb327db819bc0fe16fc32e8f144c2d71ca5a3c (diff)
downloadmongo-a12b7073003b9a1c9d19d7fe8d238952d3141779.tar.gz
auto-reconnect for mongostat
Diffstat (limited to 'tools')
-rw-r--r--tools/stat.cpp12
-rw-r--r--tools/tool.cpp4
-rw-r--r--tools/tool.h1
3 files changed, 14 insertions, 3 deletions
diff --git a/tools/stat.cpp b/tools/stat.cpp
index 64f2c2f48b2..b2c5447ad21 100644
--- a/tools/stat.cpp
+++ b/tools/stat.cpp
@@ -51,6 +51,8 @@ namespace mongo {
;
addPositionArg( "sleep" , 1 );
+
+ _autoreconnect = true;
}
virtual void printExtraHelp( ostream & out ){
@@ -210,7 +212,15 @@ 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;
diff --git a/tools/tool.cpp b/tools/tool.cpp
index bfc28a2f434..e6ef7bb564d 100644
--- a/tools/tool.cpp
+++ b/tools/tool.cpp
@@ -38,7 +38,7 @@ namespace mongo {
Tool::Tool( string name , bool localDBAllowed , string defaultDB ,
string defaultCollection , bool usesstdout ) :
_name( name ) , _db( defaultDB ) , _coll( defaultCollection ) ,
- _usesstdout(usesstdout), _noconnection(false), _conn(0), _paired(false) {
+ _usesstdout(usesstdout), _noconnection(false), _autoreconnect(false), _conn(0), _paired(false) {
_options = new po::options_description( "options" );
_options->add_options()
@@ -155,7 +155,7 @@ namespace mongo {
// do nothing
}
else if ( _host.find( "," ) == string::npos ){
- DBClientConnection * c = new DBClientConnection();
+ DBClientConnection * c = new DBClientConnection( _autoreconnect );
_conn = c;
string errmsg;
diff --git a/tools/tool.h b/tools/tool.h
index 70dd0e822f8..29dee010409 100644
--- a/tools/tool.h
+++ b/tools/tool.h
@@ -96,6 +96,7 @@ namespace mongo {
bool _usesstdout;
bool _noconnection;
+ bool _autoreconnect;
void addFieldOptions();
void needFields();