Пример #1
0
        public static ReplicaSetStatus GetReplicaSetStatus()
        {
            ReplicaSetStatus status;
            var settings = ConnectionUtilities.GetConnectionSettings( );
            settings.SlaveOk = true;
            var server = MongoServer.Create(settings);
            try
            {
                var result = server["admin"].RunCommand("replSetGetStatus");
                var response = result.Response;

                BsonValue startupStatus;
                if (response.TryGetValue("startupStatus", out startupStatus))
                {
                    status = new ReplicaSetStatus("Replica Set Initializing");
                    return status;
                }

                status = new ReplicaSetStatus((string) response.GetValue("set"));
                var value = response.GetElement("members");
                var members = value.Value.AsBsonArray;
                foreach (BsonDocument member in members)
                {
                    var node = new ServerStatus();
                    foreach (BsonElement bsonElement in member.Elements)
                    {
                        switch (bsonElement.Name)
                        {
                            case "_id":
                                node.id = bsonElement.Value.ToInt32();
                                break;
                            case "name":
                                node.name = bsonElement.Value.ToString();
                                break;
                            case "health":
                                node.health = bsonElement.Value.ToInt32() == 0 ? "DOWN" : "UP";
                                break;
                            case "state":
                                node.state = bsonElement.Value.ToInt32();
                                if (node.state == 1)
                                {
                                    node.lastHeartbeat = "Not Applicable";
                                    node.pingMS = "Not Applicable";
                                }
                                break;
                            case "stateStr":
                                node.stateStr = bsonElement.Value.ToString();
                                break;
                            case "uptime":
                                break;
                            case "lastHeartbeat":
                                var hearbeat = bsonElement.Value.AsDateTime;
                                if (hearbeat != null)
                                {
                                    node.lastHeartbeat = hearbeat.ToString("yyyy-MM-dd HH:mm tt");
                                }
                                break;
                            case "optimeDate":
                                node.optimeDate = bsonElement.Value.AsDateTime;
                                break;
                            case "pingMs":
                                Double pingTime = bsonElement.Value.AsInt32;
                                node.pingMS = pingTime.ToString(CultureInfo.InvariantCulture);
                                break;
                        }
                    }
                    status.servers.Add(node);
                }
            }
            catch
            {
                status = new ReplicaSetStatus("Replica Set Unavailable");
            }
            return status;
        }
Пример #2
0
        public static ReplicaSetStatus GetReplicaSetStatus()
        {
            ReplicaSetStatus status;
            var settings = ConnectionUtilities.GetConnectionSettings( );

            settings.SlaveOk = true;
            var server = MongoServer.Create(settings);

            try
            {
                var result   = server["admin"].RunCommand("replSetGetStatus");
                var response = result.Response;

                BsonValue startupStatus;
                if (response.TryGetValue("startupStatus", out startupStatus))
                {
                    status = new ReplicaSetStatus("Replica Set Initializing");
                    return(status);
                }

                status = new ReplicaSetStatus((string)response.GetValue("set"));
                var value   = response.GetElement("members");
                var members = value.Value.AsBsonArray;
                foreach (BsonDocument member in members)
                {
                    var node = new ServerStatus();
                    foreach (BsonElement bsonElement in member.Elements)
                    {
                        switch (bsonElement.Name)
                        {
                        case "_id":
                            node.id = bsonElement.Value.ToInt32();
                            break;

                        case "name":
                            node.name = bsonElement.Value.ToString();
                            break;

                        case "health":
                            node.health = bsonElement.Value.ToInt32() == 0 ? "DOWN" : "UP";
                            break;

                        case "state":
                            node.state = bsonElement.Value.ToInt32();
                            if (node.state == 1)
                            {
                                node.lastHeartbeat = "Not Applicable";
                                node.pingMS        = "Not Applicable";
                            }
                            break;

                        case "stateStr":
                            node.stateStr = bsonElement.Value.ToString();
                            break;

                        case "uptime":
                            break;

                        case "lastHeartbeat":
                            var hearbeat = bsonElement.Value.AsDateTime;
                            if (hearbeat != null)
                            {
                                node.lastHeartbeat = hearbeat.ToString("yyyy-MM-dd HH:mm tt");
                            }
                            break;

                        case "optimeDate":
                            node.optimeDate = bsonElement.Value.AsDateTime;
                            break;

                        case "pingMs":
                            Double pingTime = bsonElement.Value.AsInt32;
                            node.pingMS = pingTime.ToString(CultureInfo.InvariantCulture);
                            break;
                        }
                    }
                    status.servers.Add(node);
                }
            }
            catch
            {
                status = new ReplicaSetStatus("Replica Set Unavailable");
            }
            return(status);
        }
Пример #3
0
        public static ReplicaSetStatus GetReplicaSetStatus()
        {
            ReplicaSetStatus status;
            var settings = ConnectionUtilities.GetMongoClientSettings(ReadPreference.SecondaryPreferred);
            var client   = new MongoClient(settings);
            var server   = client.GetServer();

            try
            {
                var result   = server.GetDatabase("admin").RunCommand("replSetGetStatus");
                var response = result.Response;

                BsonValue startupStatus;
                if (response.TryGetValue("startupStatus", out startupStatus))
                {
                    status = new ReplicaSetStatus("Replica Set Initializing");
                    return(status);
                }

                status = new ReplicaSetStatus((string)response.GetValue("set"));
                var value   = response.GetElement("members");
                var members = value.Value.AsBsonArray;
                foreach (BsonDocument member in members)
                {
                    var node = new ServerStatus();
                    foreach (BsonElement bsonElement in member.Elements)
                    {
                        switch (bsonElement.Name)
                        {
                        case "_id":
                            node.id = bsonElement.Value.ToInt32();
                            break;

                        case "name":
                            node.name = bsonElement.Value.ToString();
                            break;

                        case "health":
                            node.health = bsonElement.Value.ToInt32() == 0 ? "DOWN" : "UP";
                            break;

                        case "state":
                            node.state = bsonElement.Value.ToInt32();
                            if (node.state == 1)
                            {
                                node.lastHeartbeat = "Not Applicable";
                                node.pingMS        = "Not Applicable";
                            }
                            break;

                        case "stateStr":
                            node.stateStr = bsonElement.Value.ToString();
                            break;

                        case "uptime":
                            break;

                        case "lastHeartbeat":
                            var hearbeat = bsonElement.Value.ToUniversalTime();
                            if (hearbeat != null)
                            {
                                node.lastHeartbeat = hearbeat.ToString("yyyy-MM-dd HH:mm tt");
                            }
                            break;

                        case "optimeDate":
                            node.optimeDate = bsonElement.Value.ToUniversalTime();
                            break;

                        case "pingMs":
                            Double pingTime = bsonElement.Value.AsInt32;
                            node.pingMS = pingTime.ToString(CultureInfo.InvariantCulture);
                            break;
                        }
                    }
                    status.servers.Add(node);
                }
            }
            catch (MongoException me)
            {
                status = new ReplicaSetStatus(string.Format(
                                                  "Replica Set Unavailable due to {0}", me.Message));
            }
            return(status);
        }
Пример #4
0
        public static ReplicaSetStatus GetReplicaSetStatus()
        {
            ReplicaSetStatus status;
            var settings = ConnectionUtilities.GetMongoClientSettings(ReadPreference.SecondaryPreferred);
            var client = new MongoClient(settings);
            var server = client.GetServer();
            try
            {
                var result = server.GetDatabase("admin").RunCommand("replSetGetStatus");
                var response = result.Response;

                BsonValue startupStatus;
                if (response.TryGetValue("startupStatus", out startupStatus))
                {
                    status = new ReplicaSetStatus("Replica Set Initializing");
                    return status;
                }

                status = new ReplicaSetStatus((string) response.GetValue("set"));
                var value = response.GetElement("members");
                var members = value.Value.AsBsonArray;
                foreach (BsonDocument member in members)
                {
                    var node = new ServerStatus();
                    foreach (BsonElement bsonElement in member.Elements)
                    {
                        switch (bsonElement.Name)
                        {
                            case "_id":
                                node.id = bsonElement.Value.ToInt32();
                                break;
                            case "name":
                                node.name = bsonElement.Value.ToString();
                                break;
                            case "health":
                                node.health = bsonElement.Value.ToInt32() == 0 ? "DOWN" : "UP";
                                break;
                            case "state":
                                node.state = bsonElement.Value.ToInt32();
                                if (node.state == 1)
                                {
                                    node.lastHeartbeat = "Not Applicable";
                                    node.pingMS = "Not Applicable";
                                }
                                break;
                            case "stateStr":
                                node.stateStr = bsonElement.Value.ToString();
                                break;
                            case "uptime":
                                break;
                            case "lastHeartbeat":
                                var hearbeat = bsonElement.Value.ToUniversalTime();
                                if (hearbeat != null)
                                {
                                    node.lastHeartbeat = hearbeat.ToString("yyyy-MM-dd HH:mm tt");
                                }
                                break;
                            case "optimeDate":
                                node.optimeDate = bsonElement.Value.ToUniversalTime();
                                break;
                            case "pingMs":
                                Double pingTime = bsonElement.Value.AsInt32;
                                node.pingMS = pingTime.ToString(CultureInfo.InvariantCulture);
                                break;
                        }
                    }
                    status.servers.Add(node);
                }
            }
            catch (MongoException me)
            {
                status = new ReplicaSetStatus(string.Format(
                    "Replica Set Unavailable due to {0}", me.Message));
            }
            return status;
        }