转载部分:
https://www.cnblogs.com/edisonchou/p/integrated_performance_monitoring_foundation.html
ConfigureServices下添加:
#region AppMetrics添加
bool isOpenMetrics = Convert.ToBoolean(Configuration["AppMetrics:IsOpen"]);
if (isOpenMetrics)
{
string database = Configuration["AppMetrics:DatabaseName"];
string connStr = Configuration["AppMetrics:ConnectionString"];
string app = Configuration["AppMetrics:App"];
string env = Configuration["AppMetrics:Env"];
string username = Configuration["AppMetrics:UserName"];
string password = Configuration["AppMetrics:Password"];
var uri = new Uri(connStr);
var metrics = AppMetrics.CreateDefaultBuilder().Configuration.Configure(options =>
{
options.AddAppTag(app);
options.AddEnvTag(env);
}).Report.ToInfluxDb(options =>
{
options.InfluxDb.BaseUri = uri;
options.InfluxDb.Database = database;
options.InfluxDb.UserName = username;
options.InfluxDb.Password = password;
options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
options.HttpPolicy.FailuresBeforeBackoff = 5;
options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
options.FlushInterval = TimeSpan.FromSeconds(5);
}).Build();
services.AddMetrics(metrics);
services.AddMetricsReportingHostedService();
//services.AddMetricsReportScheduler();
services.AddMetricsTrackingMiddleware();
services.AddMetricsEndpoints();
}
#endregion