void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const { vector<BSONObj> v; const Member *_self = this->_self; assert( _self ); // add self { BSONObjBuilder bb; bb.append("_id", (int) _self->id()); bb.append("name", _self->fullName()); bb.append("health", 1.0); bb.append("state", (int) box.getState().s); bb.append("stateStr", box.getState().toString()); bb.appendTimestamp("optime", lastOpTimeWritten.asDate()); bb.appendDate("optimeDate", lastOpTimeWritten.getSecs() * 1000LL); string s = _self->lhb(); if( !s.empty() ) bb.append("errmsg", s); bb.append("self", true); v.push_back(bb.obj()); } Member *m =_members.head(); while( m ) { BSONObjBuilder bb; bb.append("_id", (int) m->id()); bb.append("name", m->fullName()); double h = m->hbinfo().health; bb.append("health", h); bb.append("state", (int) m->state().s); if( h == 0 ) { // if we can't connect the state info is from the past and could be confusing to show bb.append("stateStr", "(not reachable/healthy)"); } else { bb.append("stateStr", m->state().toString()); } bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0)); bb.appendTimestamp("optime", m->hbinfo().opTime.asDate()); bb.appendDate("optimeDate", m->hbinfo().opTime.getSecs() * 1000LL); bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat); bb.append("ping", m->hbinfo().ping); string s = m->lhb(); if( !s.empty() ) bb.append("errmsg", s); v.push_back(bb.obj()); m = m->next(); } sort(v.begin(), v.end()); b.append("set", name()); b.appendTimeT("date", time(0)); b.append("myState", box.getState().s); if (_currentSyncTarget) { b.append("syncingTo", _currentSyncTarget->fullName()); } b.append("members", v); if( replSetBlind ) b.append("blind",true); // to avoid confusion if set...normally never set except for testing. }
// Create the date of hour/day/month document BSONObj FXtoBSON::find(struct tm tempTM, const char &a){ BSONObjBuilder FIND; switch(a){ case 'h': tempTM.tm_min = 0; FIND.appendTimeT("Date", timegm(&tempTM)); break; case 'd': tempTM.tm_min = 0; tempTM.tm_hour = 0; FIND.appendTimeT("Date", timegm(&tempTM)); break; case 'm': tempTM.tm_min = 0; tempTM.tm_hour = 0; tempTM.tm_mday = 1; FIND.appendTimeT("Date", timegm(&tempTM)); break; case 'y': tempTM.tm_min = 0; tempTM.tm_hour = 0; tempTM.tm_mday = 1; tempTM.tm_mon = 0; FIND.appendTimeT("Date", timegm(&tempTM)); break; } return FIND.obj(); }
void MongoGliderDataExporter::filesProcessed(set<string>& fileNames){ set<string>::iterator it; for(it=fileNames.begin(); it != fileNames.end(); it++){ struct stat fileDetails; BSONObjBuilder b; if(stat((*it).c_str(),&fileDetails) == 0){ b.appendTimeT("date_processed",(long long int)this->currentTime); b.appendTimeT("access_time",fileDetails.st_atime); b.appendTimeT("modify_time",fileDetails.st_mtime); b.appendTimeT("create_time",fileDetails.st_ctime); b.appendTimeT("file_size",fileDetails.st_size); size_t lastSlash = (*it).rfind("/"); string name = (*it); if(lastSlash != string::npos){ name = (*it).substr(lastSlash+1); } b.append("name",name); try{ db->insert("GDAM."+gliderName+".processed_files",b.obj()); } catch (DBException &e){ fprintf(stderr,"Unable to insert value: %s.\r\n",e.what()); } } else { fprintf(stderr,"Cannot stat file at %s.\r\n",(*it).c_str()); } } }
void logStartup() { BSONObjBuilder toLog; stringstream id; id << getHostNameCached() << "-" << jsTime(); toLog.append( "_id", id.str() ); toLog.append( "hostname", getHostNameCached() ); toLog.appendTimeT( "startTime", time(0) ); toLog.append( "startTimeLocal", dateToCtimeString(curTimeMillis64()) ); toLog.append("cmdLine", serverGlobalParams.parsedOpts); toLog.append( "pid", ProcessId::getCurrent().asLongLong() ); BSONObjBuilder buildinfo( toLog.subobjStart("buildinfo")); appendBuildInfo(buildinfo); buildinfo.doneFast(); BSONObj o = toLog.obj(); Lock::GlobalWrite lk; DBDirectClient c; const char* name = "local.startup_log"; c.createCollection( name, 10 * 1024 * 1024, true ); c.insert( name, o); }
void MongoGliderDataExporter::processReading(map<string,double>& readings){ BSONObjBuilder b; // Pull out times double timestamp = 0; if(readings.count("m_present_time-timestamp") > 0){ timestamp = readings["m_present_time-timestamp"]; readings.erase("m_present_time-timestamp"); } if(readings.count("sci_m_present_time-timestamp") > 0){ timestamp = readings["sci_m_present_time-timestamp"]; readings.erase("sci_m_present_time-timestamp"); } b.appendTimeT("timestamp",(time_t)timestamp); string gpsFields[3] = {"m_gps_lon-lon","m_lon-lon","c_wpt_lon-lon"}; for(int i=0; i < 3; i++){ pullOutGPS(b,readings,gpsFields[i]); } map<string,double>::iterator it; for(it=readings.begin(); it != readings.end(); it++){ b.append((*it).first,(*it).second); } try{ db->insert("GDAM."+gliderName+"."+fliFileType+sciFileType,b.obj()); } catch (DBException &e) { fprintf(stderr,"Unable to insert value: %s.\r\n",e.what()); } }
void MockReplicaSet::mockReplSetGetStatusCmd() { // Copied from ReplSetImpl::_summarizeStatus for (ReplNodeMap::iterator nodeIter = _nodeMap.begin(); nodeIter != _nodeMap.end(); ++nodeIter) { MockRemoteDBServer* node = nodeIter->second; vector<BSONObj> hostsField; BSONObjBuilder fullStatBuilder; { BSONObjBuilder selfStatBuilder; selfStatBuilder.append("name", node->getServerAddress()); selfStatBuilder.append("health", 1.0); selfStatBuilder.append("state", getState(node->getServerAddress())); selfStatBuilder.append("self", true); // TODO: _id, stateStr, uptime, optime, optimeDate, maintenanceMode, errmsg hostsField.push_back(selfStatBuilder.obj()); } for (ReplicaSetConfig::MemberIterator member = _replConfig.membersBegin(); member != _replConfig.membersEnd(); ++member) { MockRemoteDBServer* hostNode = getNode(member->getHostAndPort().toString()); if (hostNode == node) { continue; } BSONObjBuilder hostMemberBuilder; // TODO: _id, stateStr, uptime, optime, optimeDate, lastHeartbeat, pingMs // errmsg, authenticated hostMemberBuilder.append("name", hostNode->getServerAddress()); const double health = hostNode->isRunning() ? 1.0 : 0.0; hostMemberBuilder.append("health", health); hostMemberBuilder.append("state", getState(hostNode->getServerAddress())); hostsField.push_back(hostMemberBuilder.obj()); } sort(hostsField.begin(), hostsField.end()); // TODO: syncingTo fullStatBuilder.append("set", _setName); fullStatBuilder.appendTimeT("date", time(0)); fullStatBuilder.append("myState", getState(node->getServerAddress())); fullStatBuilder.append("members", hostsField); fullStatBuilder.append("ok", true); node->setCommandReply("replSetGetStatus", fullStatBuilder.done()); } }
void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const { vector<BSONObj> v; // add self { HostAndPort h(getHostName(), cmdLine.port); BSONObjBuilder bb; bb.append("_id", (int) _self->id()); bb.append("name", h.toString()); bb.append("health", 1.0); bb.append("state", (int) box.getState().s); string s = _self->lhb(); if( !s.empty() ) bb.append("errmsg", s); bb.append("self", true); v.push_back(bb.obj()); } Member *m =_members.head(); while( m ) { BSONObjBuilder bb; bb.append("_id", (int) m->id()); bb.append("name", m->fullName()); bb.append("health", m->hbinfo().health); bb.append("state", (int) m->state().s); bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0)); bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat); string s = m->lhb(); if( !s.empty() ) bb.append("errmsg", s); v.push_back(bb.obj()); m = m->next(); } sort(v.begin(), v.end()); b.append("set", name()); b.appendTimeT("date", time(0)); b.append("myState", box.getState().s); b.append("members", v); }
static void logStartup() { BSONObjBuilder toLog; stringstream id; id << getHostNameCached() << "-" << jsTime().asInt64(); toLog.append("_id", id.str()); toLog.append("hostname", getHostNameCached()); toLog.appendTimeT("startTime", time(0)); toLog.append("startTimeLocal", dateToCtimeString(Date_t::now())); toLog.append("cmdLine", serverGlobalParams.parsedOpts); toLog.append("pid", ProcessId::getCurrent().asLongLong()); BSONObjBuilder buildinfo(toLog.subobjStart("buildinfo")); appendBuildInfo(buildinfo); appendStorageEngineList(&buildinfo); buildinfo.doneFast(); BSONObj o = toLog.obj(); OperationContextImpl txn; ScopedTransaction transaction(&txn, MODE_X); Lock::GlobalWrite lk(txn.lockState()); AutoGetOrCreateDb autoDb(&txn, "local", mongo::MODE_X); Database* db = autoDb.getDb(); const std::string ns = "local.startup_log"; Collection* collection = db->getCollection(ns); WriteUnitOfWork wunit(&txn); if (!collection) { BSONObj options = BSON("capped" << true << "size" << 10 * 1024 * 1024); bool shouldReplicateWrites = txn.writesAreReplicated(); txn.setReplicatedWrites(false); ON_BLOCK_EXIT(&OperationContext::setReplicatedWrites, &txn, shouldReplicateWrites); uassertStatusOK(userCreateNS(&txn, db, ns, options)); collection = db->getCollection(ns); } invariant(collection); uassertStatusOK(collection->insertDocument(&txn, o, false).getStatus()); wunit.commit(); }
void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const { vector<BSONObj> v; const Member *_self = this->_self; verify( _self ); MemberState myState = box.getState(); // add self { BSONObjBuilder bb; bb.append("_id", (int) _self->id()); bb.append("name", _self->fullName()); bb.append("health", 1.0); bb.append("state", (int)myState.s); bb.append("stateStr", myState.toString()); bb.append("uptime", (unsigned)(time(0) - cmdLine.started)); if (!_self->config().arbiterOnly) { GTID lastLive; GTID lastUnapplied; GTID minLive; GTID minUnapplied; gtidManager->getGTIDs( &lastLive, &lastUnapplied, &minLive, &minUnapplied ); bb.appendDate("optimeDate", gtidManager->getCurrTimestamp()); bb.append("lastGTID", lastLive.toString()); bb.append("lastUnappliedGTID", lastUnapplied.toString()); bb.append("minLiveGTID", minLive.toString()); bb.append("minUnappliedGTID", minUnapplied.toString()); bb.append("oplogVersion", ReplSetConfig::OPLOG_VERSION); } int maintenance = _maintenanceMode; if (maintenance) { bb.append("maintenanceMode", maintenance); } if (theReplSet) { string s = theReplSet->hbmsg(); if( !s.empty() ) bb.append("errmsg", s); } bb.append("self", true); v.push_back(bb.obj()); } Member *m =_members.head(); while( m ) { BSONObjBuilder bb; bb.append("_id", (int) m->id()); bb.append("name", m->fullName()); double h = m->hbinfo().health; bb.append("health", h); bb.append("state", (int) m->state().s); if( h == 0 ) { // if we can't connect the state info is from the past and could be confusing to show bb.append("stateStr", "(not reachable/healthy)"); } else { bb.append("stateStr", m->state().toString()); } bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0)); if (!m->config().arbiterOnly) { bb.appendDate("optimeDate", m->hbinfo().opTime); bb.append("lastGTID", m->hbinfo().gtid.toString()); bb.append("lastUnappliedGTID", m->hbinfo().lastUnappliedGTID.toString()); bb.append("minLiveGTID", m->hbinfo().minLiveGTID.toString()); bb.append("minUnappliedGTID", m->hbinfo().minUnappliedGTID.toString()); bb.append("oplogVersion", m->hbinfo().oplogVersion); } bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat); bb.appendTimeT("lastHeartbeatRecv", m->getLastRecvHeartbeat()); bb.append("pingMs", m->hbinfo().ping); string s = m->lhb(); if( !s.empty() ) bb.append("lastHeartbeatMessage", s); if (m->hbinfo().authIssue) { bb.append("authenticated", false); } string syncingTo = m->hbinfo().syncingTo; if (!syncingTo.empty()) { bb.append("syncingTo", syncingTo); } v.push_back(bb.obj()); m = m->next(); } sort(v.begin(), v.end()); b.append("set", name()); b.appendTimeT("date", time(0)); b.append("myState", myState.s); const Member *syncTarget = BackgroundSync::get()->getSyncTarget(); if ( syncTarget && (myState != MemberState::RS_PRIMARY) && (myState != MemberState::RS_SHUNNED) ) { b.append("syncingTo", syncTarget->fullName()); } b.append("members", v); if( replSetBlind ) b.append("blind",true); // to avoid confusion if set...normally never set except for testing. }
void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const { vector<BSONObj> v; const Member *_self = this->_self; verify( _self ); MemberState myState = box.getState(); const HostAndPort syncTarget = BackgroundSync::get()->getSyncTarget(); // add self { BSONObjBuilder bb; bb.append("_id", (int) _self->id()); bb.append("name", _self->fullName()); bb.append("health", 1.0); bb.append("state", (int)myState.s); bb.append("stateStr", myState.toString()); bb.append("uptime", (unsigned)(time(0) - serverGlobalParams.started)); if (!_self->config().arbiterOnly) { bb.appendTimestamp("optime", lastOpTimeWritten.asDate()); bb.appendDate("optimeDate", lastOpTimeWritten.getSecs() * 1000LL); } int maintenance = _maintenanceMode; if (maintenance) { bb.append("maintenanceMode", maintenance); } if ( !syncTarget.empty() && (myState != MemberState::RS_PRIMARY) && (myState != MemberState::RS_REMOVED) ) { bb.append("syncingTo", syncTarget.toString()); } if (theReplSet) { string s = theReplSet->hbmsg(); if( !s.empty() ) bb.append("infoMessage", s); if (myState == MemberState::RS_PRIMARY) { bb.appendTimestamp("electionTime", theReplSet->getElectionTime().asDate()); bb.appendDate("electionDate", theReplSet->getElectionTime().getSecs() * 1000LL); } } bb.append("self", true); v.push_back(bb.obj()); } Member *m =_members.head(); while( m ) { BSONObjBuilder bb; bb.append("_id", (int) m->id()); bb.append("name", m->fullName()); double h = m->hbinfo().health; bb.append("health", h); bb.append("state", (int) m->state().s); if( h == 0 ) { // if we can't connect the state info is from the past and could be confusing to show bb.append("stateStr", "(not reachable/healthy)"); } else { bb.append("stateStr", m->state().toString()); } bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0)); if (!m->config().arbiterOnly) { bb.appendTimestamp("optime", m->hbinfo().opTime.asDate()); bb.appendDate("optimeDate", m->hbinfo().opTime.getSecs() * 1000LL); } bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat); bb.appendTimeT("lastHeartbeatRecv", m->hbinfo().lastHeartbeatRecv); bb.append("pingMs", m->hbinfo().ping); string s = m->lhb(); if( !s.empty() ) bb.append("lastHeartbeatMessage", s); if (m->hbinfo().authIssue) { bb.append("authenticated", false); } string syncingTo = m->hbinfo().syncingTo; if (!syncingTo.empty()) { bb.append("syncingTo", syncingTo); } if (m->state() == MemberState::RS_PRIMARY) { bb.appendTimestamp("electionTime", m->hbinfo().electionTime.asDate()); bb.appendDate("electionDate", m->hbinfo().electionTime.getSecs() * 1000LL); } v.push_back(bb.obj()); m = m->next(); } sort(v.begin(), v.end()); b.append("set", name()); b.appendTimeT("date", time(0)); b.append("myState", myState.s); if ( !syncTarget.empty() && (myState != MemberState::RS_PRIMARY) && (myState != MemberState::RS_REMOVED) ) { b.append("syncingTo", syncTarget.toString()); } b.append("members", v); }
void ReplSetImpl::_summarizeStatus(BSONObjBuilder& b) const { vector<BSONObj> v; const Member *_self = this->_self; verify( _self ); MemberState myState = box.getState(); // add self { BSONObjBuilder bb; bb.append("_id", (int) _self->id()); bb.append("name", _self->fullName()); bb.append("health", 1.0); bb.append("state", (int)myState.s); bb.append("stateStr", myState.toString()); bb.append("uptime", (unsigned)(time(0) - cmdLine.started)); if (!_self->config().arbiterOnly) { bb.appendTimestamp("optime", lastOpTimeWritten.asDate()); bb.appendDate("optimeDate", lastOpTimeWritten.getSecs() * 1000LL); } int maintenance = _maintenanceMode; if (maintenance) { bb.append("maintenanceMode", maintenance); } if (theReplSet) { string s = theReplSet->hbmsg(); if( !s.empty() ) bb.append("errmsg", s); } bb.append("self", true); v.push_back(bb.obj()); } Member *m =_members.head(); while( m ) { BSONObjBuilder bb; bb.append("_id", (int) m->id()); bb.append("name", m->fullName()); double h = m->hbinfo().health; bb.append("health", h); bb.append("state", (int) m->state().s); if( h == 0 ) { // if we can't connect the state info is from the past and could be confusing to show bb.append("stateStr", "(not reachable/healthy)"); } else { bb.append("stateStr", m->state().toString()); } bb.append("uptime", (unsigned) (m->hbinfo().upSince ? (time(0)-m->hbinfo().upSince) : 0)); if (!m->config().arbiterOnly) { bb.appendTimestamp("optime", m->hbinfo().opTime.asDate()); bb.appendDate("optimeDate", m->hbinfo().opTime.getSecs() * 1000LL); } bb.appendTimeT("lastHeartbeat", m->hbinfo().lastHeartbeat); bb.append("pingMs", m->hbinfo().ping); string s = m->lhb(); if( !s.empty() ) bb.append("errmsg", s); if (m->hbinfo().authIssue) { bb.append("authenticated", false); } v.push_back(bb.obj()); m = m->next(); } sort(v.begin(), v.end()); b.append("set", name()); b.appendTimeT("date", time(0)); b.append("myState", myState.s); const Member *syncTarget = _currentSyncTarget; if ( syncTarget && (myState != MemberState::RS_PRIMARY) && (myState != MemberState::RS_SHUNNED) ) { b.append("syncingTo", syncTarget->fullName()); } b.append("members", v); if( replSetBlind ) b.append("blind",true); // to avoid confusion if set...normally never set except for testing. }