微处事统计,分析,图表,监控一体化的HttpReports项目在.Net Core 中的使用
标签:
简单介绍HttpReports 是 .Net Core 下的一个Web项目, 适用于WebAPI,Ocelot网关应用,MVC项目,非常适合针对微处事应用使用,通过中间件的形式集成到您的项目中,可以让开发人员快速的搭建出一个 数据统计,分析,图表,监控 一体化的 Web站点。
主要包罗HttpReports 中间件 和 HttpReports.Web 的MVC项目;
HttpReports: https://github.com/SpringLeee/HttpReports
HttpReports.Web: https://github.com/SpringLeee/HttpReportsWeb
在线预览: :8801 账号 admin 暗码 123456
撑持项目类型?? 单个WebAPI应用
?? 多个独立WebAPI应用
?? Ocelot 网关应用
?? 单个MVC项目
?? 多个MVC项目
Nuget 包安置 HttpReports, 打开Startup.cs, 改削 ConfigureServices(IServiceCollection services) 要领,添加以下代码,放在 services.AddMvc() 之前都可以。
选择您的应用类型:
?? 单个WebAPI应用 或者 使用Ocelot网关的应用
改削 ConfigureServices 要领 ,
public void ConfigureServices(IServiceCollection services) { // 添加HttpReports中间件 services.AddHttpReportsMiddlewire(WebType.API, DBType.SqlServer); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }?? ** 多个独立的WebAPI应用 **
假设有一个 授权(Auth)API应用,和一个付出(Pay)API应用,并且没有使用网关,需要分袂在两个项目的Startup.cs文件的 ConfigureServices 要领中分袂添加以下代码:
授权API应用(Auth) services.AddHttpReportsMiddlewire(WebType.API, DBType.SqlServer,"Auth"); 付出Pay应用(Pay) services.AddHttpReportsMiddlewire(WebType.API, DBType.SqlServer,"Pay");?? 单个MVC应用
public void ConfigureServices(IServiceCollection services) { // 添加HttpReports中间件 services.AddHttpReportsMiddlewire(WebType.MVC, DBType.SqlServer); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }?? 多个MVC应用
假设有一个 电商(Mall)应用,和一个付出(Pay)应用,需要分袂在两个项目的Startup.cs文件的 ConfigureServices 要领中分袂添加以下代码:
电商MVC应用 (Mall) services.AddHttpReportsMiddlewire(WebType.MVC, DBType.SqlServer,"Mall"); 付出MVC应用 (Pay) services.AddHttpReportsMiddlewire(WebType.MVC, DBType.SqlServer,"Pay");?? 切换数据库
使用MySql数据库
services.AddHttpReportsMiddlewire(WebType.API, DBType.MySql);使用SqlServer数据库
services.AddHttpReportsMiddlewire(WebType.API, DBType.SqlServer); 2.使用 HttpReports 中间件改削 StartUp.cs 的 Configure 要领
.Net Core 2.2
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { //使用HttpReports app.UseHttpReportsMiddlewire(); app.UseMvc(); }必需要放在 UseMVC() 要领和其他中间件的前边,否则不生效。
.Net Core 3.0 和以上版本
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { //使用HttpReports app.UseHttpReportsMiddlewire(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }必需要放在 UseEndpoints() 要领和其他中间件的前边,否则不生效。
3. appsettings.json 配置连接字符串打开 appsetting.json, 添加数据库连接字符串, 需要手动创建数据库 HttpReports
"ConnectionStrings": { "HttpReports": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;" } 4. 运行Web应用到这一步,已经配置完成了, 直接运行Web应用,如果中间有报错的话,可能是因为数据库的连接问题,请查抄后再重试,如果没有报错的话,打开数据库 [HttpReports].[dbo].[RequestInfo], 如果能看到有数据记录,就说明 HttpReports 中间件的部分配置完成了,数据有了,下边开始配置 HttpReportsWeb 站点。
HttpReports.Web部分github源码:https://github.com/SpringLeee/HttpReportsWeb
有需要的也可以下载源码后编译,默认的git分支是Core 2.2 版本,还有一个 core 3.0的分支;
这里供给 core2.2 和 3.0 的颁布版本下载:
Core 2.2 颁布版本: https://files.cnblogs.com/files/myshowtime/HttpReports2.2.zip
Core 3.0 颁布版本:https://files.cnblogs.com/files/myshowtime/HttpReports3.0.zip
这里以 .Net Core2.2 版本为例, 下载颁布版本后,解压文件, 找到 appsettings.json文件,并改削
{ "ConnectionStrings": { "HttpReports": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;" }, "HttpReportsConfig": { "DBType": "SqlServer", // MySql Or SqlServer "UserName": "admin", "Password": "123456" } } 字段 说明HttpReports 数据库连接字符串,要和上边配置的中间件的数据库一致
DBType 数据库类型 SqlServer MySql , 注意没有空格
UserName Web站点后台登录名,可改削
Password Web站点后台登录暗码,可改削
改削数据库类型和连接字符串, 然后打开命令行,启动措施,或者部署到站点也可以
dotnet HttpReports.Web.dll跳到登录页,输入默认账号 admin 暗码 123456,登录到系统,看一下主要的几个页面
主页面温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32027.html
- 上一篇:点击li获取下标的几种方法(原生JS实现)
- 下一篇:源码已更新至开源模板