Beispiel #1
0
        public void can_generate_influx_write_endpoint()
        {
            var settings = new InfluxDBSettings("testdb", new Uri("http://localhost"))
            {
                RetensionPolicy = "defaultrp",
                Consistenency   = "consistency"
            };

            settings.Endpoint.Should().Be("write?db=testdb&rp=defaultrp&consistency=consistency");
        }
Beispiel #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="InfluxDBReporterSettings" /> class.
 /// </summary>
 public InfluxDBReporterSettings()
 {
     InfluxDbSettings = new InfluxDBSettings();
     HttpPolicy       = new HttpPolicy
     {
         FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff,
         BackoffPeriod         = Constants.DefaultBackoffPeriod,
         Timeout = Constants.DefaultTimeout
     };
     ReportInterval      = TimeSpan.FromSeconds(5);
     MetricNameFormatter = (metricContext, metricName) => $"{metricContext}__{metricName}".Replace(' ', '_').ToLowerInvariant();
 }
Beispiel #3
0
        public void database_cannot_be_whitespace()
        {
            Action action = () =>
            {
                var settings = new InfluxDBSettings(" ", new Uri("http://localhost"))
                {
                    RetensionPolicy = "defaultrp",
                    Consistenency   = "consistency"
                };
            };

            action.ShouldThrow <ArgumentException>();
        }
Beispiel #4
0
        public void base_address_cannot_be_null()
        {
            Action action = () =>
            {
                var settings = new InfluxDBSettings("influx", null)
                {
                    RetensionPolicy = "defaultrp",
                    Consistenency   = "consistency"
                };
            };

            action.ShouldThrow <ArgumentNullException>();
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="InfluxDBReporterSettings" /> class.
 /// </summary>
 public InfluxDBReporterSettings()
 {
     InfluxDbSettings = new InfluxDBSettings();
     HttpPolicy       = new HttpPolicy
     {
         FailuresBeforeBackoff = Constants.DefaultFailuresBeforeBackoff,
         BackoffPeriod         = Constants.DefaultBackoffPeriod,
         Timeout = Constants.DefaultTimeout
     };
     ReportInterval      = TimeSpan.FromSeconds(5);
     MetricNameFormatter = InfluxDBConstants.MetricNameFormatter;
     DataKeys            = new MetricValueDataKeys();
 }
Beispiel #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            var influxDbSettings = new InfluxDBSettings("apiappmetricsnet472", new Uri("http://192.168.137.253:8086"));

            influxDbSettings.UserName = "******";
            influxDbSettings.Password = "******";
            services.AddLogging();

            services.AddControllersAsServices();

            services
            .AddMetrics(options =>
            {
                options.DefaultContextLabel = "Api.AppMetrics.NET472";    //期望别名,这里建议采用项目的简写名称,保证项目之间不存在冲突即可
                options.ReportingEnabled    = true;
            }, Assembly.GetExecutingAssembly().GetName())
            .AddReporting(factory =>
            {
                factory.AddInfluxDb(new InfluxDBReporterSettings
                {
                    HttpPolicy = new HttpPolicy
                    {
                        FailuresBeforeBackoff = 3,                        //指标未能向指标入口端点报告时,在回退之前的失败次数。
                        BackoffPeriod         = TimeSpan.FromSeconds(30), //当指标无法向指标入口端点报告时,从后退
                        Timeout = TimeSpan.FromSeconds(3)                 //尝试向度量标准入口端点报告度量标准时的HTTP超时持续时间
                    },
                    InfluxDbSettings = influxDbSettings,                  //influx database,url

                    ReportInterval = TimeSpan.FromSeconds(5),
                });
            })
            .AddHealthChecks(factory =>
            {
                factory.RegisterProcessPrivateMemorySizeHealthCheck("Private Memory Size", 200);
                factory.RegisterProcessVirtualMemorySizeHealthCheck("Virtual Memory Size", 200);
                factory.RegisterProcessPhysicalMemoryHealthCheck("Working Set", 200);
            })
            .AddJsonSerialization()
            .AddMetricsMiddleware(options =>
            {
            });
        }
Beispiel #7
0
        public void ConfigureServices(IServiceCollection services)
        {
            var influxDbSettings = new InfluxDBSettings(AppSetting.InfluxDB.DatabaseName,
                                                        new Uri(AppSetting.InfluxDB.Url));

            services.AddLogging();

            services.AddControllersAsServices();

            services.AddMetrics(options =>
            {
                options.DefaultContextLabel = "Api.Sample.Net452";
                options.ReportingEnabled    = true;
            }, Assembly.GetExecutingAssembly().GetName())
            .AddReporting(factory =>
            {
                factory.AddInfluxDb(new InfluxDBReporterSettings
                {
                    HttpPolicy = new HttpPolicy
                    {
                        FailuresBeforeBackoff = 3,
                        BackoffPeriod         = TimeSpan.FromSeconds(30),
                        Timeout = TimeSpan.FromSeconds(3)
                    },
                    InfluxDbSettings = influxDbSettings,
                    ReportInterval   = TimeSpan.FromSeconds(5)
                });
            })
            .AddHealthChecks(factory =>
            {
                factory.RegisterProcessPrivateMemorySizeHealthCheck("Private Memory Size",
                                                                    200);
                factory.RegisterProcessVirtualMemorySizeHealthCheck("Virtual Memory Size",
                                                                    200);
                factory.RegisterProcessPhysicalMemoryHealthCheck("Working Set", 200);
            })
            .AddJsonSerialization()
            .AddMetricsMiddleware(options => { });
        }