HttpReports is an APM monitoring system developed based on .NET Core, using the MIT open-source license. Its main features include statistics, analysis, visualization, monitoring, and tracing, making it suitable for use in microservice environments.
Official website: https://www.yuque.com/httpreports/docs/uyaiil
Main Features
API Call Metrics Analysis
Multi-Service Node Data Aggregation Analysis
Slow Request and Error Request Analysis
API Call Log Query
Multi-Type Alert Monitoring
HTTP and gRPC Call Analysis
Distributed Tracing
Multi-Database Support and Easy Integration
Program Performance Monitoring
Step 1: Open Visual Studio and create a new .NET project. I will demonstrate using a .NET Core Web API.
Step 2: Use NuGet to install the MHttpReports.Dashboard package and HttpReports.SqlServer.
Step 3: Configure appsettings.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": "[email protected]", "Password": "*******", "EnableSsL": true, "Switch": true } }}
Parameter Introduction:
ExpireDay – The number of days data is retained, default is 3 days. HttpReports will automatically clear expired data.
Storage – Storage information.
DeferSecond – The number of seconds for batch data storage, recommended value is 5-60.
DeferThreshold – The number of records for batch data storage, recommended value is 100-1000.
Mail – Email information, can send alert emails if monitoring is configured.
Check – Health check configuration, see the health check page for details.
Step 4: Configure Startup
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940public 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();}
Start the Dashboard program. If there are no issues, it will redirect to the Dashboard login page.
Default account:
admin Password: 123456
Now the Dashboard visualization is available, but there is no data yet. We still need to add HttpReports to the server program to collect information.
Step 5: I will create a new WebAPI project called UserService to act as the user service, and then install HttpReports and HttpReports.Transport.Http.
Step 6: Modify the Services’ appsettings.json for simple configuration.
{ "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 send data to, configure it to the Dashboard project address.
DeferSecond – The number of seconds for batch data storage, recommended value is 5-60.
DeferThreshold – The number of records for batch data storage, recommended value is 100-300.
Server – The address of the service.
Service – The name of the service.
Switch – Whether to enable data collection.
RequestFilter – Data filtering, use * for fuzzy matching.
WithRequest – Whether to record the input parameters of the API.
WithResponse – Whether to record the output parameters of the API.
WithCookie – Whether to record cookie information.
WithHeader – Whether to record request header information.
Final Step: Modify the Startup.cs file of the UserService project.
Place app.UseHttpReports();
at the top of the Configure method.
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(); });}
Refresh the UserService API interface, then return to the Dashboard page, and you should now see data.
Conclusion
This blog describes the use of HttpReports for API statistics, analysis, visualization, monitoring, and tracing.