Пример #1
0
        public static IWebHostBuilder UseAppMetrics(this IWebHostBuilder webHostBuilder)
        {
            return(webHostBuilder
                   .ConfigureMetricsWithDefaults((context, builder) =>
            {
                var metricsOptions = new MetricsOptions();
                context.Configuration.GetSection("Metrics").Bind(metricsOptions);

                if (!metricsOptions.Enabled)
                {
                    return;
                }

                builder.Report.ToInfluxDb(o =>
                {
                    o.InfluxDb.Database = metricsOptions.Database;
                    o.InfluxDb.BaseUri = new Uri(metricsOptions.InfluxUrl);
                    o.InfluxDb.CreateDataBaseIfNotExists = true;
                    o.FlushInterval = TimeSpan.FromSeconds(metricsOptions.Interval);
                });
            })
                   .UseHealth()
                   .UseHealthEndpoints()
                   .UseMetricsWebTracking()
                   .UseMetrics());
        }
Пример #2
0
        public static IWebHostBuilder UseMonitoring(this IWebHostBuilder builder, bool enabled)
        {
            builder
            .ConfigureMetricsWithDefaults(bld =>
            {
                bld.Configuration.Configure(
                    options =>
                {
                    options.Enabled          = enabled;
                    options.ReportingEnabled = true;
                });
                if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("INFLUXDB")))
                {
                    bld.Report.ToInfluxDb(options =>
                    {
                        options.InfluxDb.BaseUri  = new Uri(Environment.GetEnvironmentVariable("INFLUXDB"));
                        options.InfluxDb.Database = "fluentdispatch";
                        options.FlushInterval     = TimeSpan.FromSeconds(5);
                        options.InfluxDb.CreateDataBaseIfNotExists = true;
                        options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
                    });
                }
            });

            builder.UseMetricsWebTracking();
            builder.UseMetrics <MetricsStartup>();
            return(builder);
        }
Пример #3
0
        public static IWebHostBuilder UseMetrics(this IWebHostBuilder hostBuilder, string metricsConfigurationKey)
        {
            hostBuilder.ConfigureMetricsWithDefaults((hostingContext, builder) =>
            {
                builder.AddReport(hostingContext.Configuration.GetSection(metricsConfigurationKey));
            });

            hostBuilder.UseMetricsWebTracking();
            hostBuilder.UseMetrics();
            return(hostBuilder);
        }
Пример #4
0
 public static void ConfigureMetrics(IWebHostBuilder webBuilder)
 {
     webBuilder.ConfigureMetricsWithDefaults((context, builder) =>
     {
         builder.Configuration.ReadFrom(context.Configuration);
         builder.Report.ToInfluxDb(options =>
         {
             options.FlushInterval = TimeSpan.FromSeconds(5);
             context.Configuration.GetSection("MetricsOptions").Bind(options);
             options.MetricsOutputFormatter = new MetricsInfluxDbLineProtocolOutputFormatter();
         });
     });
     webBuilder.UseMetrics();
 }
        public static IWebHostBuilder ConfigureMetricsWithDefaults(this IWebHostBuilder hostBuilder, Action <IMetricsBuilder> configureMetrics)
        {
            if (_metricsBuilt)
            {
                throw new InvalidOperationException("MetricsBuilder allows creation only of a single instance of IMetrics");
            }

            hostBuilder.ConfigureMetricsWithDefaults(
                (context, builder) =>
            {
                configureMetrics(builder);
            });

            return(hostBuilder);
        }
        public static IWebHostBuilder UseMonitoring(this IWebHostBuilder builder, IMonitoringComponent monitoringComponent)
        {
            builder
            .ConfigureMetricsWithDefaults((context, bld) =>
            {
                bld.Configuration.Configure(
                    options =>
                {
                    options.Enabled          = true;
                    options.ReportingEnabled = true;
                });
                monitoringComponent.UseMonitoring(bld.Report);
            });

            builder.UseMetricsWebTracking();
            builder.UseMetrics <MetricsStartup>();
            return(builder);
        }
Пример #7
0
        public static IWebHostBuilder UseAppMetrics(this IWebHostBuilder webHostBuilder)
        => webHostBuilder.ConfigureMetricsWithDefaults((context, builder) =>
        {
            var options = context.Configuration.GetOptions <MetricsOptions>("metrics");
            if (!options.Enabled)
            {
                return;
            }

            if (options.InfluxEnabled)
            {
                builder.Report.ToInfluxDb(o =>
                {
                    o.InfluxDb.Database = options.Database;
                    o.InfluxDb.BaseUri  = new Uri(options.InfluxUrl);
                    o.InfluxDb.CreateDataBaseIfNotExists = true;
                    o.FlushInterval = TimeSpan.FromSeconds(options.Interval);
                });
            }

            if (options.PrometheusEnabled)
            {
                builder
                .OutputMetrics.AsPrometheusPlainText()
                .OutputMetrics.AsPrometheusProtobuf();
            }
        }
                                                       )
        .UseHealth()
        .UseHealthEndpoints()
        .UseMetricsWebTracking()
        .UseMetricsEndpoints((context, setup) =>
        {
            var options = context.Configuration.GetOptions <MetricsOptions>("metrics");
            if (options.PrometheusEnabled)
            {
                setup.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
                setup.MetricsEndpointOutputFormatter     = new MetricsPrometheusProtobufOutputFormatter();
            }
        })
        .UseMetrics();
Пример #8
0
        public static IWebHostBuilder AddAppMetrics(this IWebHostBuilder builder, string serviceName)
        {
            Requires.NotNullOrWhiteSpace(serviceName, nameof(serviceName));

            builder.ConfigureMetricsWithDefaults(metricsBuilder => {
                metricsBuilder.Configuration.Configure(metricOptions => {
                    metricOptions.GlobalTags.Add("service-name", serviceName);
                });

                // Filter out internal App.Metrics library metrics
                metricsBuilder.Filter.With(new MetricsFilter().WhereContext(context => context != "appmetrics.internal"));

                metricsBuilder.SampleWith.Reservoir(() => new ForwardDecayingLowWeightThresholdReservoir(
                                                        sampleSize: 100,
                                                        alpha: 0.1,                   // Bias heavily towards lasst 15 seconds of sampling; disregard everything older than 40 seconds
                                                        sampleWeightThreshold: 0.001, // Samples with weight of less than 10% of average should be discarded when rescaling
                                                        clock: new App.Metrics.Infrastructure.StopwatchClock(),
                                                        rescaleScheduler: new FixedPeriodReservoirRescaleScheduler(TimeSpan.FromSeconds(30))
                                                        ));

                metricsBuilder.Report.ToInfluxDb(Endpoint, "dbname_unused", TimeSpan.FromSeconds(10));
                // DEBUG metricsBuilder.Report.ToConsole(TimeSpan.FromSeconds(10));
            })

            .UseMetrics <MinimalRequestTracking>(webHostMetricOptions => {
                webHostMetricOptions.EndpointOptions = (endpointOptions) => {
                    endpointOptions.EnvironmentInfoEndpointEnabled = false;
                    endpointOptions.MetricsEndpointEnabled         = false;
                    endpointOptions.MetricsTextEndpointEnabled     = true;
                };

                webHostMetricOptions.TrackingMiddlewareOptions = (trackingOptions) => {
                    trackingOptions.ApdexTrackingEnabled = false;
                    // trackingOptions.ApdexTSeconds = 1.0;
                    trackingOptions.IgnoredHttpStatusCodes.Add((int)HttpStatusCode.NotFound);
                    trackingOptions.OAuth2TrackingEnabled = false;
                };
            });

            return(builder);
        }
Пример #9
0
 public static IWebHostBuilder UseStandardMetrics(this IWebHostBuilder webHostBuilder)
 {
     return(webHostBuilder
            .ConfigureMetricsWithDefaults((webHostBuilderContext, metricsBuilder) =>
     {
         var influxDb = webHostBuilderContext.Configuration["AppMetrics:InfluxDbServer"];
         if (!string.IsNullOrWhiteSpace(influxDb))
         {
             var influxDatabase = webHostBuilderContext.Configuration["AppMetrics:InfluxDbDatabase"];
             if (!string.IsNullOrWhiteSpace(influxDatabase))
             {
                 Console.WriteLine($"Report To {influxDb}/{influxDatabase}");
                 metricsBuilder.Report.ToInfluxDb(o =>
                 {
                     o.InfluxDb.BaseUri = new Uri(influxDb);
                     o.InfluxDb.Database = influxDatabase;
                     o.FlushInterval = TimeSpan.FromSeconds(5);
                     o.InfluxDb.CreateDataBaseIfNotExists = true;
                 });
             }
         }
     })
            .UseMetrics());
 }
Пример #10
0
 internal static IWebHostBuilder ConfigureMetric(this IWebHostBuilder @this) => @this
 .ConfigureMetricsWithDefaults(builder =>
 {
     builder.OutputMetrics.AsPrometheusPlainText();
     builder.OutputMetrics.AsPrometheusProtobuf();
 })
 .UseMetricsEndpoints(options =>
 {
     options.MetricsTextEndpointOutputFormatter = new MetricsPrometheusTextOutputFormatter();
     options.MetricsEndpointOutputFormatter     = new MetricsPrometheusTextOutputFormatter();
 })
 .UseMetricsWebTracking();