Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc((MvcOptions options) =>
            {
                options.Filters.Add(new ProducesAttribute("application/json"));

                // HACK We need to disable EndpointRouting in order to run properly in 3.1
                System.Reflection.PropertyInfo prop = options.GetType().GetProperty("EnableEndpointRouting");
                prop?.SetValue(options, false);
            }).SetCompatibilityVersion(CompatibilityVersion.Latest);

            services.Configure <GzipCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });

            services.AddResponseCompression(configureOptions =>
            {
                configureOptions.Providers.Add <GzipCompressionProvider>();
                configureOptions.MimeTypes = new List <string> {
                    "application/octet-stream"
                };
            });

            var config = new PrometheusConfiguration();

            Configuration.Bind(nameof(PrometheusConfiguration), config);
            if (config.Enabled)
            {
                services.AddSingleton <MetricsStoreService>();
                services.AddHostedService <MetricsService>();
            }
        }
Ejemplo n.º 2
0
 public MetricsController(ILogger <MetricsController> logger,
                          MetricsStoreService metricsStore,
                          IOptions <PrometheusConfiguration> prometheusConfiguration)
 {
     _logger                  = logger;
     _metricsStore            = metricsStore;
     _prometheusConfiguration = prometheusConfiguration.Value;
 }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add(new ProducesAttribute("application/json"));

                options.EnableEndpointRouting = false;
            })
            .SetCompatibilityVersion(CompatibilityVersion.Latest)
            .AddApplicationPart(typeof(DiagController).Assembly);

            services.Configure <ApiBehaviorOptions>(options =>
            {
                options.InvalidModelStateResponseFactory = context =>
                {
                    var details = new ValidationProblemDetails(context.ModelState);
                    var result  = new BadRequestObjectResult(details);
                    result.ContentTypes.Add("application/problem+json");
                    return(result);
                };
            });

            services.Configure <BrotliCompressionProviderOptions>(options =>
            {
                options.Level = CompressionLevel.Optimal;
            });

            services.AddResponseCompression(configureOptions =>
            {
                configureOptions.Providers.Add <BrotliCompressionProvider>();
                configureOptions.MimeTypes = new List <string> {
                    "application/octet-stream"
                };
            });

            // This is needed to allow the StreamingLogger to synchronously write to the output stream.
            // Eventually should switch StreamingLoggger to something that allows for async operations.
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            var prometheusConfig = new PrometheusConfiguration();

            Configuration.Bind(nameof(PrometheusConfiguration), prometheusConfig);
            if (prometheusConfig.Enabled)
            {
                services.AddSingleton <MetricsStoreService>();
                services.AddHostedService <MetricsService>();
            }
        }
        public RuntimeConfigurationGenerator WithPrometheusConfiguration(double?metricUnavailableValue = -1, bool?enableMetricsTimestamp = false, string scrapeEndpointBaseUri = "/scrape-endpoint")
        {
            PrometheusConfiguration prometheusConfiguration;

            if (string.IsNullOrWhiteSpace(scrapeEndpointBaseUri) && metricUnavailableValue == null)
            {
                prometheusConfiguration = null;
            }
            else
            {
                prometheusConfiguration = new PrometheusConfiguration();

                if (string.IsNullOrWhiteSpace(scrapeEndpointBaseUri) == false)
                {
                    prometheusConfiguration.ScrapeEndpoint = new ScrapeEndpointConfiguration
                    {
                        BaseUriPath = scrapeEndpointBaseUri
                    };
                }

                if (metricUnavailableValue != null)
                {
                    prometheusConfiguration.MetricUnavailableValue = (double)metricUnavailableValue;
                }

                if (enableMetricsTimestamp != null)
                {
                    prometheusConfiguration.EnableMetricTimestamps = (bool)enableMetricsTimestamp;
                    _isEnableMetricTimestampsInPrometheusSpecified = true;
                }
            }

            _runtimeConfiguration.Prometheus = prometheusConfiguration;

            return(this);
        }