public static int intTestCount = 0; //Just a global variable for counting test loops please ignore my poor coding standards static void Main() { try { //Declaring and initilizing some stuff probaly more stuff then i need EmailClass emailClass = new EmailClass(); LogClass logClass = new LogClass(); string[] strUtilization; int intStrikes = 0; int intMissing = 0; bool bReboot = false; bool bAddStrike = false; string strMsg = ""; bool bRestartedMiner = false; int intEvents = 10; //Get config values from the config file try { getConfig(); } catch (Exception e) { logClass.Log("Error loading config. Check config file exiting program - " + e); Environment.Exit(1); } logClass.Log("Starting process assuming reboot because I don't feel like checking."); //Send Email starting up if (objConfig.SendEmail != "no") { logClass.Log("Sending Email"); emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Monitoring is starting", "Monitoring is starting", objConfig.FromEmailAddress, objConfig.FromEmailPassword); } //Half a delay checks to give the computer time to get going. Added fancy count down. CountDown(objConfig.Delay / 2); //Delete old log files logClass.DeleteOldLogs(3); //If startup bat present run it if (objConfig.StartBat != "") { try { logClass.Log("Starting miner command - " + objConfig.StartBat); ExecuteCommand(objConfig.StartBat); } catch (Exception e) { logClass.Log("Error starting miner- attemping notification - " + e); if (objConfig.SendEmail != "no") { emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Miner failed to start", "Miner failed to start check log", objConfig.FromEmailAddress, objConfig.FromEmailPassword); } } } if (objConfig.ProdOrTest == "test") { logClass.Log("\r\nUsing Test Data!!!\r\n"); } //Loop till something breaks while (!bReboot) { //Clear message for every loop strMsg = ""; //Decide if we are using real values or test values if (objConfig.ProdOrTest != "test") { strUtilization = getUtilization(); } else { strUtilization = testgetUtilization(); } //Convert the string utilizations into ints so we can do some math. int[] intUtilization = Array.ConvertAll(strUtilization, delegate(string s) { return(int.Parse(s)); }); //Make sure all cards are utilized above threshold if (checkUtilization(intUtilization, ref strMsg)) { bAddStrike = true; } //Make sure all cards are present else if (intUtilization.Length < objConfig.NumberOfGPUS) { bAddStrike = true; intMissing = objConfig.NumberOfGPUS - intUtilization.Length; strMsg = strMsg + "\r\nThe Ugly - " + intMissing + " GPUs are missing \r\n"; } //Clean run new batter clear the board else { //If there was strike log the next good run before clearing the board if (intStrikes > 0) { logClass.Log(strMsg); intStrikes = 0; } else { Console.Write("\r\n" + DateTime.Now.ToString("MM/dd/yyyy h:mm:ss tt") + " - " + strMsg); } bRestartedMiner = false; } //If Error Log int if (strMsg.Contains("Bad") || strMsg.Contains("Ugly")) { logClass.Log(strMsg); } //If error and internet is up count it as strike if (bAddStrike) { //Check for internet connection before looking for strikes. If not internet/pool then no need to try anything. if (CheckForInternetConnection()) { intStrikes++; } else { logClass.Log("Internet check failed strike not counted."); } } //Check if we need attempt to restart computer if (intStrikes >= objConfig.ComputerStrikes) { bReboot = true; } //Check if we need to attempt to restart miner else if (intStrikes >= objConfig.MinerStrikes) { //If restart bat present execute it if (objConfig.RestartBat != "") { try { if (!bRestartedMiner) { bRestartedMiner = true; logClass.Log("Restarting miner command - " + objConfig.StartBat); actionLog(); ExecuteCommand(objConfig.RestartBat); if (objConfig.SendEmail != "no") { emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + " Restarting Miner Program", logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword); } } } catch (Exception e) { logClass.Log("Error - attemping notification if enabled - " + e); if (objConfig.SendEmail != "no") { emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "Miner failed to restart", "Miner failed to restart. Monitoring will continue and computer restart may be attempted if enabled.\r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword); } } } else { logClass.Log("Miner strike set but no bat file provided!"); } } //sleep for the set delay CountDown(objConfig.Delay); } //Well crap we made it out time to reboot actionLog(); if (objConfig.Restart != "no") { //Send Email something went wrong if (objConfig.SendEmail != "no") { logClass.Log("Sending Email"); emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "struck out rebooting", "Rebooting\r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword); } logClass.Log("Attemping reboot with force"); strMsg = "-r -f -t 60 -c \"" + strMsg + "\""; System.Diagnostics.Process.Start("shutdown.exe", strMsg); } else { logClass.Log("Computer struck out but reboot is disabled."); if (objConfig.SendEmail != "no") { emailClass.SendEmail(objConfig.ToEmailAddress, "GPU Utilization Monitor - " + objConfig.Rig + "struck out", "Reboot is diabled taking no farther action to be taken. Stopping monitoring \r\n" + logClass.returnEvents(intEvents), objConfig.FromEmailAddress, objConfig.FromEmailPassword); } } } catch (Exception e) { LogClass logClass = new LogClass(); logClass.Log("Fatal exception - " + e); } }