• .NET Core HttpReports 监控


    HttpReports 基于.NET Core 开发的APM监控系统,使用MIT开源协议,主要功能包括,统计, 分析, 可视化, 监控,追踪等,适合在中小项目中使用。

    语雀:https://www.yuque.com/httpreports/docs/uyaiil
    github:https://github.com/dotnetcore/HttpReports
    在线预览: http://apm.nonop.cn
    账号:  admin 密码 123456

    主要功能
    接口调用指标分析
    多服务节点数据聚合分析
    慢请求,错误请求分析
    接口调用日志查询 
    多类型预警监控
    HTTP,Grpc 调用分析 
    分布式追踪
    多数据库支持,集成方便
    程序性能监控

    1、新建一个 .Net Core 的空Web项目【HttpReports.Dashboard】
    2、通过 NuGet包分别安装 HttpReports.Dashboard,HttpReports.MySQL(或者是HttpReports.SqlServer,HttpReports.PostgreSQL)
    管理 NuGet 包(N)...

    1. HttpReports.Dashboard
    2. HttpReports.SQLServer

    3、修改 appsetting.json 文件

    1. {
    2. "Logging": {
    3. "LogLevel": {
    4. "Default": "Information",
    5. "Microsoft": "Warning",
    6. "Microsoft.Hosting.Lifetime": "Information"
    7. }
    8. },
    9. "AllowedHosts": "*",
    10. "HttpReportsDashboard": {
    11. "ExpireDay": 3,
    12. "Storage": {
    13. "ConnectionString": "DataBase=dbHttpReports;Data Source=.;User Id=sa;Password=123456;",
    14. "DeferSecond": 10,
    15. "DeferThreshold": 100
    16. },
    17. "Check": {
    18. "Mode": "Self",
    19. "Switch": true,
    20. "Endpoint": "",
    21. "Range": "500,2000"
    22. },
    23. "Mail": {
    24. "Server": "smtp.163.com",
    25. "Port": 465,
    26. "Account": "HttpReports@qq.com",
    27. "Password": "*******",
    28. "EnableSsL": true,
    29. "Switch": true
    30. }
    31. }
    32. }

    参数介绍
    ExpireDay - 数据过期天数,默认3天,HttpReports 会自动清除过期的数据
    Storage - 存储信息 
    DeferSecond - 批量数据入库的秒数,建议值 5-60
    DeferThreshold - 批量数据入库的数量,建议值100-1000
    Mail - 邮箱信息,配置监控的话,可以发告警邮件
    Check - 健康检查配置,具体看 健康检查 页面

    4、修改 Dahboard 项目的 Startup.cs 文件

    1. using Microsoft.AspNetCore.Builder;
    2. using Microsoft.AspNetCore.Hosting;
    3. using Microsoft.AspNetCore.Http;
    4. using Microsoft.Extensions.DependencyInjection;
    5. using Microsoft.Extensions.Hosting;
    6. namespace Dashboard
    7. {
    8. public class Startup
    9. {
    10. public void ConfigureServices(IServiceCollection services)
    11. {
    12. services.AddHttpReportsDashboard().AddSQLServerStorage();
    13. }
    14. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    15. {
    16. if (env.IsDevelopment())
    17. {
    18. app.UseDeveloperExceptionPage();
    19. }
    20. app.UseHttpReportsDashboard();
    21. app.UseRouting();
    22. app.UseEndpoints(endpoints =>
    23. {
    24. endpoints.MapGet("/", async context =>
    25. {
    26. await context.Response.WriteAsync("Hello World!");
    27. });
    28. });
    29. }
    30. }
    31. }

    把Dashboard 程序启动起来,如果没有问题的话,会跳转到Dashboard的登陆页面*
    默认账号:admin
    密码: 123456 
    现在Dashboard 可视化有了,但是没有数据,我们还需要 给服务端程序,添加 HttpReports 来收集信息。

    5、新建一个WebAPI 项目 UserService(用户服务),来充当用户服务,然后安装 HttpReports
    通过 NuGet包分别安装 HttpReports , HttpReports.Transport.Http
    管理 NuGet 包(N)... 

    1. HttpReports
    2. HttpReports.Transport.Http

    6、修改项目的 appsetting.json 文件

    1. {
    2. "Logging": {
    3. "LogLevel": {
    4. "Default": "Information",
    5. "Microsoft": "Warning",
    6. "Microsoft.Hosting.Lifetime": "Information"
    7. }
    8. },
    9. "AllowedHosts": "*",
    10. "HttpReports": {
    11. "Transport": {
    12. "CollectorAddress": "http://localhost:12216/", //数据批量发送的地址,Dashboard 项目地址
    13. "DeferSecond": 10, //批量数据入库的秒数,建议值 5-60
    14. "DeferThreshold": 100 //批量数据入库的数量,建议值100-300
    15. },
    16. "Server": "http://localhost:32168", //服务的地址,UserService 项目地址
    17. "Service": "User", //服务名称
    18. "Switch": true, //是否开启收集数据
    19. "RequestFilter": [ "/api/health/*", "/HttpReports*" ],
    20. "WithRequest": true,
    21. "WithResponse": true,
    22. "WithCookie": true,
    23. "WithHeader": true
    24. }
    25. }

    参数介绍
    Transport -   
    CollectorAddress - 数据发送的地址,配置Dashboard 的项目地址即可
    DeferSecond - 批量数据入库的秒数,建议值 5-60
    DeferThreshold - 批量数据入库的数量,建议值100-300

    Server - 服务的地址, 
    Service - 服务的名称
    Switch - 是否开启收集数据
    RequestFilter - 数据过滤,用 * 来模糊匹配
    WithRequest - 是否记录接口的入参
    WithResponse - 是否记录接口的出参
    WithCookie - 是否记录Cookie 信息
    WithHeader - 是否记录请求Header信息

    7、修改 UserService 项目的 Startup.cs 文件

    1. using Microsoft.AspNetCore.Builder;
    2. using Microsoft.AspNetCore.Hosting;
    3. using Microsoft.Extensions.Configuration;
    4. using Microsoft.Extensions.DependencyInjection;
    5. using Microsoft.Extensions.Hosting;
    6. namespace UserService
    7. {
    8. public class Startup
    9. {
    10. public Startup(IConfiguration configuration)
    11. {
    12. Configuration = configuration;
    13. }
    14. public IConfiguration Configuration { get; }
    15. public void ConfigureServices(IServiceCollection services)
    16. {
    17. services.AddHttpReports().AddHttpTransport();
    18. services.AddControllers();
    19. }
    20. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    21. {
    22. if (env.IsDevelopment())
    23. {
    24. app.UseDeveloperExceptionPage();
    25. }
    26. app.UseHttpReports();
    27. app.UseRouting();
    28. app.UseAuthorization();
    29. app.UseEndpoints(endpoints =>
    30. {
    31. endpoints.MapControllers();
    32. });
    33. }
    34. }
    35. }

    8、设置启动项目
    解决方案中设置多项目启动,同时运行 Dashboard 和 UserService 项目。
    多请求几次 UserService 的接口,然后再回到 Dashboard 页面,选择一下时间,现在已经可以看到数据了!

    *
    *
    *

  • 相关阅读:
    Nat. Med. | 基于遗传学原发部位未知癌症的分类和治疗反应预测
    HDMI转mipiCSI+Audio,东芝,TC358743,视频转换芯片
    spark shuffle——shuffle管理
    docker进阶作业
    STM32F103定时计算方法
    【Vue】vue2 封装 echarts 基础组件,直接传 option 即可
    Windows部署Docker
    JS-函数
    一篇文章讲清楚芯片设计全流程及相关岗位划分
    servlet中doGet方法无法读取body中的数据
  • 原文地址:https://blog.csdn.net/KingCruel/article/details/127591278