private void TimerTicker(object state) { try { CollectInternalCounters(); //Check and notify about threshold violations occured foreach (var item in countersListGeneric) { foreach (var thr in item.Thresholds) { thr.TestThresholdOk(item); } } double count = requestNum.GetValue(); if (count > Configuration.DoNotStorePerfCountersIfReqLessOrEqThan) { var listTemp = countersListGeneric.Select(a => a.GetPerfCounterData(true)).ToList(); ///Note that it is not ideal solution! ///Ideally, storing and resetting should be locked in one section for exact precise counter values, /// and increment should use the same lock object! ///But for our purposes precision is enough, for polling periods ~1sec //foreach (var item in countersListGeneric) //{ // item.Reset(); //} //Stopwatch sw = Stopwatch.StartNew(); foreach (var item in storagesList) { item.StorePerfCounters(listTemp); } //sw.Stop(); //if (sw.Elapsed.TotalMilliseconds > 300) //{ // OnError(null, new PerfonErrorEventArgs("Storing counters:" + sw.Elapsed.TotalMilliseconds.ToString("n0") + " ms")); //} } } catch (Exception exc) { if (OnError != null) { OnError(new object(), new PerfonErrorEventArgs(exc.ToString())); } } }
public override bool TestThresholdOk(IPerformanceCounter counter) { bool res = true; var val = counter.GetValue(); res = val >= ThresholdValue; if (res && !IsThresholdViolated) { IsThresholdViolated = true; RaiseThresholdViolated(new ThreshouldNotificationEventArg(counter.Name + ", " + Message + " violated, val=" + val)); } if (!res && IsThresholdViolated) { IsThresholdViolated = false; RaiseThresholdViolated(new ThreshouldNotificationEventArg(counter.Name + ", " + Message + " recovered, val=" + val)); } return(res); }