public static ISolariBuilder AddCeres(this ISolariBuilder builder) { IConfigurationSection section = builder.Configuration.GetSection(CeresConstants.AppSettingsSection); if (!section.Exists()) { throw new CeresException("Ceres AppSettings section not found!"); } var options = section.GetOptions <CeresOptions>(); ApplicationOptions appOptions = builder.GetAppOptions(); var metricsBuilder = new MetricsBuilder(); if (!options.Enabled) { return(builder); } builder.Services.Configure <CeresOptions>(builder.Configuration.GetSection(CeresConstants.AppSettingsSection)); ConfigureMetricsBuilder(metricsBuilder, options, appOptions); builder.Services.AddMetrics(metricsBuilder.Build()); builder.Services.AddMetricsEndpoints(); ConfigureReporters.ConfigurePrometheus(options, metricsBuilder); ConfigureInfluxDb(builder, options, metricsBuilder); ConfigureEndpoints(builder, options); ConfigureMiddleware(builder, options.Middlewares); ConfigureCpuUsageMetric(builder, options.CollectCpuMetrics); ConfigureMemoryUsageMetric(builder, options.CollectMemoryMetrics); return(builder); }
private static void ConfigureInfluxDb(ISolariBuilder builder, CeresOptions options, IMetricsBuilder metricsBuilder) { if (options.InfluxDb is null || !options.InfluxDb.Enabled) { return; } ConfigureReporters.ConfigureInfluxDbReporter(options, metricsBuilder); builder.Services.AddMetricsReportingHostedService(); }