Created
November 10, 2015 00:35
-
-
Save marceloinacio/8256128eeb0cfe49724d to your computer and use it in GitHub Desktop.
Thread to monitoring the Server
This file contains hidden or 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