static DefaultCollectorRegistry() { // We register the default on-demand collectors here. To avoid having the, // use a custom instance instead of the singleton or call Clear() before the first use. Instance = new DefaultCollectorRegistry(); Instance.RegisterOnDemandCollectors(new[] { new DotNetStatsCollector() }); }
private IDisposable StartCollecting(TCollectorRegistry registry, bool registryIsDefault) { if (registryIsDefault && DotNetRuntimeStatsCollector.Instance != null) { throw new InvalidOperationException(".NET runtime metrics are already being collected. Dispose() of your previous collector before calling this method again."); } var runtimeStatsCollector = new DotNetRuntimeStatsCollector(StatsCollectors.ToImmutableHashSet(), _errorHandler, _debugMetrics, isDefaultInstance: registryIsDefault); #if PROMV2 registry.RegisterOnDemandCollectors(runtimeStatsCollector); #elif PROMV3 runtimeStatsCollector.RegisterMetrics(registry); registry.AddBeforeCollectCallback(runtimeStatsCollector.UpdateMetrics); #endif SetupBuildInfo(); return(runtimeStatsCollector); }