public void Can_set_host()
        {
            var services = new ServiceCollection();
            var spy      = new MetricServerOptions();
            var sut      = new MetricServerOptionsConfiguration(services);

            sut.WithHost("foo");

            sut.Apply(spy);

            Assert.Equal("foo", spy.Host);
        }
        public void Can_set_port()
        {
            var services = new ServiceCollection();
            var spy      = new MetricServerOptions();
            var sut      = new MetricServerOptionsConfiguration(services);

            sut.WithPort(8888);

            sut.Apply(spy);

            Assert.Equal(8888, spy.Port);
        }
        public void Can_override_default_http_metrics()
        {
            var services = new ServiceCollection();
            var spy      = new MetricServerOptions();
            var sut      = new MetricServerOptionsConfiguration(services);
            Action <HttpMiddlewareExporterOptions> stub = x => { };

            sut.EnableHttpMetrics(stub);

            sut.Apply(spy);

            Assert.Equal(stub, spy.HttpMetrics);
        }
        public void Can_enable_http_metrics()
        {
            var services = new ServiceCollection();
            var spy      = new MetricServerOptions();
            var sut      = new MetricServerOptionsConfiguration(services);

            sut.EnableHttpMetrics();

            sut.Apply(spy);

            var serviceDescriptor = services.FirstOrDefault(x => x.ServiceType == typeof(IStartupFilter));

            Assert.NotNull(serviceDescriptor);
            Assert.Equal(typeof(HttpMetricsStartupFilter), serviceDescriptor.ImplementationType);
            Assert.Equal(ServiceLifetime.Singleton, serviceDescriptor.Lifetime);
        }
        public MetricServerMiddleware(
            RequestDelegate next,
            IOptions <MetricServerOptions> options,
            IMetricRegistry registry)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (registry == null)
            {
                throw new ArgumentNullException(nameof(registry));
            }

            _options  = options.Value;
            _registry = registry;
        }
Ejemplo n.º 6
0
        static void Main()
        {
            var options = new MetricServerOptions
            {
                Port = 9091
            };

            ICollectorRegistry registry = new CollectorRegistry();
            var factory = new MetricFactory(registry);

            IMetricServer metricServer = new MetricServer(registry, options);

            metricServer.Start();

            var counter = factory.CreateCounter("test_count", "helptext");

            counter.Inc();

            Console.WriteLine("Press any key..");
            Console.ReadKey();
            metricServer.Stop();
        }
Ejemplo n.º 7
0
        static void Main()
        {
            var registry = new CollectorRegistry();
            var options  = new MetricServerOptions
            {
                CollectorRegistryInstance = registry,
                UseDefaultCollectors      = true
            };
            var factory = new MetricFactory(registry);

            IMetricServer metricServer = new MetricServer(options);

            metricServer.Start();

            var counter = factory.CreateCounter("test_count", "helptext");

            counter.Inc();

            Console.WriteLine("Press any key..");
            Console.ReadKey();
            metricServer.Stop();
        }
Ejemplo n.º 8
0
        public MetricHostService(ILogger <MetricHostService> logger, IApplicationLifetime appLifetime, IOptions <MetricServiceOptions> options)
        {
            var conf = options ?? throw new ArgumentNullException(nameof(options));

            _logger      = logger ?? throw new ArgumentNullException(nameof(logger));
            _appLifetime = appLifetime ?? throw new ArgumentNullException(nameof(appLifetime));

            _options = new MetricServerOptions
            {
                Host     = conf.Value.Host,
                Port     = conf.Value.Port,
                UseHttps = conf.Value.Https
            };

            if (!string.IsNullOrEmpty(conf.Value.Path))
            {
                _options.MapPath = conf.Value.Path;
            }


            _metricServer = new MetricServer(Prometheus.Client.Metrics.DefaultCollectorRegistry, _options);
        }
Ejemplo n.º 9
0
        static IApplicationBuilder UseMetricServerCore(this IApplicationBuilder app, PathString path, MetricServerOptions options)
        {
            app.Map(path, b => b.UseMiddleware <MetricServerMiddleware>(Options.Create(options)));

            return(app);
        }