private void SendAlertMessage(AlertType alertType, double value, long ramValue) { List <RTPMProcess> list = new List <RTPMProcess>(); lstPerformance = new List <PerformanceCounter>(); Process[] processes = System.Diagnostics.Process.GetProcesses(); for (int i = 0; i < processes.Length; i++) { PerformanceCounter pc = new PerformanceCounter("Process", "% Processor Time", processes[i].ProcessName, true); try { pc.NextValue(); } catch { } lstPerformance.Add(pc); } Thread.Sleep(1000); for (int i = 0; i < processes.Length; i++) { RTPMProcess r = new RTPMProcess(); r.RAMUsage = processes[i].PrivateMemorySize64; r.ProcessName = processes[i].ProcessName; r.Id = processes[i].Id; try { r.CPUUsage = lstPerformance[i].NextValue() / Environment.ProcessorCount; } catch { } list.Add(r); } var pList = (from pp in list orderby pp.CPUUsage descending select pp).ToList(); mrePublish = new ManualResetEvent(false); RTPMServer rtpmServer = new RTPMServer(); rtpmServer.AlertType = alertType; rtpmServer.Date = DateTime.UtcNow; rtpmServer.ServerName = Environment.MachineName; rtpmServer.CPUUsage = value; rtpmServer.RAMAvailable = ramValue; rtpmServer.Processes = pList; publishedMessage = rtpmServer; pubnub.Publish <string>(channel, publishedMessage, PublishCallback, ErrorCallback); mrePublish.WaitOne(manualResetEventsWaitTimeout); }
private void SendAlertMessage(AlertType alertType, double value, long ramValue) { List<RTPMProcess> list = new List<RTPMProcess>(); lstPerformance = new List<PerformanceCounter>(); Process[] processes = System.Diagnostics.Process.GetProcesses(); for (int i = 0; i < processes.Length; i++) { PerformanceCounter pc = new PerformanceCounter("Process", "% Processor Time", processes[i].ProcessName, true); try { pc.NextValue(); } catch { } lstPerformance.Add(pc); } Thread.Sleep(1000); for (int i = 0; i < processes.Length; i++) { RTPMProcess r = new RTPMProcess(); r.RAMUsage = processes[i].PrivateMemorySize64; r.ProcessName = processes[i].ProcessName; r.Id = processes[i].Id; try { r.CPUUsage = lstPerformance[i].NextValue() / Environment.ProcessorCount; } catch { } list.Add(r); } var pList = (from pp in list orderby pp.CPUUsage descending select pp).ToList(); mrePublish = new ManualResetEvent(false); RTPMServer rtpmServer = new RTPMServer(); rtpmServer.AlertType = alertType; rtpmServer.Date = DateTime.UtcNow; rtpmServer.ServerName = Environment.MachineName; rtpmServer.CPUUsage = value; rtpmServer.RAMAvailable = ramValue; rtpmServer.Processes = pList; publishedMessage = rtpmServer; pubnub.Publish<string>(channel, publishedMessage, PublishCallback, ErrorCallback); mrePublish.WaitOne(manualResetEventsWaitTimeout); }