Skip to content

Instantly share code, notes, and snippets.

@joshmarinacci
Created December 3, 2015 06:06
Show Gist options
  • Save joshmarinacci/63f99f5522ef46ac570c to your computer and use it in GitHub Desktop.
Save joshmarinacci/63f99f5522ef46ac570c to your computer and use it in GitHub Desktop.
private void Process()
{
while (!finalizeService)
{
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Processor";
PC.CounterName = "% Processor Time";
PC.InstanceName = "_Total";
PC.ReadOnly = true;
var value = PC.NextValue();
Thread.Sleep(1000);
value = PC.NextValue();
PC.Close();
PC.Dispose();
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes", true);
var ramValue = ramCounter.NextValue();
if (ramValue <= MinRAMAvailable)
{
SendAlertMessage(AlertType.RAM_ALERT, value,Convert.ToInt64(ramValue));
}
if (value >= MaxCPUUsage)
{
totalHits = totalHits + 1;
if (totalHits == Period)
{
SendAlertMessage(AlertType.PROCESS_ALERT, value, Convert.ToInt64(ramValue));
totalHits = 0;
}
}
else
{
totalHits = 0;
}
}
eventLog.WriteEntry(ServiceName + " stoped.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment