Giter Club home page Giter Club logo

aspectcore-apm's Introduction

AspectCore-APM

Build status

AspectCore-APM 旨在为.NET Core 应用程序提供一套应用性能监控管理(APM)方案,当前版本使用 InfluxDb 作为数据存储方案 Grafana 作为展示方案。

使用指南:

环境准备:

1、安装运行influxdb

下载链接:influxdb

2、安装运行Grafana

下载链接:Grafana

3、执行命令 influx 进入influxdb CLI,并创建aspnetcore dataBase

CREATE DATABASE aspectcore

4、配置并运行 Grafana

sudo vi /etc/grafana/grafana.ini

http_addr配置为您所需要的IP,如: 0.0.0.0:3000

5、配置grafana数据源、图表

打开浏览器,进入Grafana站点: http://IP:3000

输入用户名/密码:admin/admin

选择添加DataSource,Type选择influxdb,并且database填入aspectcore

进入Dashbord选项,导入配置:https://grafana.com/dashboards/3837

外部环境准备就绪,创建.NET CORE应用:

1、创建ASP.NET Core应用

2、加入 AspectCoreAPM 相关依赖

Install-Package AspectCore.APM.AspNetCore
Install-Package AspectCore.APM.LineProtocolCollector
Install-Package AspectCore.APM.ApplicationProfiler

修改Startup.cs文件:

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        services.AddAspectCoreAPM(component =>
        {
            component.AddApplicationProfiler(); //注册ApplicationProfiler收集GC和ThreadPool数据
            component.AddHttpProfiler();        //注册HttpProfiler收集Http请求数据
            component.AddLineProtocolCollector(options => //注册LineProtocolCollector将数据发送到InfluxDb
            {
                options.Server = "http://192.168.3.4:8086"; //你自己的InfluxDB Http地址
                options.Database = "aspectcore";    //你自己创建的Database
            });
        });

        return services.BuildAspectCoreServiceProvider(); //返回AspectCore AOP的ServiceProvider,这句代码一定要有
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseAspectCoreAPM();     //启动AspectCoreAPM
        app.UseHttpProfiler();      //启动Http请求监控

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseMvc();
    }
}

启动应用并访问页面。

回到Grafana,在DataSource处选择 aspectcore,就能看到我们的监控数据。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.