/// <summary> /// Prepare for stats collection /// </summary> private void Prepare() { if (Environment.OSVersion.ToString().StartsWith("unix", StringComparison.InvariantCultureIgnoreCase)) { logger.Warn(ErrorCode.PerfCounterNotFound, "Windows perf counters are only available on Windows :) -- defaulting to in-memory counters."); shouldWritePerfCounters = false; return; } if (!OrleansPerfCounterManager.AreWindowsPerfCountersAvailable()) { logger.Warn(ErrorCode.PerfCounterNotFound, "Windows perf counters not found -- defaulting to in-memory counters. Run CounterControl.exe as Administrator to create perf counters for Orleans."); shouldWritePerfCounters = false; return; } try { OrleansPerfCounterManager.PrecreateCounters(); } catch (Exception exc) { logger.Warn(ErrorCode.PerfCounterFailedToInitialize, "Failed to initialize perf counters -- defaulting to in-memory counters. Run CounterControl.exe as Administrator to create perf counters for Orleans.", exc); shouldWritePerfCounters = false; } }
/// <summary> /// Handle a timer tick /// </summary> /// <param name="state"></param> private void TimerTick(object state) { if (shouldWritePerfCounters) { // Write counters to Windows perf counters int numErrors = OrleansPerfCounterManager.WriteCounters(); if (numErrors > 0) { logger.Warn(ErrorCode.PerfCounterWriteErrors, "Completed writing Windows perf counters with {0} errors", numErrors); } else if (logger.IsVerbose2) { logger.Verbose2(ErrorCode.PerfCounterWriteSuccess, "Completed writing Windows perf counters sucessfully"); } if (numErrors > ERROR_THRESHOLD) { logger.Error(ErrorCode.PerfCounterWriteTooManyErrors, "Too many errors writing Windows perf counters -- disconnecting counters"); shouldWritePerfCounters = false; } } else if (logger.IsVerbose2) { logger.Verbose2("Skipping - Writing Windows perf counters is disabled"); } }
/// <summary> /// Constructors -- Registers Orleans system performance counters, /// plus any grain-specific activation conters that can be detected when this installer is run. /// </summary> public OrleansPerformanceCounterInstaller() { try { using (var myPerformanceCounterInstaller = new PerformanceCounterInstaller()) { myPerformanceCounterInstaller.CategoryName = OrleansPerfCounterManager.CATEGORY_NAME; myPerformanceCounterInstaller.CategoryType = PerformanceCounterCategoryType.MultiInstance; myPerformanceCounterInstaller.Counters.AddRange(OrleansPerfCounterManager.GetCounterCreationData()); Installers.Add(myPerformanceCounterInstaller); } } catch (Exception exc) { Context.LogMessage("Failed to install performance counters: " + exc.Message); } }
/// <summary> /// Prepare for stats collection /// </summary> private void Prepare() { if (!OrleansPerfCounterManager.AreWindowsPerfCountersAvailable()) { logger.Warn(ErrorCode.PerfCounterNotFound, "Windows perf counters not found -- defaulting to in-memory counters. Run CounterControl.exe as Administrator to create perf counters for Orleans."); shouldWritePerfCounters = false; return; } try { OrleansPerfCounterManager.PrecreateCounters(); } catch (Exception exc) { logger.Warn(ErrorCode.PerfCounterFailedToInitialize, "Failed to initialize perf counters -- defaulting to in-memory counters. Run CounterControl.exe as Administrator to create perf counters for Orleans.", exc); shouldWritePerfCounters = false; } }