private void TestSystemPerformanceCounters() { IPerformanceCounterNumeric memory = State.AttachSystemCounter("Memory", "Available Bytes"); IPerformanceCounterNumeric fiorate = State.AttachSystemCounter("System", "File Read Operations/sec"); IPerformanceCounterNumeric paging = State.AttachSystemCounter("Processor", "% Processor Time", "_Total"); IPerformanceCounterNumeric uptime = State.AttachSystemCounter("System", "System Up Time"); for (int i = 0; i < 100; i++) { memory.Update(); float value1 = memory.CounterValue; Assert.GreaterOrEqual(value1, 0, "System performance counter value is invalid!"); fiorate.Update(); float value2 = fiorate.CounterValue; Assert.GreaterOrEqual(value2, 0, "System performance counter value is invalid!"); paging.Update(); float value3 = paging.CounterValue; Assert.GreaterOrEqual(value3, 0, "System performance counter value is invalid!"); uptime.Update(); float value4 = uptime.CounterValue; Assert.GreaterOrEqual(value4, 0, "System performance counter value is invalid!"); } memory.RemoveFromMonitoring(); fiorate.RemoveFromMonitoring(); paging.RemoveFromMonitoring(); uptime.RemoveFromMonitoring(); }
private void TestNumericPerformanceCountersElapsedTime() { IPerformanceCounterNumeric counter = State.AttachNumericCounter("Counter", PerformanceCounterType.ElapsedTime); counter.SetRawValue(DateTime.UtcNow); Thread.Sleep(2500); counter.Update(); Assert.GreaterOrEqual(counter.CounterValue, 2, "Numeric performance counter value is invalid!"); Assert.LessOrEqual(counter.CounterValue, 3, "Numeric performance counter value is invalid!"); counter.RemoveFromMonitoring(); }
private void TestNumericPerformanceCountersCountPerSecond() { IPerformanceCounterNumeric counter = State.AttachNumericCounter("Counter", PerformanceCounterType.CountPerSecond); for (int i = 1; i <= 30; i++) { counter.Increment(); counter.Update(); Assert.LessOrEqual(counter.CounterValue, 10, "Numeric performance counter value is invalid!"); Thread.Sleep(100); } counter.RemoveFromMonitoring(); }
private void TestNumericPerformanceCountersDeltaValue() { var random = new Random(); IPerformanceCounterNumeric counter = State.AttachNumericCounter("Counter", PerformanceCounterType.DeltaValue); for (int i = 1; i <= 100; i++) { counter.IncrementBy(random.Next(100)); counter.Update(); Assert.LessOrEqual(counter.CounterValue, 100, "Numeric performance counter value is invalid!"); } counter.RemoveFromMonitoring(); }
private void TestNumericPerformanceCountersNumberOfItems() { IPerformanceCounterNumeric counter = State.AttachNumericCounter("Counter"); counter.SetRawValue(100); for (int i = 1; i <= 10; i++) { counter.Increment(); counter.Update(); Assert.AreEqual(100 + i, counter.CounterValue, 0.001, "Numeric performance counter value is invalid!"); } counter.SetRawValue(100); for (int i = 1; i <= 10; i++) { counter.IncrementBy(10); counter.Update(); Assert.AreEqual(100 + 10 * i, counter.CounterValue, 0.001, "Numeric performance counter value is invalid!"); } counter.SetRawValue(100); for (int i = 1; i <= 10; i++) { counter.Decrement(); counter.Update(); Assert.AreEqual(100 - i, counter.CounterValue, 0.001, "Numeric performance counter value is invalid!"); } counter.SetRawValue(100); for (int i = 1; i <= 10; i++) { counter.DecrementBy(10); counter.Update(); Assert.AreEqual(100 - 10 * i, counter.CounterValue, 0.001, "Numeric performance counter value is invalid!"); } counter.RemoveFromMonitoring(); }
private void TestNumericPerformanceCountersPercentValue() { IPerformanceCounterNumeric counter = State.AttachNumericCounter("Counter", PerformanceCounterType.PercentValue); for (int i = 1; i <= 1000; i++) { counter.IncrementBy(0.01f); if ((i % 100 == 0)) { counter.IncrementBase(); } counter.Update(); Assert.LessOrEqual(counter.CounterValue, 100, "Numeric performance counter value is invalid!"); } counter.RemoveFromMonitoring(); }
private void TestNumericPerformanceCounters() { const float value = 12345678; IPerformanceCounterNumeric counter1 = State.AttachNumericCounter("Counter1"); IPerformanceCounterNumeric counter2 = State.AttachNumericCounter("Counter2", () => value); counter1.SetRawValue(value); for (int i = 0; i < 10; i++) { counter1.Update(); Assert.AreEqual(value, counter1.CounterValue, 0.001, "Numeric performance counter value is invalid!"); counter2.Update(); Assert.AreEqual(value, counter2.CounterValue, 0.001, "Numeric performance counter value is invalid!"); } counter1.RemoveFromMonitoring(); counter2.RemoveFromMonitoring(); }