Пример #1
0
        static void Main()
        {
            var counter = Metrics.CreateCounter("abc");

            counter.Increment();
            counter.Increment(2);
            counter.Increment("def");
            counter.Increment("ghi", 5000);
            counter.Increment("\\\"\n", 3);
            counter.Increment(null, 5000);

            var summary = Metrics.CreateSummary("my_summary");

            for (int i = 0; i < 100; i++)
            {
                summary.Observe(i);
                summary.Observe("inst", i * 2);
            }

            var histogram = Metrics.CreateHistogram("my_histogram", HistogramBuckets.SampleExponentialBuckets);

            for (int i = 0; i < 100; i++)
            {
                histogram.Observe(i * 0.004);
                histogram.Observe("inst", i * 2);
            }

            var instance = DotNetStats.Register(Metrics.DefaultRegistry);

            instance.UpdateMetrics();

            Metrics.DefaultRegistry.WriteTo(Console.Out);
        }
Пример #2
0
        static Metrics()
        {
            DefaultRegistry = new CollectorRegistry();
            _defaultFactory = new MetricFactory(DefaultRegistry);

            // We include some metrics by default, just to give some output when a user first uses the library.
            // These are not designed to be super meaningful/useful metrics.
            DotNetStats.Register(DefaultRegistry);
        }
Пример #3
0
    public static IHostBuilder AddMetrics(this IHostBuilder builder)
    => builder.ConfigureServices(services =>
    {
        var registry = Prometheus.Metrics.NewCustomRegistry();
        DotNetStats.Register(registry);

        var factory = Prometheus.Metrics.WithCustomRegistry(registry);
        services.AddSingleton <IMetricFactory>(factory);

        services.AddSingleton(provider =>
        {
            foreach (var collector in provider.GetRequiredService <IEnumerable <MetricCollector> >())
            {
                provider.GetRequiredService(collector.CollectorType);
            }

            return(registry);
        });
    });
Пример #4
0
        static Metrics()
        {
            NewDefaultRegistry();

            DotNetStats.Register(DefaultRegistry);
        }