public int executePlugin() { int retVal = 0; if (failTest()) { retVal = 2; } else { if (hasArgs) { if (!checkArgs()) { Console.WriteLine("Error: Check your arguments!"); return(3); } } Computer c1 = new Computer(); c1.RAMEnabled = true; c1.Open(); double max_memory_load = 0; bool has_memory_sensor = false; foreach (var hardwareItem in c1.Hardware) { if (hardwareItem.HardwareType == HardwareType.RAM) { hardwareItem.Update(); foreach (var sensor in hardwareItem.Sensors) { if (sensor.SensorType == SensorType.Data) { if (sensor.Name == "Used Memory") { has_memory_sensor = true; max_memory_load = Convert.ToDouble(sensor.Value); continue; } if (sensor.Name == "Available Memory") { max_memory_load = max_memory_load / (Convert.ToDouble(sensor.Value) + max_memory_load); continue; } } } } } if (!has_memory_sensor) { resultString = "MEMORY LOAD OK: No sensors detected for this type of RAM | metric=1.00"; retVal = 0; } if ((max_memory_load * 100.0) < warning.getDouble()) { String performance_data = String.Format("memory_load={0};{1};{2}", max_memory_load.ToString("N2"), (warning.getDouble() / 100.0).ToString("N2"), (critical.getDouble() / 100.0).ToString("N2")); resultString = "MEMORY LOAD OK: Memory load below thresholds | metric=1.00 " + performance_data; retVal = 0; } else if ((max_memory_load * 100.0) >= warning.getDouble() && (max_memory_load * 100.0) < critical.getDouble()) { ATypes a1 = new ATypes(max_memory_load * 100.0); double temp1 = (1.0 / (this.warning.getDouble() - this.critical.getDouble())) * (a1.getDouble() - this.warning.getDouble()) + 1.0; String performance_data = String.Format("memory_load={0};{1};{2}", max_memory_load.ToString("N2"), (warning.getDouble() / 100.0).ToString("N2"), (critical.getDouble() / 100.0).ToString("N2")); resultString = String.Format("MEMORY LOAD WARNING: Found memory load above warning threshold: {0}% | metric={1} " + performance_data, max_memory_load.ToString("N2"), temp1.ToString("N2")); retVal = 1; } else if ((max_memory_load * 100.0) >= critical.getDouble()) { String performance_data = String.Format("memory_load={0};{1};{2}", max_memory_load.ToString("N2"), (warning.getDouble() / 100.0).ToString("N2"), (critical.getDouble() / 100.0).ToString("N2")); resultString = "MEMORY LOAD CRITICAL: Memory load below thresholds | metric=0.00 " + performance_data; retVal = 2; } else { resultString = "MEMORY LOAD UNKNOWN: This an unknown error"; retVal = 3; } } Console.WriteLine(resultString); return(retVal); }
public int executePlugin() { int retVal = 3; if (failTest()) { retVal = 2; } else { if (hasArgs) { if (!checkArgs()) { Console.WriteLine("Check your arguments!"); return(3); } } UserUtilities s1 = new UserUtilities(); Dictionary <string, List <StoreUserProcesses> > processes = s1.GetUsersProcessesInfo(); Dictionary <string, float> user_memory = new Dictionary <string, float>(); foreach (KeyValuePair <string, List <StoreUserProcesses> > user in processes) { if (!user_memory.ContainsKey(user.Key)) { user_memory[user.Key] = 0; } foreach (StoreUserProcesses process in user.Value) { user_memory[user.Key] += process.cpu_load; } } string output_data = ""; string performance_data = ""; string metric_data = " | metric="; bool is_critical = false; bool is_warning = false; float largest_cpu_load_found = 0; foreach (var x in user_memory) { if (exclude_system_accounts) { if (users_exclusions.Contains(x.Key)) { continue; } } string user = x.Key.Contains(" ") ? x.Key.Replace(" ", "_") : x.Key; float current_cpu_load = x.Value; performance_data += String.Format("{0}={1};{2};{3} ", user, current_cpu_load.ToString("N2"), warning.getDouble().ToString("N2"), critical.getDouble().ToString("N2")); if (current_cpu_load > largest_cpu_load_found) { largest_cpu_load_found = current_cpu_load; } if (current_cpu_load >= critical.getLong()) { is_critical = true; output_data += String.Format("User {0} has {1} %/sec ", user, current_cpu_load.ToString("N2")); continue; } if (current_cpu_load >= warning.getLong()) { is_warning = true; output_data += String.Format("User {0} has {1} %/sec ", user, current_cpu_load.ToString("N2")); continue; } } if (is_critical) { string metric = metric_data + "0.00 "; resultString = "USER CPU LOAD CRITICAL: " + output_data.Trim() + " cpu in use" + metric + performance_data; retVal = 2; } else if (is_warning) { ATypes a1 = new ATypes(largest_cpu_load_found); double metric = (1.0 / (this.warning.getDouble() - this.critical.getDouble())) * (a1.getDouble() - this.warning.getDouble()) + 1.0; resultString = "USER CPU LOAD WARNING: " + output_data.Trim() + " cpu in use" + metric_data + metric.ToString("N2") + " " + performance_data; retVal = 1; } else if (!is_warning && !is_critical) { string metric = "1.00 "; resultString = "USER CPU LOAD OK: All users are within thresholds" + metric_data + metric + performance_data; retVal = 0; } else { resultString = "USER CPU LOAD UNKNOWN: Unknown error"; retVal = 3; } } Console.WriteLine(resultString); return(retVal); }
public int executePlugin() { int retVal = 3; if (failTest()) { retVal = 2; } else { if (hasArgs) { if (!this.checkArgs()) { Console.WriteLine("Error: Check your arguments"); return(3); } } string user = String.Empty; int max = 0; string performance_data = " "; Dictionary <string, int> dic = this.getProcessOwner(); foreach (KeyValuePair <string, int> entry in dic) { string key = entry.Key.Trim(); int value = entry.Value; if (key.Contains(" ")) { key = key.Replace(" ", "_"); } if ((int)entry.Value > max) { max = value; user = key; } performance_data += " " + key + "=" + value.ToString() + ";" + this.warning.getInt().ToString() + ";" + this.critical.getInt().ToString(); } string metric_data = " | metric="; double metric = 0.0; ATypes a1 = new ATypes(max); if (max < this.warning.getInt()) { metric = 1.0; resultString = "USER PROCESSES OK: No users exceeding thresholds" + metric_data + metric.ToString("N2") + performance_data; retVal = 0; } else if (max >= this.warning.getInt() && max < this.critical.getInt()) { metric = (1.0 / (this.warning.getDouble() - this.critical.getDouble())) * (a1.getDouble() - this.warning.getDouble()) + 1.0; resultString = "USER PROCESSES WARNING: User " + user + " found with " + max + " services " + metric_data + metric.ToString("N2") + performance_data; retVal = 1; } else if (max >= this.critical.getInt()) { metric = 0.0; resultString = "USER PROCESSES CRITICAL: User " + user + " found with " + max + " services " + metric_data + metric.ToString("N2") + performance_data; retVal = 2; } else { resultString = "USER PROCESSES UNKNOWN: Unknown error"; retVal = 3; } } Console.WriteLine(resultString); return(retVal); }