private void Initialize(String machineName) { try { var counters = new List <Tuple <int, PerformanceCounter> >(); serviceCounterList = PerfmonClient.SelectServiceCounter(machineName).ToList(); foreach (var counter in serviceCounterList) { logger.InfoFormat(@"Creating performance counter: {0}\{1}\{2}\{3}", counter.MachineName ?? ".", counter.CategoryName, counter.CounterName, counter.InstanceName); var perfCounter = new PerformanceCounter(counter.CategoryName, counter.CounterName, counter.InstanceName, counter.MachineName ?? "."); counters.Add(new Tuple <int, PerformanceCounter>(counter.Id, perfCounter)); // first value doesn't matter so we should call the counter at least once try { perfCounter.NextValue(); } catch { } } serviceCounters = counters; } catch (Exception ex) { logger.Error(ex); } }
private void SaveServiceSnapshots(IEnumerable <ServiceCounterSnapshot> snapshots) { PerfmonClient.SaveServiceSnapshots(snapshots); }