asp.net core api网关 实时性能监控
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了asp.net core api网关 实时性能监控,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2702字,纯文字阅读大概需要4分钟。
内容图文
asp.net core api网关 实时性能监控
使用InfluxDB、Grafana
Dockerfile 运行 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"
配置 Grafana
- 浏览器打开
<本地ip>:3000
,使用默认账号登录 - 添加数据源
在Configuration中点击Add data source按钮,输入你安装的InfluxDB数据库信息 - 点击仪表板设置模板
在API网关中App.Metrics
- 安装必要的nuget包
> App.Metrics
> App.Metrics.AspNetCore.Endpoints
> App.Metrics.AspNetCore.Reporting
> App.Metrics.AspNetCore.Tracking
> App.Metrics.Reporting.InfluxDB
- ConfigureServices 配置
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; }
}
最终效果
参考文章
- .NET Core微服务之基于App.Metrics+InfluxDB+Grafana实现统一性能监控
- ASP.NET Core Real-time Performance Monitoring
- influxdb docker 文档
- grafana 官方文档
原文:https://www.cnblogs.com/zengande/p/9444284.html
内容总结
以上是互联网集市为您收集整理的asp.net core api网关 实时性能监控全部内容,希望文章能够帮你解决asp.net core api网关 实时性能监控所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。