0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00
This commit is contained in:
Eliot Horowitz 2010-02-12 10:00:50 -05:00
parent 4b372247f1
commit 9f06af5d7b

View File

@ -29,7 +29,7 @@ namespace mongo {
/** Mongo Monitoring Service
if enabled, this runs in the background ands pings mss
*/
*/
class MMS : public BackgroundJob , Module {
public:
@ -45,7 +45,7 @@ namespace mongo {
}
~MMS(){}
void config( program_options::variables_map& params ){
if ( params.count( "mms-token" ) ){
_token = params["mms-token"].as<string>();
@ -57,86 +57,86 @@ namespace mongo {
}
void run(){
if ( _token.size() == 0 && _name.size() == 0 ){
log(1) << "mms not configured" << endl;
return;
}
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 ( _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;
}
if ( _name.size() == 0 ){
log() << "no name for mms - not running" << endl;
return;
}
log() << "mms monitor staring... token:" << _token << " name:" << _name << " interval: " << _secsToSleep << endl;
log() << "mms monitor staring... token:" << _token << " name:" << _name << " interval: " << _secsToSleep << endl;
unsigned long long lastTime = 0;
unsigned long long lastLockTime = 0;
unsigned long long lastTime = 0;
unsigned long long lastLockTime = 0;
while ( ! inShutdown() ){
sleepsecs( _secsToSleep );
while ( ! inShutdown() ){
sleepsecs( _secsToSleep );
stringstream url;
url << _baseurl << _token << "?";
url << "monitor_name=" << _name << "&";
url << "version=" << versionString << "&";
url << "git_hash=" << gitVersion() << "&";
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;
dbMutex.info().getTimingInfo( start , lock );
if ( lastTime ){
double timeDiff = (double) (time - lastTime);
double lockDiff = (double) (lock - lastLockTime);
url << "percent_locked=" << (int)ceil( 100 * ( lockDiff / timeDiff ) ) << "&";
{ //percent_locked
unsigned long long time = curTimeMicros64();
unsigned long long start , lock;
dbMutex.info().getTimingInfo( start , lock );
if ( lastTime ){
double timeDiff = (double) (time - lastTime);
double lockDiff = (double) (lock - lastLockTime);
url << "percent_locked=" << (int)ceil( 100 * ( lockDiff / timeDiff ) ) << "&";
}
lastTime = time;
lastLockTime = lock;
}
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 ) << "&";
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
*/
/* TODO:
message_operations
update_operations
insert_operations
get_more_operations
delete_operations
kill_cursors_operations
*/
log(1) << "mms url: " << url.str() << endl;
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;
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;
}
}
catch ( std::exception& e ){
log() << "mms get exception: " << e.what() << endl;
}
}
}
void init(){ go(); }
@ -152,7 +152,7 @@ namespace mongo {
string _token;
string _name;
} /* mms */;
} mms ;
}