Skip to content

Instantly share code, notes, and snippets.

@joshmarinacci
Created December 3, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmarinacci/f9615c7e67ab6c588fbc to your computer and use it in GitHub Desktop.
Save joshmarinacci/f9615c7e67ab6c588fbc to your computer and use it in GitHub Desktop.
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment