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.RegisterOnDemandCollector <DotNetStatsCollector>(); }
public void custom_registry() { var myRegistry = new DefaultCollectorRegistry(); var counter1 = Metrics.WithCustomRegistry(myRegistry).CreateCounter("counter1", "help1"); //registered on a custom registry var counter2 = Metrics.CreateCounter("counter1", "help1"); //created on different registry - same name is hence permitted counter1.Inc(3); counter2.Inc(4); myRegistry.CollectAll().ToArray()[0].metric[0].counter.value.ShouldEqual(3); //counter1 == 3 DefaultCollectorRegistry.Instance.CollectAll().ToArray()[0].metric[0].counter.value.ShouldEqual(4); //counter2 == 4 }
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); }
/// <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) { return(StartCollecting(registry, registryIsDefault: false)); }