Example #1
0
 public static IServiceCollection UseMetrics(
     this IServiceCollection services,
     Microsoft.Extensions.Configuration.IConfiguration configuration,
     IHostingEnvironment env)
 {
     _metricsSettings = new MetricsSettings();
     configuration.GetSection("MetricsSettings").Bind(_metricsSettings);
     if (_metricsSettings.UseMetrics)
     {
         services.AddMetrics(options =>
         {
             options.WithGlobalTags((globalTags, info) =>
             {
                 globalTags.Add("app", info.EntryAssemblyName);
                 globalTags.Add("env", env.EnvironmentName);
             });
         })
         .AddHealthChecks()
         .AddReporting(
             factory =>
         {
             factory.AddInfluxDb(
                 new InfluxDBReporterSettings
             {
                 InfluxDbSettings = new InfluxDBSettings(_metricsSettings.InfluxDatabase, new Uri(_metricsSettings.InfluxServer)),
                 ReportInterval   = TimeSpan.FromSeconds(5)
             });
         })
         .AddMetricsMiddleware(options => options.IgnoredHttpStatusCodes = new[] { 404 });
     }
     return(services);
 }
Example #2
0
        /// <summary>
        /// injecting Metrics related dependencies
        /// </summary>
        /// <param name="services"></param>
        /// <typeparam name="TService"></typeparam>
        /// <typeparam name="TImplementation"></typeparam>
        protected void ConfigureMetrics <TService, TImplementation>(IServiceCollection services)
            where TService : class
            where TImplementation : class, TService
        {
            var metricsSettings = new MetricsSettings();

            Configuration.GetSection("Metrics").Bind(metricsSettings);
            var metricsAgent = new MetricsAgent(metricsSettings);

            services.AddSingleton <IMetricsAgent>(metricsAgent);
            services.AddSingleton <TService, TImplementation>();
        }
Example #3
0
        /// <summary>
        /// Runs the application
        /// </summary>
        /// <returns></returns>
        private async Task RunAsync()
        {
            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
            AssemblyLoadContext.Default.Unloading      += OnShutdown;
            Console.CancelKeyPress += OnCancelKeyPress;

            try
            {
                _logger.Information("Starting Ditto. Press Ctrl+C to exit.");

                // Log the configuration if running in Development mode
                if (IsDevelopmentEnvironment())
                {
                    _logger.Information(_configuration.Dump());
                }

                _serviceProvider = AppRegistry.Register(_configuration, new ServiceCollection()).BuildServiceProvider();
                _service         = _serviceProvider.GetService <AppService>();
                await _service.StartAsync();

                MetricsSettings metrics = _configuration.Bind <MetricsSettings>("Metrics");

                if (metrics.Enabled)
                {
                    _logger.Information("Starting metrics server at {MetricsUrl}:{MetricsPort}", metrics.Path, metrics.Port);
                    _metricsServer = new MetricServer(port: metrics.Port, url: metrics.Path);
                    _metricsServer.Start();
                }

                // Block until an exit signal is detected
                _closing.WaitOne();
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Error starting Ditto");
            }
        }
Example #4
0
 public MetricSource(ILogger <MetricSource> logger, IRepository repository, IOptions <MetricsSettings> settings)
 {
     Repository = repository;
     _settings  = settings.Value;
     _logger    = logger;
 }
 public ServiceModule(MetricsSettings settings, ILog log)
 {
     _settings = settings;
     _log      = log;
 }
 public PhotoPercentageMetric(IMetricSource source, IOptions <MetricsSettings> settings) : base(source)
 {
     _settings = settings.Value;
 }