/// <summary>
            /// Finishes configuration and starts collecting .NET runtime metrics. Returns a <see cref="IDisposable"/> that
            /// can be disposed of to stop metric collection.
            /// </summary>
            /// <param name="registry">Registry where metrics will be collected</param>
            /// <returns></returns>
            public IDisposable StartCollecting(TCollectorRegistry registry)
            {
                var runtimeStatsCollector = new DotNetRuntimeStatsCollector(StatsCollectors.ToImmutableHashSet(), _errorHandler, _debugMetrics, registry);

#if PROMV2
                registry.RegisterOnDemandCollectors(runtimeStatsCollector);
#elif PROMV3
                runtimeStatsCollector.RegisterMetrics(registry);
                registry.AddBeforeCollectCallback(runtimeStatsCollector.UpdateMetrics);
#endif

                return(runtimeStatsCollector);
            }
示例#2
0
            /// <summary>
            /// Finishes configuration and starts collecting .NET runtime metrics. Returns a <see cref="IDisposable"/> that
            /// can be disposed of to stop metric collection.
            /// </summary>
            /// <returns></returns>
            public IDisposable StartCollecting()
            {
                if (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);

#if PROMV2
                DefaultCollectorRegistry.Instance.RegisterOnDemandCollectors(runtimeStatsCollector);
#elif PROMV3
                runtimeStatsCollector.RegisterMetrics(Metrics.DefaultRegistry);
                Metrics.DefaultRegistry.AddBeforeCollectCallback(runtimeStatsCollector.UpdateMetrics);
#endif
                return(runtimeStatsCollector);
            }
示例#3
0
            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);
            }