public void RegisterServer() { server = sproc.ReturnServer(serverName); if (server.ServerID == 0) { Guid g = Guid.NewGuid(); string serverUniqueCode = Convert.ToBase64String(g.ToByteArray()); serverUniqueCode = serverUniqueCode.Replace("=", ""); serverUniqueCode = serverUniqueCode.Replace("+", ""); //Numbers given are the defult server.ServerID = sproc.InsertServer(serverName, serverUniqueCode, 90, 90, 500, 60); icon.Icon = SystemIcons.Exclamation; icon.BalloonTipText = "Use this code to register your server on the mobile app: " + serverUniqueCode; icon.BalloonTipIcon = ToolTipIcon.Info; icon.Visible = true; icon.ShowBalloonTip(3000); } }
/// <summary> /// The main monitoring code /// </summary> /// <param name="serverID">ID of the current server</param> public void Monitoring(int serverID) { string warning = ""; DateTime startTime = new DateTime(); DateTime endTime = new DateTime(); int warningID = 0; int stop = 0; Client client = new Client(); while (stop != 1) { server = sproc.ReturnServer(serverName); int ticksForOneMinute = (int)(server.TimeWarning / 5); float cpuPercent = GetCPUCounter(); float networkUsage = GetBandWidth(); float ramAvailable = GetAvailableRAM(); #region CPU Alert Check if (cpuPercent >= server.CPUWarningPoint) { totalHitsCPU = totalHitsCPU + 1; if (totalHitsCPU == ticksForOneMinute) { warning = "ALERT! CPU over " + server.CPUWarningPoint + "% usage for " + server.TimeWarning + " seconds"; startTime = DateTime.Now; warningID = sproc.InsertServerWarning(warning, startTime, startTime, serverID); client.GetClient("http://localhost:2021/", "api/Push?serverID=" + server.ServerID + "&hardware=CPU"); } } //Check for the end of the warning else if (totalHitsCPU >= ticksForOneMinute) { endTime = DateTime.Now; sproc.InsertServerWarning(warning, startTime, endTime, serverID, warningID); totalHitsCPU = 0; } else { totalHitsCPU = 0; } #endregion #region RAM Alert Usage if (ramAvailable >= server.RAMWarningPoint) { totalHitsNetwork = totalHitsNetwork + 1; if (totalHitsNetwork == ticksForOneMinute) { warning = "ALERT! RAM under " + server.RAMWarningPoint + "MB Avaialble for " + server.TimeWarning + " seconds"; startTime = DateTime.Now; warningID = sproc.InsertServerWarning(warning, startTime, startTime, serverID); client.GetClient("http://localhost:2021/", "api/Push?serverID=" + server.ServerID + "&hardware=RAM"); } } //Check for the end of the warning else if (totalHitsNetwork >= ticksForOneMinute) { endTime = DateTime.Now; sproc.InsertServerWarning(warning, startTime, endTime, serverID, warningID); totalHitsNetwork = 0; } else { totalHitsNetwork = 0; } #endregion #region Network Alert Usage if (networkUsage >= server.NetworkWarningPoint) { totalHitsNetwork = totalHitsNetwork + 1; if (totalHitsNetwork == ticksForOneMinute) { warning = "ALERT! Network over " + server.NetworkWarningPoint + "% usage for " + server.TimeWarning + " seconds"; startTime = DateTime.Now; warningID = sproc.InsertServerWarning(warning, startTime, startTime, serverID); client.GetClient("http://localhost:2021/", "api/Push?serverID=" + server.ServerID + "&hardware=Net"); } } //Check for the end of the warning else if (totalHitsNetwork >= ticksForOneMinute) { endTime = DateTime.Now; sproc.InsertServerWarning(warning, startTime, endTime, serverID, warningID); totalHitsNetwork = 0; } else { totalHitsNetwork = 0; } #endregion sproc.InsertServerSpecs(cpuPercent.ToString() + "%", GetAvailableRAM() + "MB Available", networkUsage.ToString(), serverID); } }