public PerformanceCounterInput(PerformanceCounterInputConfiguration configuration, IHealthReporter healthReporter)
        {
            Requires.NotNull(configuration, nameof(configuration));
            Requires.NotNull(healthReporter, nameof(healthReporter));

            Initialize(configuration, healthReporter);
        }
        private void Initialize(PerformanceCounterInputConfiguration configuration, IHealthReporter healthReporter)
        {
            this.syncObject               = new object();
            this.subject                  = new EventFlowSubject <EventData>();
            this.healthReporter           = healthReporter;
            this.processInstanceNameCache = new ProcessInstanceNameCache();
            this.sampleInterval           = TimeSpan.FromMilliseconds(configuration.SampleIntervalMsec);
            var currentProcess = Process.GetCurrentProcess();

            this.currentProcessName = currentProcess.ProcessName;
            this.currentProcessId   = currentProcess.Id;

            // The CLR Process ID counter used for process ID to counter instance name mapping for CLR counters will not read correctly
            // until at least one garbage collection is performed, so we will force one now.
            // The listener is usually created during service startup so the GC should not take very long.
            GC.Collect();

            this.trackedPerformanceCounters = new List <TrackedPerformanceCounter>();

            foreach (var counterConfiguration in configuration.Counters)
            {
                if (!counterConfiguration.Validate())
                {
                    healthReporter.ReportProblem($"{nameof(PerformanceCounterInput)}: configuration for counter {counterConfiguration.CounterName} is invalid");
                }
                else
                {
                    this.trackedPerformanceCounters.Add(new TrackedPerformanceCounter(counterConfiguration));
                }
            }

            this.collectionTimer = new Timer(this.DoCollection, null, this.sampleInterval, TimeSpan.FromDays(1));
        }
        public PerformanceCounterInput(IConfiguration configuration, IHealthReporter healthReporter)
        {
            Requires.NotNull(configuration, nameof(configuration));
            Requires.NotNull(healthReporter, nameof(healthReporter));

            var inputConfiguration = new PerformanceCounterInputConfiguration();

            try
            {
                configuration.Bind(inputConfiguration);
            }
            catch (Exception e)
            {
                healthReporter.ReportProblem($"{nameof(PerformanceCounterInput)}: an error occurred when reading configuration{Environment.NewLine}{e.ToString()}");
                return;
            }

            Initialize(inputConfiguration, healthReporter);
        }