/// <summary> /// Tells the given server to start a new logfile and archive the old one. /// </summary> public ActionResult LogRotate(int id) { var server = ServerStatus.Get(id); if (server == null) { TempData["flashError"] = "That server does not exist."; return(RedirectToAction("Index", "Dashboard")); } var client = new MongoClient(string.Format( "mongodb://{0}/?slaveOk=true", server.Name)); var conn = client.GetServer(); try { var result = conn.GetDatabase("admin").RunCommand("logRotate"); } catch (MongoException e) { TempData["flashErrorTitle"] = "Error during log rotation"; TempData["flashError"] = e.Message; return(RedirectToAction("Index", "Dashboard")); } TempData["flashSuccess"] = "Logs rotated on " + server.Name + "."; return(RedirectToAction("Details", new { id = id })); }
/// <summary> /// Tells the given primary server to step down (elect another primary). /// </summary> public ActionResult StepDown(int id) { var server = ServerStatus.Get(id); if (server == null) { TempData["flashError"] = "That server does not exist."; return(RedirectToAction("Index", "Dashboard")); } var client = new MongoClient(string.Format("mongodb://{0}/", server.Name)); var conn = client.GetServer(); try { var result = conn.GetDatabase("admin").RunCommand("replSetStepDown"); return(RedirectToAction("Details", new { id = id })); } catch (EndOfStreamException) { // [PC] This occurs when the command succeeded - driver bug? TempData["flashSuccessTitle"] = "Stepdown succeeded"; TempData["flashSuccess"] = "It will take a few seconds for the replica set to come back online. Refresh the page manually."; return(RedirectToAction("Index", "Dashboard")); } catch (MongoException e) { TempData["flashErrorTitle"] = "Error during stepdown"; TempData["flashError"] = e.Message; return(RedirectToAction("Index", "Dashboard")); } }
//========================================================================= // // AJAX ACTIONS // //========================================================================= /// <summary> /// Fetches the instance log by connecting to its mongod server. /// This is fast and cheap, but won't work if the instance is down. /// </summary> public JsonResult GetServerLog(int id) { var server = ServerStatus.Get(id); var urlBuilder = new MongoUrlBuilder(); urlBuilder.ConnectTimeout = new TimeSpan(0, 0, 3); urlBuilder.Server = MongoServerAddress.Parse(server.Name); urlBuilder.ReadPreference = ReadPreference.SecondaryPreferred; var client = new MongoClient(urlBuilder.ToMongoUrl()); var conn = client.GetServer(); try { var command = new CommandDocument { { "getLog", "global" } }; var result = conn.GetDatabase("admin").RunCommand(command); return(Json(new { log = HtmlizeFromLogArray(result. Response["log"].AsBsonArray) }, JsonRequestBehavior.AllowGet)); } catch (MongoException e) { return(Json(new { error = e.Message }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Tells the given server to start a new logfile and archive the old one. /// </summary> public ActionResult LogRotate(int id) { var server = ServerStatus.Get(id); if (server == null) { TempData["flashError"] = "That server does not exist."; return(RedirectToAction("Index", "Dashboard")); } var mongo = MongoServer.Create("mongodb://" + server.Name + "/?slaveOk=true"); try { var result = mongo["admin"].RunCommand("logRotate"); } catch (MongoException e) { TempData["flashErrorTitle"] = "Error during log rotation"; TempData["flashError"] = e.Message; return(RedirectToAction("Index", "Dashboard")); } TempData["flashSuccess"] = "Logs rotated on " + server.Name + "."; return(RedirectToAction("Details", new { id = id })); }
//========================================================================= // // REGULAR ACTIONS // //========================================================================= /// <summary> /// Shows details about one server. /// </summary> public ActionResult Details(int id) { var server = ServerStatus.Get(id); if (server == null) { TempData["flashError"] = "That server does not exist."; return(RedirectToAction("Index", "Dashboard")); } return(View(server)); }
//========================================================================= // // AJAX ACTIONS // //========================================================================= /// <summary> /// Fetches the instance log by connecting to its mongod server. /// This is fast and cheap, but won't work if the instance is down. /// </summary> public JsonResult GetServerLog(int id) { var server = ServerStatus.Get(id); var mongo = MongoServer.Create(new MongoServerSettings { ConnectTimeout = new TimeSpan(0, 0, 3), Server = MongoServerAddress.Parse(server.Name), SlaveOk = true }); try { var result = mongo["admin"]["$cmd"].FindOne(Query.EQ("getLog", "global")); return(Json(new { log = HtmlizeFromLogArray(result.AsBsonDocument["log"].AsBsonArray) }, JsonRequestBehavior.AllowGet)); } catch (MongoException e) { return(Json(new { error = e.Message }, JsonRequestBehavior.AllowGet)); } }