private static void SetUpYAxis(ChartArea chartArea, MetricOptions options) { if (options.YAxisMax != null) { chartArea.AxisY.Maximum = options.YAxisMax.Value; } chartArea.AxisY.Title = "Cycle Time (Seconds) "; chartArea.AxisY.Minimum = 0; }
private static void SetSplitFailPassX2Axis(ChartArea chartArea, MetricOptions options) { chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Days; chartArea.AxisX2.LabelStyle.Format = " "; chartArea.AxisX2.Minimum = options.StartDate.ToOADate(); chartArea.AxisX2.Maximum = options.EndDate.ToOADate(); chartArea.AxisX2.Interval = 30; }
public static IHostBuilder CreateHostBuilder(IConfiguration config, string environment) { Console.Title = "Exceptionless Web"; var options = AppOptions.ReadFromConfiguration(config); var loggerConfig = new LoggerConfiguration().ReadFrom.Configuration(config); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey)) { loggerConfig.WriteTo.Sink(new ExceptionlessSink(), LogEventLevel.Verbose); } Log.Logger = loggerConfig.CreateLogger(); var configDictionary = config.ToDictionary("Serilog"); Log.Information("Bootstrapping Exceptionless Web in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", environment, options.InformationalVersion, Environment.MachineName, configDictionary); bool useApplicationInsights = !String.IsNullOrEmpty(options.ApplicationInsightsKey); var builder = Host.CreateDefaultBuilder() .UseEnvironment(environment) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseConfiguration(config) .ConfigureKestrel(c => { c.AddServerHeader = false; // c.AllowSynchronousIO = false; // TODO: Investigate issue with JSON Serialization. if (options.MaximumEventPostSize > 0) { c.Limits.MaxRequestBodySize = options.MaximumEventPostSize; } }) .UseStartup <Startup>(); var metricOptions = MetricOptions.ReadFromConfiguration(config); if (!String.IsNullOrEmpty(metricOptions.Provider)) { ConfigureMetricsReporting(webBuilder, metricOptions); } }) .ConfigureServices((ctx, services) => { services.AddSingleton(config); services.AddAppOptions(options); services.AddHttpContextAccessor(); if (useApplicationInsights) { services.AddSingleton <ITelemetryInitializer, ExceptionlessTelemetryInitializer>(); services.AddApplicationInsightsTelemetry(options.ApplicationInsightsKey); } }); return(builder); }
public static Chart ChartInitialization(MetricOptions options) { var chart = new Chart(); SetImageProperties(chart); chart.ChartAreas.Add(CreateChartArea(options)); return(chart); }
private static ChartArea CreateChartAreaNoX2AxisNoY2Axis(MetricOptions options) { var chartArea = new ChartArea(); chartArea.Name = "ChartArea1"; SetUpYAxis(chartArea, options); SetUpXAxis(chartArea, options); SetUpX2AxisNoLabels(chartArea, options); return(chartArea); }
private static void SetUpX2AxisNoLabels(ChartArea chartArea, MetricOptions options) { chartArea.AxisX2.Enabled = AxisEnabled.True; chartArea.AxisX2.MajorGrid.Enabled = false; chartArea.AxisX2.MajorTickMark.Enabled = false; chartArea.AxisX2.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX2.Minimum = options.StartDate.ToOADate(); chartArea.AxisX2.Maximum = options.EndDate.ToOADate(); chartArea.AxisX2.CustomLabels.Add(options.StartDate.ToOADate(), options.EndDate.ToOADate(), ""); }
/// <summary> /// Установка и настройка метрики для нового Niddleware. Метрики могут в себя включать следующие типы: Counter, Gauge, Summary, Histogram. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="builder"></param> /// <param name="configureOptions"></param> /// <returns></returns> public static IApplicationBuilder AddMetric <T>( this IApplicationBuilder builder, Action <IMetricOptions> configureOptions ) where T : IMetricMiddleware { var options = new MetricOptions(); configureOptions(options); return(builder.UseMiddleware <T>(options)); }
/// <summary> /// Increments counter /// </summary> /// <param name="configureOptions"></param> public void IncrementCounter(Action <IMetricOptions> configureOptions) { var options = new MetricOptions(); configureOptions(options); var counter = Prometheus.Metrics.CreateCounter(options.Name, options.Help, options.LabelNames); counter.WithLabels(options.LabelValues).Inc(); }
public void CreateFileNameReturnsStringTest() { MetricOptions options = NewOptionsForTest(); var expectedMetricType = _mtr.GetMetricsByID(1); string filename = options.CreateFileName(); Assert.IsTrue(filename.Contains(expectedMetricType.Abbreviation)); }
private MetricOptions NewOptionsForTest() { MetricOptions options = new MetricOptions { MetricTypeID = 1, MetricFileLocation = "C:\\Temp\\ATSPMImages", SignalID = _signalRepository.GetAllSignals().Take(1).FirstOrDefault().SignalID }; return(options); }
private static void SetUpY2Axis(ChartArea chartArea, MetricOptions options) { if (options.Y2AxisMax != null) { chartArea.AxisY2.Maximum = options.Y2AxisMax.Value; } chartArea.AxisY2.Enabled = AxisEnabled.True; chartArea.AxisY2.MajorTickMark.Enabled = false; chartArea.AxisY2.MajorGrid.Enabled = false; chartArea.AxisY2.IntervalType = DateTimeIntervalType.Number; chartArea.AxisY2.Title = options.Y2AxisTitle ?? ""; }
public static AppOptions ReadFromConfiguration(IConfiguration config) { var options = new AppOptions(); options.BaseURL = config.GetValue <string>(nameof(options.BaseURL))?.TrimEnd('/'); options.InternalProjectId = config.GetValue(nameof(options.InternalProjectId), "54b56e480ef9605a88a13153"); options.ExceptionlessApiKey = config.GetValue <string>(nameof(options.ExceptionlessApiKey)); options.ExceptionlessServerUrl = config.GetValue <string>(nameof(options.ExceptionlessServerUrl)); options.AppMode = config.GetValue(nameof(options.AppMode), AppMode.Production); options.AppScope = config.GetValue(nameof(options.AppScope), options.AppMode.ToScope()); options.RunJobsInProcess = config.GetValue(nameof(options.RunJobsInProcess), options.AppMode == AppMode.Development); options.JobsIterationLimit = config.GetValue(nameof(options.JobsIterationLimit), -1); options.BotThrottleLimit = config.GetValue(nameof(options.BotThrottleLimit), 25).NormalizeValue(); options.ApiThrottleLimit = config.GetValue(nameof(options.ApiThrottleLimit), options.AppMode == AppMode.Development ? Int32.MaxValue : 3500).NormalizeValue(); options.EnableArchive = config.GetValue(nameof(options.EnableArchive), true); options.EnableSampleData = config.GetValue(nameof(options.EnableSampleData), options.AppMode != AppMode.Development); options.EventSubmissionDisabled = config.GetValue(nameof(options.EventSubmissionDisabled), false); options.DisabledPipelineActions = config.GetValueList(nameof(options.DisabledPipelineActions)); options.DisabledPlugins = config.GetValueList(nameof(options.DisabledPlugins)); options.MaximumEventPostSize = config.GetValue(nameof(options.MaximumEventPostSize), 200000).NormalizeValue(); options.MaximumRetentionDays = config.GetValue(nameof(options.MaximumRetentionDays), 180).NormalizeValue(); options.GoogleGeocodingApiKey = config.GetValue <string>(nameof(options.GoogleGeocodingApiKey)); options.MaxMindGeoIpKey = config.GetValue <string>(nameof(options.MaxMindGeoIpKey)); options.BulkBatchSize = config.GetValue(nameof(options.BulkBatchSize), 1000); options.EnableRepositoryNotifications = config.GetValue(nameof(options.EnableRepositoryNotifications), true); options.EnableWebSockets = config.GetValue(nameof(options.EnableWebSockets), true); try { var versionInfo = FileVersionInfo.GetVersionInfo(typeof(AppOptions).Assembly.Location); options.Version = versionInfo.FileVersion; options.InformationalVersion = versionInfo.ProductVersion; } catch { } options.CacheOptions = CacheOptions.ReadFromConfiguration(config, options); options.MessageBusOptions = MessageBusOptions.ReadFromConfiguration(config, options); options.MetricOptions = MetricOptions.ReadFromConfiguration(config); options.QueueOptions = QueueOptions.ReadFromConfiguration(config, options); options.StorageOptions = StorageOptions.ReadFromConfiguration(config, options); options.EmailOptions = EmailOptions.ReadFromConfiguration(config, options); options.ElasticsearchOptions = ElasticsearchOptions.ReadFromConfiguration(config, options); options.IntercomOptions = IntercomOptions.ReadFromConfiguration(config); options.SlackOptions = SlackOptions.ReadFromConfiguration(config); options.StripeOptions = StripeOptions.ReadFromConfiguration(config); options.AuthOptions = AuthOptions.ReadFromConfiguration(config); return(options); }
/// <summary> /// Observes summary /// </summary> /// <param name="configureOptions"></param> public void ObserveSummary(Action <IMetricOptions> configureOptions) { var options = new MetricOptions(); configureOptions(options); var summary = Prometheus.Metrics.CreateSummary(options.Name, options.Help, new SummaryConfiguration { LabelNames = options.LabelNames }); summary.Observe(options.ObserveValue); }
/// <summary> /// Observes histogram /// </summary> /// <param name="configureOptions"></param> public void ObserveHistogram(Action <IMetricOptions> configureOptions) { var options = new MetricOptions(); configureOptions(options); var histogram = Prometheus.Metrics.CreateHistogram(options.Name, options.Help, new HistogramConfiguration { Buckets = options.Buckets }); histogram.Observe(options.ObserveValue); }
/// <summary> /// Increments gauge /// </summary> /// <param name="configureOptions"></param> public void IncrementGauge(Action <IMetricOptions> configureOptions) { var options = new MetricOptions(); configureOptions(options); var gauge = Prometheus.Metrics.CreateGauge(options.Name, options.Help, new GaugeConfiguration { LabelNames = options.LabelNames }); gauge.WithLabels(options.LabelValues).Inc(); }
internal DefaultMetricFamily(string name, MetricType type, MetricOptions options, Func <LabelValues, TMetric> factory) { Guard.ArgNotNull(factory, nameof(factory)); Guard.ValidMetricName(name, nameof(name)); var labels = Guard.ValidLabelNames(options.LabelNames); _factory = factory; Name = name; Type = type; Help = options.Help; LabelNames = labels; SupressInitialValue = options.SuppressInitialValue; }
private static IMetricsRoot BuildAppMetrics(MetricOptions options) { var metricsBuilder = AppMetrics.CreateDefaultBuilder(); switch (options.Provider) { case "graphite": metricsBuilder.Report.ToGraphite(new MetricsReportingGraphiteOptions { Graphite = { BaseUri = new Uri(options.Data.GetString("server")) } }); break; case "http": metricsBuilder.Report.OverHttp(new MetricsReportingHttpOptions { HttpSettings = { RequestUri = new Uri(options.Data.GetString("server")), UserName = options.Data.GetString("username"), Password = options.Data.GetString("password"), } }); break; case "influxdb": metricsBuilder.Report.ToInfluxDb(new MetricsReportingInfluxDbOptions { InfluxDb = { BaseUri = new Uri(options.Data.GetString("server")), UserName = options.Data.GetString("username"), Password = options.Data.GetString("password"), Database = options.Data.GetString("database", "exceptionless") } }); break; default: return(null); } return(metricsBuilder.Build()); }
public void CreateMetricTestHasMetricTypeInChartName() { MetricOptions options = NewOptionsForTest(); options.CreateMetric(); var expectedMetricType = _mtr.GetMetricsByID(1); Models.ApplicationEvent applicationEvent = _db.ApplicationEvents.Take(1).FirstOrDefault(); if (applicationEvent != null) { Assert.IsTrue(applicationEvent.Description.Contains(expectedMetricType.ChartName)); } else { Assert.Fail(); } }
private static void ConfigureMetricsReporting(IWebHostBuilder builder, MetricOptions options) { if (String.Equals(options.Provider, "prometheus")) { var metrics = AppMetrics.CreateDefaultBuilder() .OutputMetrics.AsPrometheusPlainText() .OutputMetrics.AsPrometheusProtobuf() .Build(); builder.ConfigureMetrics(metrics).UseMetrics(o => { o.EndpointOptions = endpointsOptions => { endpointsOptions.MetricsTextEndpointOutputFormatter = metrics.OutputMetricsFormatters.GetType <MetricsPrometheusTextOutputFormatter>(); endpointsOptions.MetricsEndpointOutputFormatter = metrics.OutputMetricsFormatters.GetType <MetricsPrometheusProtobufOutputFormatter>(); }; }); } else if (!String.Equals(options.Provider, "statsd")) { builder.UseMetrics(); } }
public SignalPhaseCollection(MetricOptions options, bool showVolume, int binSize) { var repository = SignalsRepositoryFactory.Create(); var signal = repository.GetVersionOfSignalByDate(options.SignalID, options.StartDate); var approaches = signal.GetApproachesForSignalThatSupportMetric(options.MetricTypeID); if (signal.Approaches != null && approaches.Count > 0) { //Parallel.ForEach(approaches, approach => foreach (Models.Approach approach in approaches) { if (approach.ProtectedPhaseNumber != 0) { var protectedSignalPhase = new SignalPhase(options.StartDate, options.EndDate, approach, showVolume, binSize, options.MetricTypeID, false); SignalPhaseList.Add(protectedSignalPhase); } }//); //TODO: Should we remove phases with no cycles? SignalPhaseList = SignalPhaseList.OrderBy(s => s.Approach.ProtectedPhaseNumber).ToList(); } }
public static MetricOptions ReadFromConfiguration(IConfiguration config) { var options = new MetricOptions(); string cs = config.GetConnectionString("Metrics"); options.Data = cs.ParseConnectionString(); options.Provider = options.Data.GetString(nameof(options.Provider)); var providerConnectionString = !String.IsNullOrEmpty(options.Provider) ? config.GetConnectionString(options.Provider) : null; if (!String.IsNullOrEmpty(providerConnectionString)) { options.Data.AddRange(providerConnectionString.ParseConnectionString()); } options.ConnectionString = options.Data.BuildConnectionString(new HashSet <string> { nameof(options.Provider) }); return(options); }
public void CreateFileNameCreatesImageDirectory() { string testDirPath = "C:\\Temp\\ATSPMImages"; MetricOptions options = NewOptionsForTest(); options.MetricFileLocation = testDirPath; DirectoryInfo di = new DirectoryInfo(testDirPath); di.Refresh(); if (di.Exists) { Directory.Delete(testDirPath); } string filename = options.CreateFileName(); di.Refresh(); Assert.IsTrue(di.Exists); }
private static void SetUpXAxis(ChartArea chartArea, MetricOptions options) { chartArea.AxisX.Minimum = options.StartDate.ToOADate(); chartArea.AxisX.Maximum = options.EndDate.ToOADate(); var reportTimespan = options.EndDate - options.StartDate; double totalMinutesRounded = Math.Round(reportTimespan.TotalMinutes); if (totalMinutesRounded <= 1) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Seconds; chartArea.AxisX.Interval = 1; chartArea.AxisX.LabelStyle.Format = "HH:mm:ss"; chartArea.AxisX.Title = "Time (Hours:Minutes:Seconds of Day)"; } else if (totalMinutesRounded > 1.0 && totalMinutesRounded <= 3.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Seconds; chartArea.AxisX.Interval = 3; chartArea.AxisX.LabelStyle.Format = "HH:mm:ss"; chartArea.AxisX.Title = "Time (Hours:Minutes:Seconds of Day)"; } else if (totalMinutesRounded > 3.0 && totalMinutesRounded <= 6.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Seconds; chartArea.AxisX.Interval = 15; chartArea.AxisX.LabelStyle.Format = "HH:mm:ss"; chartArea.AxisX.Title = "Time (Hours:Minutes:Seconds of Day)"; } else if (totalMinutesRounded > 6.0 && totalMinutesRounded <= 10.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Seconds; chartArea.AxisX.Interval = 30; chartArea.AxisX.LabelStyle.Format = "HH:mm:ss"; chartArea.AxisX.Title = "Time (Hours:Minutes:Seconds of Day)"; } else if (totalMinutesRounded > 10.0 && totalMinutesRounded <= 1.0 * 60.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Minutes; chartArea.AxisX.Interval = 5; chartArea.AxisX.LabelStyle.Format = "HH:mm"; chartArea.AxisX.Title = "Time (Hours:Minutes of Day)"; } else if (totalMinutesRounded > 1.0 * 60.0 && totalMinutesRounded <= 2.0 * 60.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Minutes; chartArea.AxisX.Interval = 15; chartArea.AxisX.LabelStyle.Format = "HH:mm"; chartArea.AxisX.Title = "Time (Hours:Minutes of Day)"; } else if (totalMinutesRounded > 2.0 * 60.0 && totalMinutesRounded <= 24.0 * 60.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.Interval = 1; chartArea.AxisX.LabelStyle.Format = "HH:mm"; chartArea.AxisX.Title = "Time (Hours:Minutes of Day)"; } else if (totalMinutesRounded > 24.0 * 60.0 && totalMinutesRounded <= 48.0 * 60.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.Interval = 12; chartArea.AxisX.LabelStyle.Format = "HH"; chartArea.AxisX.Title = "Time (Hours of Day)"; } else if (totalMinutesRounded > 48.0 * 60.0) { chartArea.AxisX.IntervalType = DateTimeIntervalType.Hours; chartArea.AxisX.Interval = 24; chartArea.AxisX.LabelStyle.Format = "MM/dd/yyyy"; chartArea.AxisX.Title = "Time (Days)"; } }
public static IWebHostBuilder CreateWebHostBuilder(IConfiguration config, string environment) { Console.Title = "Exceptionless Web"; var options = AppOptions.ReadFromConfiguration(config); var loggerConfig = new LoggerConfiguration().ReadFrom.Configuration(config); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey)) { loggerConfig.WriteTo.Sink(new ExceptionlessSink(), LogEventLevel.Verbose); } var serilogLogger = loggerConfig.CreateLogger(); _logger = new SerilogLoggerFactory(serilogLogger).CreateLogger <Program>(); var configDictionary = config.ToDictionary("Serilog"); _logger.LogInformation("Bootstrapping Exceptionless Web in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", environment, options.InformationalVersion, Environment.MachineName, configDictionary); bool useApplicationInsights = !String.IsNullOrEmpty(options.ApplicationInsightsKey); var builder = WebHost.CreateDefaultBuilder() .UseEnvironment(environment) .UseConfiguration(config) .UseDefaultServiceProvider((ctx, o) => { o.ValidateScopes = ctx.HostingEnvironment.IsDevelopment(); }) .ConfigureKestrel(c => { c.AddServerHeader = false; // c.AllowSynchronousIO = false; // TODO: Investigate issue with JSON Serialization. if (options.MaximumEventPostSize > 0) { c.Limits.MaxRequestBodySize = options.MaximumEventPostSize; } }) .UseSerilog(serilogLogger, true) .ConfigureServices((ctx, services) => { services.AddSingleton(config); services.AddHttpContextAccessor(); if (useApplicationInsights) { services.AddSingleton <ITelemetryInitializer, ExceptionlessTelemetryInitializer>(); services.AddApplicationInsightsTelemetry(); } services.PostConfigure <HostFilteringOptions>(o => { if (o.AllowedHosts == null || o.AllowedHosts.Count == 0) { // "AllowedHosts": "localhost;127.0.0.1;[::1]" var hosts = ctx.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Fall back to "*" to disable. o.AllowedHosts = (hosts?.Length > 0 ? hosts : new[] { "*" }); } }); services.AddSingleton <IOptionsChangeTokenSource <HostFilteringOptions> >(new ConfigurationChangeTokenSource <HostFilteringOptions>(ctx.Configuration)); services.AddTransient <IStartupFilter, HostFilteringStartupFilter>(); }) .UseStartup <Startup>(); if (String.IsNullOrEmpty(builder.GetSetting(WebHostDefaults.ContentRootKey))) { builder.UseContentRoot(Directory.GetCurrentDirectory()); } if (useApplicationInsights) { builder.UseApplicationInsights(options.ApplicationInsightsKey); } var metricOptions = MetricOptions.ReadFromConfiguration(config); if (!String.IsNullOrEmpty(metricOptions.Provider)) { ConfigureMetricsReporting(builder, metricOptions); } return(builder); }
static object GetOptions(MetricOptions metric = MetricOptions.Euclidean) => metric;
private DefaultHistogram(string name, MetricOptions options, ImmutableArray <double> buckets) : base(name, MetricType.Histogram, options, labels => new HistogramMetric(labels, buckets)) { Guard.InvalidLabel("Histogram", LabelNames, "le"); }
///<summary>GET /_nodes/{node_id}/stats/indices/{metric}/{fields} ///<pre>http://elasticsearch.org/guide/reference/api/admin-cluster-nodes-stats/</pre> ///</summary> ///<param name="fields">A comma-separated list of fields to return detailed information for, when returning the `indices` metric family (supports wildcards)</param> ///<param name="metric">Limit the information returned for `indices` family to a specific metric</param> ///<param name="node_id">A comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes</param> public Task<ConnectionStatus> ClusterNodeStatsGetAsync(string fields, MetricOptions metric, string node_id, Func<ClusterNodeStatsGetQueryString, ClusterNodeStatsGetQueryString> queryString = null) { fields.ThrowIfNull("fields"); metric.ThrowIfNull("metric"); node_id.ThrowIfNull("node_id"); var url = "/_nodes/{node_id}/stats/indices/{metric}/{fields}".Inject(new { fields = Stringify(fields), metric = Stringify(metric), node_id = Stringify(node_id) }); NameValueCollection nv = null; if (queryString != null) { var qs = queryString(new ClusterNodeStatsGetQueryString()); if (qs != null) nv = qs.NameValueCollection; } return this.DoRequestAsync("GET", url, data: null, queryString: nv); }
public static IWebHostBuilder CreateWebHostBuilder(string[] args) { var jobOptions = new JobRunnerOptions(args); Console.Title = jobOptions.JobName != null ? $"Exceptionless {jobOptions.JobName} Job" : "Exceptionless Jobs"; string environment = Environment.GetEnvironmentVariable("EX_AppMode"); if (String.IsNullOrWhiteSpace(environment)) { environment = "Production"; } string currentDirectory = Directory.GetCurrentDirectory(); var config = new ConfigurationBuilder() .SetBasePath(currentDirectory) .AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true) .AddYamlFile($"appsettings.{environment}.yml", optional: true, reloadOnChange: true) .AddEnvironmentVariables("EX_") .AddCommandLine(args) .Build(); var options = AppOptions.ReadFromConfiguration(config); var loggerConfig = new LoggerConfiguration().ReadFrom.Configuration(config); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey)) { loggerConfig.WriteTo.Sink(new ExceptionlessSink(), LogEventLevel.Verbose); } var serilogLogger = loggerConfig.CreateLogger(); _logger = new SerilogLoggerFactory(serilogLogger).CreateLogger <Program>(); var configDictionary = config.ToDictionary("Serilog"); _logger.LogInformation("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, configDictionary); bool useApplicationInsights = !String.IsNullOrEmpty(options.ApplicationInsightsKey); var builder = WebHost.CreateDefaultBuilder(args) .UseEnvironment(environment) .UseConfiguration(config) .UseDefaultServiceProvider((ctx, o) => { o.ValidateScopes = ctx.HostingEnvironment.IsDevelopment(); }) .ConfigureKestrel(c => { c.AddServerHeader = false; //c.AllowSynchronousIO = false; // TODO: Investigate issue with JSON Serialization. }) .UseSerilog(serilogLogger, true) .ConfigureServices((ctx, services) => { services.AddHttpContextAccessor(); AddJobs(services, jobOptions); if (useApplicationInsights) { services.AddApplicationInsightsTelemetry(); } Bootstrapper.RegisterServices(services); var serviceProvider = services.BuildServiceProvider(); Insulation.Bootstrapper.RegisterServices(serviceProvider, services, options, true); services.PostConfigure <HostFilteringOptions>(o => { if (o.AllowedHosts == null || o.AllowedHosts.Count == 0) { // "AllowedHosts": "localhost;127.0.0.1;[::1]" var hosts = ctx.Configuration["AllowedHosts"]?.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); // Fall back to "*" to disable. o.AllowedHosts = (hosts?.Length > 0 ? hosts : new[] { "*" }); } }); services.AddSingleton <IOptionsChangeTokenSource <HostFilteringOptions> >(new ConfigurationChangeTokenSource <HostFilteringOptions>(ctx.Configuration)); services.AddTransient <IStartupFilter, HostFilteringStartupFilter>(); }) .Configure(app => { Bootstrapper.LogConfiguration(app.ApplicationServices, options, _logger); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey) && !String.IsNullOrEmpty(options.ExceptionlessServerUrl)) { app.UseExceptionless(ExceptionlessClient.Default); } app.UseHealthChecks("/health", new HealthCheckOptions { Predicate = hcr => !String.IsNullOrEmpty(jobOptions.JobName) ? hcr.Tags.Contains(jobOptions.JobName) : hcr.Tags.Contains("AllJobs") }); app.UseHealthChecks("/ready", new HealthCheckOptions { Predicate = hcr => hcr.Tags.Contains("Critical") }); app.UseWaitForStartupActionsBeforeServingRequests(); app.Use((context, func) => context.Response.WriteAsync($"Running Job: {jobOptions.JobName}")); }); if (String.IsNullOrEmpty(builder.GetSetting(WebHostDefaults.ContentRootKey))) { builder.UseContentRoot(Directory.GetCurrentDirectory()); } if (useApplicationInsights) { builder.UseApplicationInsights(options.ApplicationInsightsKey); } var metricOptions = MetricOptions.ReadFromConfiguration(config); if (!String.IsNullOrEmpty(metricOptions.Provider)) { ConfigureMetricsReporting(builder, metricOptions); } return(builder); }
public static IHostBuilder CreateHostBuilder(string[] args) { var jobOptions = new JobRunnerOptions(args); Console.Title = jobOptions.JobName != null ? $"Exceptionless {jobOptions.JobName} Job" : "Exceptionless Jobs"; string environment = Environment.GetEnvironmentVariable("EX_AppMode"); if (String.IsNullOrWhiteSpace(environment)) { environment = "Production"; } var config = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddYamlFile("appsettings.yml", optional: true, reloadOnChange: true) .AddYamlFile($"appsettings.{environment}.yml", optional: true, reloadOnChange: true) .AddEnvironmentVariables("EX_") .AddEnvironmentVariables("ASPNETCORE_") .AddCommandLine(args) .Build(); var options = AppOptions.ReadFromConfiguration(config); var loggerConfig = new LoggerConfiguration().ReadFrom.Configuration(config); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey)) { loggerConfig.WriteTo.Sink(new ExceptionlessSink(), LogEventLevel.Verbose); } Log.Logger = loggerConfig.CreateLogger(); var configDictionary = config.ToDictionary("Serilog"); Log.Information("Bootstrapping Exceptionless {JobName} job(s) in {AppMode} mode ({InformationalVersion}) on {MachineName} with settings {@Settings}", jobOptions.JobName ?? "All", environment, options.InformationalVersion, Environment.MachineName, configDictionary); bool useApplicationInsights = !String.IsNullOrEmpty(options.ApplicationInsightsKey); var builder = Host.CreateDefaultBuilder() .UseEnvironment(environment) .UseSerilog() .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseConfiguration(config) .Configure(app => { app.UseSerilogRequestLogging(o => o.GetLevel = (context, duration, ex) => { if (ex != null || context.Response.StatusCode > 499) { return(LogEventLevel.Error); } return(duration < 1000 && context.Response.StatusCode < 400 ? LogEventLevel.Debug : LogEventLevel.Information); }); }) .Configure(app => { Bootstrapper.LogConfiguration(app.ApplicationServices, options, app.ApplicationServices.GetService <ILogger <Program> >()); if (!String.IsNullOrEmpty(options.ExceptionlessApiKey) && !String.IsNullOrEmpty(options.ExceptionlessServerUrl)) { app.UseExceptionless(ExceptionlessClient.Default); } app.UseHealthChecks("/health", new HealthCheckOptions { Predicate = hcr => !String.IsNullOrEmpty(jobOptions.JobName) ? hcr.Tags.Contains(jobOptions.JobName) : hcr.Tags.Contains("AllJobs") }); app.UseHealthChecks("/ready", new HealthCheckOptions { Predicate = hcr => hcr.Tags.Contains("Critical") }); app.UseWaitForStartupActionsBeforeServingRequests(); app.Use((context, func) => context.Response.WriteAsync($"Running Job: {jobOptions.JobName}")); }); var metricOptions = MetricOptions.ReadFromConfiguration(config); if (!String.IsNullOrEmpty(metricOptions.Provider)) { ConfigureMetricsReporting(webBuilder, metricOptions); } }) .ConfigureServices((ctx, services) => { AddJobs(services, jobOptions); services.AddAppOptions(options); if (useApplicationInsights) { services.AddApplicationInsightsTelemetry(options.ApplicationInsightsKey); } Bootstrapper.RegisterServices(services); Insulation.Bootstrapper.RegisterServices(services, options, true); }); return(builder); }
public void MetricOptionsTest() { MetricOptions options = NewOptionsForTest(); Assert.IsTrue(options.Y2AxisMin == 0); }
private static IHealthChecksBuilder RegisterHealthChecks(IServiceCollection services, CacheOptions cacheOptions, MessageBusOptions messageBusOptions, MetricOptions metricOptions, StorageOptions storageOptions, QueueOptions queueOptions) { services.AddStartupActionToWaitForHealthChecks("Critical"); return(services.AddHealthChecks() .AddCheckForStartupActions("Critical") .AddAutoNamedCheck <ElasticsearchHealthCheck>("Critical") .AddAutoNamedCheck <CacheHealthCheck>("Critical") .AddAutoNamedCheck <StorageHealthCheck>("EventPosts", "AllJobs") .AddAutoNamedCheck <QueueHealthCheck <EventPost> >("EventPosts", "AllJobs") .AddAutoNamedCheck <QueueHealthCheck <EventUserDescription> >("EventUserDescriptions", "AllJobs") .AddAutoNamedCheck <QueueHealthCheck <EventNotificationWorkItem> >("EventNotifications", "AllJobs") .AddAutoNamedCheck <QueueHealthCheck <WebHookNotification> >("WebHooks", "AllJobs") .AddAutoNamedCheck <QueueHealthCheck <MailMessage> >("AllJobs") .AddAutoNamedCheck <QueueHealthCheck <WorkItemData> >("WorkItem", "AllJobs") .AddAutoNamedCheck <CloseInactiveSessionsJob>("AllJobs") .AddAutoNamedCheck <DailySummaryJob>("AllJobs") .AddAutoNamedCheck <DownloadGeoIPDatabaseJob>("AllJobs") .AddAutoNamedCheck <MaintainIndexesJob>("AllJobs") .AddAutoNamedCheck <RetentionLimitsJob>("AllJobs") .AddAutoNamedCheck <StackEventCountJob>("AllJobs")); }