summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct4
-rw-r--r--db/db.cpp18
-rw-r--r--db/mms.cpp104
-rw-r--r--db/mms.h38
-rw-r--r--db/pdfile.cpp2
-rw-r--r--util/httpclient.cpp45
-rw-r--r--util/httpclient.h14
7 files changed, 220 insertions, 5 deletions
diff --git a/SConstruct b/SConstruct
index b2880c81295..2fa772452dc 100644
--- a/SConstruct
+++ b/SConstruct
@@ -216,7 +216,7 @@ if GetOption( "extrapath" ) is not None:
# ------ SOURCE FILE SETUP -----------
commonFiles = Split( "stdafx.cpp buildinfo.cpp db/jsobj.cpp db/json.cpp db/commands.cpp db/lasterror.cpp db/nonce.cpp db/queryutil.cpp shell/mongo.cpp" )
-commonFiles += [ "util/background.cpp" , "util/mmap.cpp" , "util/sock.cpp" , "util/util.cpp" , "util/message.cpp" , "util/assert_util.cpp" ]
+commonFiles += [ "util/background.cpp" , "util/mmap.cpp" , "util/sock.cpp" , "util/util.cpp" , "util/message.cpp" , "util/assert_util.cpp" , "util/httpclient.cpp" ]
commonFiles += Glob( "util/*.c" )
commonFiles += Split( "client/connpool.cpp client/dbclient.cpp client/model.cpp" )
commonFiles += [ "scripting/engine.cpp" ]
@@ -729,7 +729,7 @@ testEnv.Prepend( LIBPATH=["."] )
# main db target
-mongod = env.Program( "mongod" , commonFiles + coreDbFiles + serverOnlyFiles + [ "db/db.cpp" ] )
+mongod = env.Program( "mongod" , commonFiles + coreDbFiles + serverOnlyFiles + [ "db/db.cpp" , "db/mms.cpp" ] )
Default( mongod )
# tools
diff --git a/db/db.cpp b/db/db.cpp
index 351ec447e0e..d711f2d583c 100644
--- a/db/db.cpp
+++ b/db/db.cpp
@@ -36,6 +36,7 @@
#endif
#include "../scripting/engine.h"
+#include "mms.h"
namespace mongo {
@@ -361,6 +362,8 @@ namespace mongo {
log() << "opLogging = " << opLogging << endl;
_oplog.init();
+ mms.go();
+
#if 0
{
stringstream indexpath;
@@ -467,6 +470,9 @@ int main(int argc, char* argv[], char *envp[] )
("remove", "remove mongodb service")
("service", "start mongodb service")
#endif
+ ( "mms-token" , po::value<string>() , "account token for mongo monitoring server" )
+ ( "mms-name" , po::value<string>() , "server name mongo monitoring server" )
+ ( "mms-interval" , po::value<int>()->default_value(30) , "ping interval for mongo monitoring server (defaut 30)" )
;
replication_options.add_options()
@@ -560,7 +566,7 @@ int main(int argc, char* argv[], char *envp[] )
cout << visible_options << endl;
return 0;
}
-
+
if (params.count("help")) {
show_help_text(visible_options);
return 0;
@@ -681,6 +687,14 @@ int main(int argc, char* argv[], char *envp[] )
setRecCacheSize(x);
}
+ if ( params.count( "mms-token" ) ){
+ mms.setToken( params["mms-token"].as<string>() );
+ }
+ if ( params.count( "mms-name" ) ){
+ mms.setName( params["mms-name"].as<string>() );
+ }
+ mms.setPingInterval( params["mms-interval"].as<int>() );
+
if (params.count("command")) {
vector<string> command = params["command"].as< vector<string> >();
@@ -718,7 +732,7 @@ int main(int argc, char* argv[], char *envp[] )
cout << visible_options << endl;
return 0;
}
-
+
#if defined(_WIN32)
if ( installService ) {
if ( !ServiceController::installService( L"MongoDB", L"Mongo DB", L"Mongo DB Server", argc, argv ) )
diff --git a/db/mms.cpp b/db/mms.cpp
new file mode 100644
index 00000000000..15a3760cb1d
--- /dev/null
+++ b/db/mms.cpp
@@ -0,0 +1,104 @@
+// mms.cpp
+
+#include "mms.h"
+#include "db.h"
+#include "instance.h"
+#include "../util/httpclient.h"
+
+namespace mongo {
+
+ MMS::MMS() :
+ baseurl( "http://mms.10gen.com/ping/" ) , secsToSleep(1) , token( "" ) , name( "" ) {
+ }
+
+ MMS::~MMS(){
+
+ }
+
+ void MMS::run(){
+
+ if ( token.size() == 0 && name.size() == 0 ){
+ log(1) << "mms not configured" << endl;
+ return;
+ }
+
+ if ( token.size() == 0 ){
+ log() << "no token for mms - not running" << endl;
+ return;
+ }
+
+ if ( name.size() == 0 ){
+ log() << "no name for mms - not running" << endl;
+ return;
+ }
+
+ log() << "mms monitor staring... token:" << token << " name:" << name << " interval: " << secsToSleep << endl;
+
+ unsigned long long lastTime = 0;
+ unsigned long long lastLockTime = 0;
+
+ while ( 1 ){
+ sleepsecs( secsToSleep );
+
+ stringstream url;
+ url << baseurl << token << "?";
+ url << "monitor_name=" << name << "&";
+ url << "version=" << versionString << "&";
+ url << "git_hash=" << gitVersion() << "&";
+
+ { //percent_locked
+ unsigned long long time = curTimeMicros64();
+ unsigned long long start , lock;
+ dbMutexInfo.timingInfo( start , lock );
+ if ( lastTime ){
+ double timeDiff = time - lastTime;
+ double lockDiff = lock - lastLockTime;
+ url << "percent_locked=" << (int)ceil( 100 * ( lockDiff / timeDiff ) ) << "&";
+ }
+ lastTime = time;
+ lastLockTime = lock;
+ }
+
+ vector< string > dbNames;
+ getDatabaseNames( dbNames );
+ boost::intmax_t totalSize = 0;
+ for ( vector< string >::iterator i = dbNames.begin(); i != dbNames.end(); ++i ) {
+ boost::intmax_t size = dbSize( i->c_str() );
+ totalSize += size;
+ }
+ url << "data_size=" << totalSize / ( 1024 * 1024 ) << "&";
+
+
+
+ /* TODO:
+ message_operations
+ update_operations
+ insert_operations
+ get_more_operations
+ delete_operations
+ kill_cursors_operations
+ */
+
+
+ log(1) << "mms url: " << url.str() << endl;
+
+ try {
+ HttpClient c;
+ map<string,string> headers;
+ stringstream ss;
+ int rc = c.get( url.str() , headers , ss );
+ log(1) << "\t response code: " << rc << endl;
+ if ( rc != 200 ){
+ log() << "mms error response code:" << rc << endl;
+ log(1) << "mms error body:" << ss.str() << endl;
+ }
+ }
+ catch ( std::exception& e ){
+ log() << "mms get exception: " << e.what() << endl;
+ }
+ }
+ }
+
+
+ MMS mms;
+}
diff --git a/db/mms.h b/db/mms.h
new file mode 100644
index 00000000000..4a868bf512c
--- /dev/null
+++ b/db/mms.h
@@ -0,0 +1,38 @@
+// mms.h
+
+#pragma once
+
+#include "../stdafx.h"
+#include "../util/background.h"
+
+namespace mongo {
+
+ class MMS : public BackgroundJob {
+ public:
+
+ MMS();
+ ~MMS();
+
+ /**
+ e.g. http://mms.10gen.com/ping/
+ */
+ void setBaseUrl( const string& host );
+
+ void setToken( const string& s ){ token = s; }
+ void setName( const string& s ){ name = s; }
+
+ void setPingInterval( int seconds ){ secsToSleep = seconds; }
+
+ void run();
+
+ private:
+ string baseurl;
+ int secsToSleep;
+
+ string token;
+ string name;
+
+ };
+
+ extern MMS mms;
+}
diff --git a/db/pdfile.cpp b/db/pdfile.cpp
index afae9561aca..c9417ee99a9 100644
--- a/db/pdfile.cpp
+++ b/db/pdfile.cpp
@@ -1562,7 +1562,7 @@ namespace mongo {
bool ok = false;
BOOST_CHECK_EXCEPTION( ok = fo.apply( q ) );
if ( ok )
- log( 1 ) << fo.op() << " file " << q.string() << '\n';
+ log(2) << fo.op() << " file " << q.string() << '\n';
int i = 0;
int extra = 10; // should not be necessary, this is defensive in case there are missing files
while ( 1 ) {
diff --git a/util/httpclient.cpp b/util/httpclient.cpp
new file mode 100644
index 00000000000..7b20303048e
--- /dev/null
+++ b/util/httpclient.cpp
@@ -0,0 +1,45 @@
+// httpclient.cpp
+
+#include "httpclient.h"
+
+namespace mongo {
+
+ int HttpClient::get( string url , map<string,string>& headers, stringstream& data ){
+ uassert( "invalid url" , url.find( "http://" ) == 0 );
+ url = url.substr( 7 );
+
+ string host , path;
+ if ( url.find( "/" ) == string::npos ){
+ host = url;
+ path = "/";
+ }
+ else {
+ host = url.substr( 0 , url.find( "/" ) );
+ path = url.substr( url.find( "/" ) );
+ }
+
+ int port = 80;
+ uassert( "non standard port not supported yet" , host.find( ":" ) == string::npos );
+
+ cout << "host [" << host << "]" << endl;
+ cout << "path [" << path << "]" << endl;
+ cout << "port: " << port << endl;
+
+ string req;
+ {
+ stringstream ss;
+ ss << "GET " << path << " HTTP/1.1\r\n";
+ ss << "Host: " << host << "\r\n";
+ ss << "Connection: Close\r\n";
+ ss << "User-Agent: mongodb http client\r\n";
+ ss << "\r\n";
+
+ req = ss.str();
+ }
+
+ cout << req << endl;
+
+ return -1;
+ }
+
+}
diff --git a/util/httpclient.h b/util/httpclient.h
new file mode 100644
index 00000000000..d783c5a9ae0
--- /dev/null
+++ b/util/httpclient.h
@@ -0,0 +1,14 @@
+// httpclient.h
+
+#pragma once
+
+#include "../stdafx.h"
+
+namespace mongo {
+
+ class HttpClient {
+ public:
+ int get( string url , map<string,string>& headers, stringstream& data );
+ };
+}
+