{"id":18740009,"url":"https://github.com/springleee/httpreportsweb","last_synced_at":"2025-04-12T20:04:30.356Z","repository":{"id":115818613,"uuid":"225804040","full_name":"SpringLeee/HttpReportsWeb","owner":"SpringLeee","description":"HttpReportsWeb","archived":false,"fork":false,"pushed_at":"2020-01-10T05:13:51.000Z","size":13544,"stargazers_count":44,"open_issues_count":2,"forks_count":16,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-12T20:04:22.959Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SpringLeee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-04T07:18:04.000Z","updated_at":"2024-01-15T08:13:36.000Z","dependencies_parsed_at":"2023-07-12T11:15:51.665Z","dependency_job_id":null,"html_url":"https://github.com/SpringLeee/HttpReportsWeb","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringLeee%2FHttpReportsWeb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringLeee%2FHttpReportsWeb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringLeee%2FHttpReportsWeb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SpringLeee%2FHttpReportsWeb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SpringLeee","download_url":"https://codeload.github.com/SpringLeee/HttpReportsWeb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625493,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T15:38:11.214Z","updated_at":"2025-04-12T20:04:30.350Z","avatar_url":"https://github.com/SpringLeee.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\n \n####  微服务统计，分析，图表，监控一体化的HttpReports项目在.Net Core 中的使用\n\n\n#  HttpReports\n### 简单介绍  \nHttpReports 是 .Net Core 下的一个Web项目, 适用于WebAPI，Ocelot网关应用，MVC项目，非常适合针对微服务应用使用，通过中间件的形式集成到您的项目中，可以让开发人员快速的搭建出一个 数据统计，分析，图表，监控 一体化的 Web站点。\n \n\n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a1.png)  \n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a2.png) \n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a3.png)   \n\n\n#### 主要模块\n\n主要包含HttpReports 中间件 和 HttpReports.Web 的MVC项目;\n\nHttpReports： https://github.com/SpringLeee/HttpReports  \n  \nHttpReports.Web： https://github.com/SpringLeee/HttpReportsWeb\n\n在线预览： http://175.102.11.117:8801 账号 admin 密码 123456\n\n#### 支持项目类型  \n\n😂 单个WebAPI应用  \n😆 多个独立WebAPI应用   \n😊 Ocelot 网关应用 \n😛 单个MVC项目\n😃 多个MVC项目\n\n\n### 如何使用\n\n##### 1.添加 HttpReports 中间件 \n\nNuget 包安装 HttpReports, 打开Startup.cs, 修改 ConfigureServices(IServiceCollection services) 方法，添加以下代码，放在 services.AddMvc() 之前都可以。\n\n 选择您的应用类型：\n \n😆 **单个WebAPI应用 或者 使用Ocelot网关的应用**\n \n 修改 ConfigureServices 方法 ，\n \n ```csharp\n\t public void ConfigureServices(IServiceCollection services)\n\t { \n\t\t // 添加HttpReports中间件\n\t\t services.AddHttpReportsMiddleware(WebType.API, DBType.SqlServer);\n\n\t     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); \n\t}\n```\n😆 ** 多个独立的WebAPI应用 **\n\n假设有一个 授权（Auth）API应用，和一个支付（Pay）API应用，并且没有使用网关，需要分别在两个项目的Startup.cs文件的 ConfigureServices 方法中分别添加以下代码:\n \n###### 授权API应用(Auth)\n ```csharp\nservices.AddHttpReportsMiddleware(WebType.API, DBType.SqlServer,\"Auth\");\n```\n###### 支付Pay应用(Pay)\n ```csharp\nservices.AddHttpReportsMiddleware(WebType.API, DBType.SqlServer,\"Pay\");  \n```\n\n😆 **单个MVC应用** \n\n```csharp\n\tpublic void ConfigureServices(IServiceCollection services)\n\t{ \n\t\t// 添加HttpReports中间件\n\t\tservices.AddHttpReportsMiddleware(WebType.MVC, DBType.SqlServer);\n\n\t\tservices.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); \n\t}\n```\n\n😆 **多个MVC应用**\n\n假设有一个 电商（Mall）应用，和一个支付（Pay）应用，需要分别在两个项目的Startup.cs文件的 ConfigureServices 方法中分别添加以下代码:\n\n###### 电商MVC应用 （Mall）\n ```csharp\n services.AddHttpReportsMiddleware(WebType.MVC, DBType.SqlServer,\"Mall\");\n```\n###### 支付MVC应用 （Pay）\n ```csharp\n services.AddHttpReportsMiddleware(WebType.MVC, DBType.SqlServer,\"Pay\");  \n```\n😆 **切换数据库**\n\n使用MySql数据库\n```csharp\n services.AddHttpReportsMiddleware(WebType.API, DBType.MySql);\n```\n使用SqlServer数据库\n```csharp\n services.AddHttpReportsMiddleware(WebType.API, DBType.SqlServer);\n``` \n   \n##### 2.使用 HttpReports 中间件  \n\n修改 StartUp.cs 的 Configure 方法\n\n.Net Core 2.2\n\n```csharp\n\tpublic void Configure(IApplicationBuilder app, IHostingEnvironment env)\n\t{    \n\t\t//使用HttpReports \n\t\tapp.UseHttpReportsMiddleware();  \n\n\t\tapp.UseMvc();\n\t}\n```\n必须要放在 UseMVC() 方法和其他中间件的前边，否则不生效。\n\n.Net Core 3.0 和以上版本\n\n```csharp\n\tpublic void Configure(IApplicationBuilder app, IWebHostEnvironment env)\n\t{ \n\t\t//使用HttpReports\n\t\tapp.UseHttpReportsMiddleware();\n\n\t\tapp.UseRouting(); \n\n\t\tapp.UseAuthorization(); \n\n\t\tapp.UseEndpoints(endpoints =\u003e\n\t\t{\n\t\t\tendpoints.MapControllers();\n\t\t});\n\t}\n```  \n必须要放在 UseEndpoints() 方法和其他中间件的前边，否则不生效。\n\n##### 3.  appsettings.json 配置连接字符串\n\n 打开 appsetting.json, 添加数据库连接字符串,  **需要手动创建数据库 HttpReports**\n \n```csharp\n\"ConnectionStrings\": {\n    \"HttpReports\": \"Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;\"\n  }\n```\n##### 4. 运行Web应用\n到这一步，已经配置完成了, 直接运行Web应用，如果中间有报错的话，可能是因为数据库的连接问题，请检查后再重试，如果没有报错的话，打开数据库 [HttpReports].[dbo].[RequestInfo],  如果能看到有数据记录，就说明 HttpReports 中间件的部分配置完成了，数据有了，下边开始配置 HttpReportsWeb 站点。\n\n------------ \n\n#### HttpReports.Web部分\n\ngithub源码：https://github.com/SpringLeee/HttpReportsWeb \n有需要的也可以下载源码后编译，默认的git分支是Core 2.2 版本，还有一个 core 3.0的分支；\n\n这里提供 core2.2 和 3.0 的发布版本下载：  \n\nCore 2.2 发布版本：   https://files.cnblogs.com/files/myshowtime/HttpReports2.2.zip \nCore 3.0 发布版本：https://files.cnblogs.com/files/myshowtime/HttpReports3.0.zip\n\n这里以 .Net Core2.2 版本为例, 下载发布版本后，解压文件, 找到 appsettings.json文件，并修改\n\n```csharp\n{\n  \"ConnectionStrings\": {\n    \"HttpReports\": \"Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;\"   \n  },\n  \"HttpReportsConfig\": {\n    \"DBType\": \"SqlServer\", // MySql Or SqlServer\n    \"UserName\": \"admin\",\n    \"Password\": \"123456\"\n  }\n}\n```\n |  字段 | 说明  |\n| ------------ | ------------ |\n| HttpReports  | 数据库连接字符串，要和上边配置的中间件的数据库一致  |\n| DBType  | 数据库类型 SqlServer MySql , 注意没有空格  |\n| UserName  | Web站点后台登录名，可修改  |\n| Password  | Web站点后台登录密码，可修改  |\n\n 修改数据库类型和连接字符串, 然后打开命令行，启动程序，或者部署到站点也可以\n \n ```csharp\ndotnet HttpReports.Web.dll\n```\n跳到登录页，输入默认账号 admin 密码 123456，登录到系统，看一下主要的几个页面 \n \n#### 主页面\n\n主要是Web应用 请求次数, 请求时间, 请求错误，错误率TOP, 响应最快和响应最慢等， 按天，月，年进行趋势分析,  服务节点 点击可以选中和取消，并且可以切换亮色和暗色主题 \n\n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a5.png)\n\n#### 预警监控\n\n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a6.png)\n\nHttpReports 监控预警主要针对以下几点：  \n\n😃 响应超时 \n😃 请求错误\n😃 IP异常\n😃 请求量监控\n \n **如何添加监控：**\n \n![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a7.png)\n \n这里演示添加一个监控，监控频率 选1小时，也就是1个小时 运行一次，然后填入预警的收件邮箱,可填写多个邮箱, 服务节点 可以选中单个和多个节点，默认的话，下边 4个监控都是关闭状态, 如果需要勾选启动即可 \n\n##### 响应超时监控配置\n \n 预防一段时间内接口大量超时，设置超时时间为4000ms ， 超时率为0.05% (最多支持两位小数,设置值要带上%号)\n\n ![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a8.png) \n \n##### 请求错误监控配置\n \n   预防一段时间内接口大量错误，设置错误HTTP状态码为500,503， 超时率为20% \n \n ![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a9.png) \n \n##### IP异常监控配置\n \n 预防机器人请求，防止一段时间大量重复IP请求，设置IP重复率为15% \n \n ![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_b11.png) \n \n##### 请求量监控\n \n 预防短时间内接口新增大量的请求，造成系统异常，设置 单位时间 请求量为100000，当请求量达到这个值触发预警\n \n ![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_b12.png) \n \n 保存任务，任务自动运行，监控频率可以逐渐修改，找到适合系统的预警值， 如果数据达到预警值时,您就会收到HttpReports 发送给您的预警通知邮件   \n \n\n### 项目环境基本要求\n\n使用HttpReports中间件的.Net Core 版本 2.0 及以上版本\n\nHttpReports.Web 的core版本为 2.2 , 3.0 \n\n### 性能事项\n\nHttpReports 中间件存储数据是异步操作，所以对api接口请求的时间可以忽略, 存储数据是也只是存储基本信息，对请求内容和响应内容不作记录，后台监控任务采用Quartz.Net实现\n\n下面是用PostMan做的一个简单测试：\n\nWebAPI内的方法：\n\n```csharp\n        public string Sql1()\n        {\n            SqlConnection con = new SqlConnection(\n                \"Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HyBasicData;\");\n\n            var list1 =  con.Query(\" select * from [HyBasicData].[dbo].[Customers] \");\n\n            var list2 = con.Query(\" select * from [HyBasicData].[dbo].[Customers] \");\n\n            var list3 = con.Query(\" select * from [HyBasicData].[dbo].[Customers] \"); \n\n            return list1.Count().ToString();\n        } \n```\nPostMan分别对添加中间件和不添加中间件的 API请求 1000次，每300ms请求一次\n\n 说明 | 请求次数  | 平均响应时间 ms\n-|-|-\n原生API|1000|32.535\n使用中间件|1000|32.899 \n\n### 总结\n\nHttpReports  后台使用简单三层，前端使用BootStrap，如果你想给你的程序，快速的添加一套分析，图表，监控系统 ，那么使用HttpReports 是一个不错的选择，如果能帮助到您的话，还请希望给个Star， 感谢 😆\n\nhttps://github.com/SpringLeee/HttpReports \n\n[MIT](https://github.com/SpringLeee/HttpReports/blob/master/LICENSE \"MIT\")\n\n### 维护和更新\n \n  [ToDoList](https://github.com/SpringLeee/HttpReports/blob/master/ToDoList.md \"ToDoList\")\n\n### 交流反馈\n \n如果您在项目中使用了HttpReports，或者感兴趣的可以加入QQ群，大家一起沟通，有更新也会第一时间通知，也可以添加我的微信，希望可以帮助到您\n \n ![](https://images.cnblogs.com/cnblogs_com/myshowtime/1627540/o_a15.png)\n \n \n\n \n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringleee%2Fhttpreportsweb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringleee%2Fhttpreportsweb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringleee%2Fhttpreportsweb/lists"}