public PerformanceCountersListener(IDogStatsd statsd)
        {
            _statsd = statsd;

            ProcessHelpers.GetCurrentProcessInformation(out _processName, out _, out _processId);

            // To prevent a potential deadlock when hosted in a service, performance counter initialization must be asynchronous
            // That's because performance counters may rely on wmiApSrv being started,
            // and the windows service manager only allows one service at a time to be starting: https://docs.microsoft.com/en-us/windows/win32/services/service-startup
            _initializationTask = Task.Run(InitializePerformanceCounters);
        }
        public PerformanceCountersListener(IDogStatsd statsd)
        {
            _statsd = statsd;

            ProcessHelpers.GetCurrentProcessInformation(out _processName, out _, out _processId);

            _memoryCategory = new PerformanceCounterCategory(MemoryCategoryName);

            var instanceName = GetInstanceName();

            _fullInstanceName = instanceName.Item2;
            _instanceName     = instanceName.Item1;

            InitializePerformanceCounters(_instanceName);
        }
Exemple #3
0
 private static void TrySetProcess()
 {
     try
     {
         if (!_processDataUnavailable && !_initialized)
         {
             _initialized = true;
             ProcessHelpers.GetCurrentProcessInformation(out _currentProcessName, out _currentProcessMachineName, out _currentProcessId);
         }
     }
     catch
     {
         _processDataUnavailable = true;
     }
 }