コード例 #1
0
        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);
            }
        }
コード例 #2
0
 private void SaveServiceSnapshots(IEnumerable <ServiceCounterSnapshot> snapshots)
 {
     PerfmonClient.SaveServiceSnapshots(snapshots);
 }