Created
December 3, 2015 06:06
-
-
Save joshmarinacci/63f99f5522ef46ac570c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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