Esempio n. 1
0
    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);
    }
Esempio n. 2
0
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.
}
Esempio n. 3
0
    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.
    }