public static int WriteCounters() { if (logger.IsVerbose) { logger.Verbose("Writing Windows perf counters."); } int numWriteErrors = 0; foreach (PerfCounterConfigData cd in perfCounterData) { StatisticName name = cd.Name; string perfCounterName = GetPerfCounterName(cd); try { if (cd.PerfCounter == null) { if (logger.IsVerbose) { logger.Verbose(ErrorCode.PerfCounterUnableToConnect, "No perf counter found for {0}", name); } cd.PerfCounter = CreatePerfCounter(perfCounterName); } if (cd.CounterStat == null) { if (logger.IsVerbose) { logger.Verbose(ErrorCode.PerfCounterRegistering, "Searching for statistic {0}", name); } ICounter <long> ctr = IntValueStatistic.Find(name); cd.CounterStat = ctr ?? CounterStatistic.FindOrCreate(name); } long val; //if (cd.UseDeltaValue) //{ // ((CounterStatistic)cd.CounterStat).GetCurrentValueAndDeltaAndResetDelta(out val); //} //else { val = cd.CounterStat.GetCurrentValue(); } if (logger.IsVerbose3) { logger.Verbose3(ErrorCode.PerfCounterWriting, "Writing perf counter {0} Value={1}", perfCounterName, val); } cd.PerfCounter.RawValue = val; } catch (Exception ex) { numWriteErrors++; logger.Error(ErrorCode.PerfCounterUnableToWrite, string.Format("Unable to write to Windows perf counter '{0}'", name), ex); } } return(numWriteErrors); }
public static int WriteCounters() { if (logger.IsVerbose) { logger.Verbose("Writing counters."); } int numWriteErrors = 0; foreach (CounterConfigData cd in CounterConfigData.StaticCounters) { StatisticName name = cd.Name; string perfCounterName = GetPerfCounterName(cd); try { if (logger.IsVerbose3) { logger.Verbose3(ErrorCode.PerfCounterWriting, "Writing counter {0}", perfCounterName); } if (cd.CounterStat == null) { if (logger.IsVerbose) { logger.Verbose(ErrorCode.PerfCounterRegistering, "Searching for statistic {0}", name); } ICounter <long> ctr = IntValueStatistic.Find(name); cd.CounterStat = ctr ?? CounterStatistic.FindOrCreate(name); } if (cd.CounterStat != null) { logger.TrackMetric(perfCounterName, cd.CounterStat.GetCurrentValue()); } } catch (Exception ex) { numWriteErrors++; logger.Error(ErrorCode.PerfCounterUnableToWrite, string.Format("Unable to write to counter '{0}'", name), ex); } } return(numWriteErrors); }