? HttpReports ?基于.Net Core 開發的APM監控系統,使用MIT開源協議,主要功能包括,統計, 分析, 可視化, 監控,追蹤等,適合在微服務環境中使用。
? 官方地址:https://www.yuque.com/httpreports/docs/uyaiil
主要功能
?????接口調用指標分析
?????多服務節點數據聚合分析
?????慢請求,錯誤請求分析
?????接口調用日志查詢?
?????多類型預警監控
?????HTTP,Grpc 調用分析?
?????分布式追蹤
?????多數據庫支持,集成方便
?????程序性能監控
第一步打開VS新建.net項目我這里用的是.net core webapi 進行演示
第二步 使用Nuget安裝MHttpReports.Dashboard包和HttpReports.SqlServer
第三步配置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}}
}
參數介紹:? ?
ExpireDay - 數據過期天數,默認3天,HttpReports 會自動清除過期的數據
Storage - 存儲信息?
DeferSecond - 批量數據入庫的秒數,建議值 5-60
DeferThreshold - 批量數據入庫的數量,建議值100-1000
Mail - 郵箱信息,配置監控的話,可以發告警郵件
Check - 健康檢查配置,具體看 健康檢查 頁面
第四步配置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();}
? 把Dashboard 程序啟動起來,如果沒有問題的話,會跳轉到Dashboard的登陸頁面
默認賬號:
admin 密碼: 123456
現在Dashboard 可視化有了,但是沒有數據,我們還需要 給服務端程序,添加 HttpReports 來收集信息。
第五步 我新建一個WebAPI 項目 UserService ,來充當用戶服務,然后安裝 HttpReports,HttpReports.Transport.Http??
第六步修改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}
}
參數介紹:? ?
Transport -? ?
CollectorAddress - 數據發送的地址,配置Dashboard 的項目地址即可
DeferSecond - 批量數據入庫的秒數,建議值 5-60
DeferThreshold - 批量數據入庫的數量,建議值100-300
Server - 服務的地址,?
Service - 服務的名稱
Switch - 是否開啟收集數據
RequestFilter - 數據過濾,用 * 來模糊匹配
WithRequest - 是否記錄接口的入參
WithResponse - 是否記錄接口的出參
WithCookie - 是否記錄Cookie 信息
WithHeader - 是否記錄請求Header信息
最后一步我們接著修改 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的頁面上面,已經可以看到數據了
總結
本篇博客描述了使用HttpReports進行接口統計,分析, 可視化, 監控,追蹤等
如果覺得還不錯,請給個關注