ASP. NET Core API Gateway real-time performance monitoring

Source: Internet
Author: User
Tags grafana influxdb

ASP. NET Core API Gateway real-time performance monitoring

Using Influxdb, Grafana

Dockerfile running InfluxDB, Grafana
influxdb:image: influxdb  ports:    - "8086:8086"    - "8083:8083"  environment:    - INFLUXDB_DB=TogetherAppMetricsDB    - INFLUXDB_ADMIN_ENABLED=true    - INFLUXDB_ADMIN_USER=admin    - INFLUXDB_ADMIN_PASSWORD=admingrafana:  image: grafana/grafana  ports:    - "3000:3000"
Configure Grafana
    1. Browser Open <本地ip>:3000 , login with default account
    2. Add a data source
      Click the Add Data Source button in the configuration to enter the INFLUXDB database information you installed
    3. Click Dashboard Settings Template
App.metrics in API Gateway
    1. Install the necessary NuGet packages
> App.Metrics> App.Metrics.AspNetCore.Endpoints> App.Metrics.AspNetCore.Reporting> App.Metrics.AspNetCore.Tracking> App.Metrics.Reporting.InfluxDB
    1. Configureservices Configuration

StartUp.cs

public void ConfigureServices(IServiceCollection services){      ...      services.AddOptions();      services.Configure<AppMetricsOptions>(Configuration.GetSection("AppMetrics"));      services.AddAppMetrics(Configuration);      services.AddOcelot(Configuration);} public void Configure(ILoggerFactory loggerFactory, IApplicationBuilder app, IHostingEnvironment env) {      app.UseMetricsAllEndpoints();      app.UseMetricsAllMiddleware();      app.UseOcelot(); }

ServiceCollectionExtensions.cs

public static class servicecollectionextensions{public static Iservicecollection Addappmetrics (This iservicecollectio N Services, iconfiguration configuration) {var options = Services. Buildserviceprovider (). Getrequiredservice<ioptions<appmetricsoptions>> ()?.        Value; if (options?. IsOpen = = true) {var uri = new Uri (options).            ConnectionString); var metrics = Appmetrics.createdefaultbuilder (). Configuration.configure (opt + = {opt. Addapptag (options.                APP); Opt. Addenvtag (options.            ENV); }). Report.toinfluxdb (opt + = {opt.                Influxdb.baseuri = URI; Opt. Influxdb.database = options.                DatabaseName; Opt. Influxdb.username = options.                UserName; Opt. Influxdb.password = options.                Password; Opt.                Httppolicy.backoffperiod = Timespan.fromseconds (30); Opt.   Httppolicy.failuresbeforebackoff = 5;             Opt.                Httppolicy.timeout = Timespan.fromseconds (10); Opt.            Flushinterval = Timespan.fromseconds (5); }).            Build (); Services.            Addmetrics (metrics); Services.            Addmetricsreportscheduler (); Services.            Addmetricstrackingmiddleware (); Services.        Addmetricsendpoints ();    } return services;    }}public class appmetricsoptions{public bool IsOpen {get; set;}    public string DatabaseName {get; set;}    public string ConnectionString {get; set;}    public string UserName {get; set;}    public string Password {get; set;}    public string App {get; set;} public string Env {get; set;}}
Final effect

Reference articles
    1. . NET core microservices based on App.metrics+influxdb+grafana for unified performance monitoring
    2. ASP. NET Core Real-time performance monitoring
    3. Influxdb Docker Documentation
    4. Grafana Official documents

ASP. NET Core API Gateway real-time performance monitoring

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.