标签:time service static factor ISE middle ONBUILD pen builder
使用InfluxDB、Grafana
influxdb:
image: influxdb
ports:
- "8086:8086"
- "8083:8083"
environment:
- INFLUXDB_DB=TogetherAppMetricsDB
- INFLUXDB_ADMIN_ENABLED=true
- INFLUXDB_ADMIN_USER=admin
- INFLUXDB_ADMIN_PASSWORD=admin
grafana:
image: grafana/grafana
ports:
- "3000:3000"
<本地ip>:3000
,使用默认账号登录> App.Metrics
> App.Metrics.AspNetCore.Endpoints
> App.Metrics.AspNetCore.Reporting
> App.Metrics.AspNetCore.Tracking
> App.Metrics.Reporting.InfluxDB
StartUp.cs
public void ConfigureServices(IServiceCollection services)
{
...
services.AddOptions();
services.Configure<AppMetricsOptions>(Configuration.GetSection("AppMetrics"));
services.AddAppMetrics(Configuration);
services.AddOcelot(Configuration);
}
public void Configure(ILoggerFactory loggerFactory, IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMetricsAllEndpoints();
app.UseMetricsAllMiddleware();
app.UseOcelot();
}
ServiceCollectionExtensions.cs
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddAppMetrics(this IServiceCollection services, IConfiguration configuration)
{
var options = services.BuildServiceProvider()
.GetRequiredService<IOptions<AppMetricsOptions>>()?.Value;
if (options?.IsOpen == true)
{
var uri = new Uri(options.ConnectionString);
var metrics = AppMetrics.CreateDefaultBuilder().Configuration.Configure(opt =>
{
opt.AddAppTag(options.App);
opt.AddEnvTag(options.Env);
}).Report.ToInfluxDb(opt =>
{
opt.InfluxDb.BaseUri = uri;
opt.InfluxDb.Database = options.DatabaseName;
opt.InfluxDb.UserName = options.UserName;
opt.InfluxDb.Password = options.Password;
opt.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
opt.HttpPolicy.FailuresBeforeBackoff = 5;
opt.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
opt.FlushInterval = TimeSpan.FromSeconds(5);
}).Build();
services.AddMetrics(metrics);
services.AddMetricsReportScheduler();
services.AddMetricsTrackingMiddleware();
services.AddMetricsEndpoints();
}
return services;
}
}
public class AppMetricsOptions
{
public bool IsOpen { get; set; }
public string DatabaseName { get; set; }
public string ConnectionString { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string App { get; set; }
public string Env { get; set; }
}
标签:time service static factor ISE middle ONBUILD pen builder
原文地址:https://www.cnblogs.com/zengande/p/9444284.html