HttpReports 基于.NET Core 开发的APM监控系统,使用MIT开源协议,主要功能包括,统计, 分析, 可视化, 监控,追踪等,适合在微服务环境中使用。
官方地址:https://www.yuque.com/httpreports/docs/uyaiil
** Main functions **
- Analysis of Interface Call Indicators
- Multi-service node data aggregation analysis
- Slow request, error request analysis
- Interface call log query
- Various types of early warning monitoring
- HTTP,Grpc call analysis
- distributed tracing
- Multiple database support, easy integration
- Program performance monitoring
the first step
打开 VS 新建.NET 项目我这里用的是.NET Core Web API 进行演示
the second step
使用NuGet安装MHttpReports.Dashboard包和HttpReports.SqlServer

the third step
Configure appsetting.json
{
"HttpReportsDashboard": {
"ExpireDay": 3,
"Storage": {
"ConnectionString": "Server=10.1.30.252;Database=GEISDB;user id=sa;password=Mg2021;",
"DeferSecond": 10,
"DeferThreshold": 100
},
"Check": {
"Mode": "Self",
"Switch": true,
"Endpoint": "",
"Range": "500,2000"
},
"Mail": {
"Server": "smtp.163.com",
"Port": 465,
"Account": "HttpReports@qq.com",
"Password": "*******",
"EnableSsL": true,
"Switch": true
}
}
}
** Parameter introduction: **
- ExpireDay -The number of days that data expires. The default is 3 days. HttpReports will automatically clear expired data
- Storage -Store information
- DeferSecond -Number of seconds for batch data to be put into storage, recommended value of 5-60
- DeferThreshold -Quantity of batch data put into storage, recommended value 100-1000
- Mail -Mailbox information. If monitoring is configured, an alarm email can be sent
- Check -Health check configuration, see the health check page for details
the fourth step
Configure Startup
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReportsDashboard().AddSQLServerStorage();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReportsDashboard();
}
Launch the Dashboard application. If there are no problems, it will jump to the Dashboard login page

默认账号:admin
密码: 123456
Now that the Dashboard visualization is available, but there is no data, we still need to add HttpReports to the server program to collect information.
the fifth step
我新建一个 WebAPI 项目 UserService ,来充当用户服务,然后安装 HttpReports,HttpReports.Transport.Http

the sixth step
修改 Services 的Appsettings.json 简单配置一下
{
"HttpReports": {
"Transport": {
"CollectorAddress": "http://localhost:5000/",
"DeferSecond": 10,
"DeferThreshold": 100
},
"Server": "http://localhost:7000",
"Service": "User",
"Switch": true,
"RequestFilter": ["/api/health/*", "/HttpReports*"],
"WithRequest": true,
"WithResponse": true,
"WithCookie": true,
"WithHeader": true
}
}
** Parameter introduction: **
Transport -
CollectorAddress -The address to which the data is sent. You can configure the Dashboard item address
DeferSecond -Number of seconds for batch data to be put into storage, recommended value of 5-60
DeferThreshold -Quantity of batch data put into storage, recommended value 100-300
Server -Address of the service,
Service -Name of the service
Switch -Whether to turn on data collection
RequestFilter -Data filtering, using* to obscure matches
WithRequest -Whether to record input parameters of the interface
WithResponse -Whether to record the parameters of the interface
WithCookie -Whether to record Cookie information
WithHeader -Whether to record request Header information
the last step
我们接着修改 UserService 项目的 Startup.cs 文件
app.UseHttpReports(); 这一行最好放到 Configure 方法 最上面
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReports().AddHttpTransport();
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReports();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
刷新下 UserService 的接口,再回到Dashboard的页面上面,已经可以看到数据了

summary
This blog describes the use of HttpReports for interface statistics, analysis, visualization, monitoring, tracking, etc. If you think it is good, please pay attention.