예제 #1
0
        public static void AddPrometheusMetrics(
            this IServiceCollection services,
            IConfiguration configuration)
        {
            PrometheusMetricsConfig prometheusConfig = new PrometheusMetricsConfig();

            configuration.Bind("PrometheusMetrics", prometheusConfig);
            services.AddSingleton(Options.Create(prometheusConfig));

            if (prometheusConfig.Enabled)
            {
                services.Add <PrometheusMetricsServer>()
                .Singleton()
                .AsService <IStartable>();

                if (prometheusConfig.SystemMetrics)
                {
                    services.AddSystemMetrics();
                }
            }
        }
#pragma warning restore CA2213

        public PrometheusMetricsServer(IOptions <PrometheusMetricsConfig> config, ILogger <PrometheusMetricsServer> logger)
        {
            _prometheusMetricsConfig = config.Value;
            _logger = logger;
        }