/// <summary> /// Initialize with ILoggerFactory /// <inheritdoc cref="IPrometheusAdapter.FetchPrometheusMonitorData(IEnumerable{KeyValuePair{string, string}})"/> /// </summary> /// <param name="config"></param> /// <param name="httpClient"></param> /// <param name="loggerFactory"></param> public PrometheusAdapter(PrometheusConfig config, HttpClient httpClient, ILoggerFactory loggerFactory) { this._logger = loggerFactory.CreateLogger <PrometheusAdapter>(); this._httpClient = httpClient; this._httpClient.BaseAddress = new Uri(new Uri($"http://{config.Host}:{config.Port}"), config.APIPath); _logger.LogDebug($"{this.GetType()} initialized"); }
static void Main(string[] args) { var configuration = new ConfigurationBuilder() .AddJsonFile("appsettings.json") .Build(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(configuration) .CreateLogger(); var serviceCollection = new ServiceCollection(); ConfigureServices(serviceCollection); var serviceProvider = serviceCollection.BuildServiceProvider(); var logger = serviceProvider.GetService <ILogger <Program> >(); var monitoringConfig = new MonitoringConfig(); configuration.GetSection("MonitoringConfig").Bind(monitoringConfig); var prometheus = new PrometheusConfig(); configuration.GetSection(Constants.DefaultMetricsServerName).Bind(prometheus); MetricPusher metricServer = null; if (!string.IsNullOrEmpty(prometheus.Instance) && !string.IsNullOrEmpty(prometheus.Endpoint)) { metricServer = new MetricPusher(endpoint: prometheus.Endpoint, job: "FileMonitoring", instance: prometheus.Instance); metricServer.Start(); } logger.LogInformation("Приложение запущено"); if (FailedMigrateDb.CountExceptions(() => MigrateDb(configuration, logger))) { //запуск планировщика задач var mainSheduler = new MainSheduler(monitoringConfig, logger, configuration, JobsGaugeException, metricServer); logger.LogInformation("Для завершения работы нажмите клавишу Q"); var stopKey = new ConsoleKeyInfo(); while (stopKey.Key != ConsoleKey.Q) { stopKey = Console.ReadKey(); } mainSheduler.Dispose(); metricServer?.Stop(); } logger.LogInformation("Приложение завершило работу"); }