• .net core使用App.Metrics+InfluxDB+Grafana进行APM监控


    一、InfluxDB

    1、下载InfluxDB

    wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.2.x86_64.rpm

    2、安装InfluxDB

    rpm -ivh influxdb-1.5.2.x86_64.rpm
    systemctl start influxdb.service

    3、创建库、用户

    influx
    CREATE DATABASE qkaweb
    use qkaweb
    create user "leizhihui" with password '123456'

    二、Grafana

    1、下载、安装:

    wget https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.1.2-1.x86_64.rpm
    yum localinstall grafana-5.1.2-1.x86_64.rpm

    2、设置开机自动启动:

    systemctl daemon-reload
    systemctl enable grafana-server.service

    3、启动服务并查看服务状态:

    systemctl start grafana-server.service
    systemctl status grafana-server.service

    4、访问ip+3000端口,用户名和密码均为admin进行登录,

    5、创建数据源,如下图所示:

     6、导入Dashboard:

    输入2125后点击Import按钮即导入App Metrics模板。

    三、网关项目中添加App Metrics

    1、添加下面nuget引用:

    App.Metrics
    App.Metrics.Extensions.Middleware
    App.Metrics.Extensions.Mvc
    App.Metrics.Extensions.Reporting.InfluxDB
    App.Metrics.Extensions.Middleware
    App.Metrics.Formatters.Json
    

    2、修改appsettings.json文件:

    "AppMetrics": {
        "DataBaseName": "qkaweb",
        "ConnectionString": "http://192.168.2.168:8086",
        "UserName": "leizhihui",
        "Password": "123456",
        "App": "QkaWebApis",
        "Env": "develop"
      }

    3、添加如下代码:

            public void ConfigureServices(IServiceCollection services)
            {
    
                #region App Metrics
                AppMetricsConfig appMetricsConfig = Configuration.GetSection("AppMetrics").Get<AppMetricsConfig>();
                var uri = new Uri(appMetricsConfig.ConnectionString);
    
                var metrics = AppMetrics.CreateDefaultBuilder()
                .Configuration.Configure(
                options =>
                {
                    options.AddAppTag(appMetricsConfig.App);
                    options.AddEnvTag(appMetricsConfig.Env);
                })
                .Report.ToInfluxDb(
                options =>
                {
                    options.InfluxDb.BaseUri = uri;
                    options.InfluxDb.Database = appMetricsConfig.DataBaseName;
                    options.InfluxDb.UserName = appMetricsConfig.UserName;
                    options.InfluxDb.Password = appMetricsConfig.Password;
                    options.HttpPolicy.BackoffPeriod = TimeSpan.FromSeconds(30);
                    options.HttpPolicy.FailuresBeforeBackoff = 5;
                    options.HttpPolicy.Timeout = TimeSpan.FromSeconds(10);
                    options.FlushInterval = TimeSpan.FromSeconds(5);
                })
                .Build();
    
                services.AddMetrics(metrics);
                services.AddMetricsReportScheduler();
                services.AddMetricsTrackingMiddleware();
                services.AddMetricsEndpoints();
                #endregion
            }
    
            public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            {
                app.UseMetricsAllMiddleware();
                app.UseMetricsAllEndpoints();
            }
  • 相关阅读:
    数据库系统原理
    Java并发编程详解读书笔记(一)
    Java基础之String
    Java基础之数据类型
    winform BackgroundWorker控件的用法
    汉子转拼音
    model验证(验证登录、注册...)
    Ajax.BeginForm 异步搜索
    Ajax.ActionLink 辅助方法实现局部刷新
    js 随笔
  • 原文地址:https://www.cnblogs.com/focus-lei/p/9037421.html
Copyright © 2020-2023  润新知