Ocelot monitoring,

Source: Internet
Author: User
Tags grafana influxdb

Ocelot monitoring,

One of the functions of the gateway is to have a unified data portal. Based on this function, we can configure monitoring on the gateway to capture and display the basic data of all web service request responses.
On the web monitoring, the general approach is to collect data and save, and then through the chart display, the database used is generally time series database Graphite, InfluxDB (https://portal.influxdata.com/downloads), OpenDSDB, etc, this article uses InfluxDB, display data generally uses a graphical framework, this article uses Grafana (https://grafana.com/get)
First, download InfluxDB and Grafana from the link above.
After InfluxDB is downloaded, as shown in figure

For more information about InfluxDB operations, see the official documentation. We will not go into details here. We only need to create a database named MetricsDB.

After grafana is downloaded, set grafana-server.exe as the Startup Program in the BINLOG.
Enter http: // localhost: 3000 in the browser, and the username and password are both admin (you can change the password after entering)
Add DataSource

Add Dashboards that can be imported using the https://grafana.com/dashboards/2125


Click Import to display the graphic view panel.

We are using the App. Metrics (https://www.app-metrics.io) package for monitoring
In the OcelotGateway project, add and reference the following five Nuget packages
App. Metrics MAIN package
App. Metrics. AspNetCore. Endpoints
App. Metrics. AspNetCore. Reporting
App. Metrics. AspNetCore. Tracking
App. Metrics. Reporting. InfluxDB

Startup. cs

1 using Microsoft. aspNetCore. builder; 2 using Microsoft. aspNetCore. hosting; 3 using Microsoft. extensions. configuration; 4 using Microsoft. extensions. dependencyInjection; 5 using Ocelot. dependencyInjection; 6 using Ocelot. middleware; 7 using Ocelot. JWTAuthorizePolicy; 8 using App. metrics; 9 using System; 10 11 namespace OcelotGateway12 {13 public class Startup14 {15 public Startup (IConfiguration configuration) 16 {17 Configuration = configuration; 18} 19 public IConfiguration Configuration {get ;} 20 public void ConfigureServices (IServiceCollection services) 21 {22 # region Note Metrics 23 var metrics = AppMetrics. createdefabuilder Builder () 24. configuration. configure (25 options => 26 {27 options. addAppTag ("RepairApp"); 28 options. addEnvTag ("stage"); 29}) 30. report. toInfluxDb (31 options => 32 {33 options. influxDb. baseUri = new Uri (" http://127.0.0.1:8086 "); 34 options. influxDb. database = "AppMetricsDemo"; 35 options. influxDb. userName = "admin"; 36 options. influxDb. password = "123456"; 37 options. httpPolicy. backoffPeriod = TimeSpan. fromSeconds (30); 38 options. httpPolicy. failuresBeforeBackoff = 5; 39 options. httpPolicy. timeout = TimeSpan. fromSeconds (10); 40 options. flushInterval = TimeSpan. fromSeconds (5); 41}) 42. build (); 43 services. addMetrics (metrics); 44 services. addMetricsReportScheduler (); 45 services. addMetricsTrackingMiddleware (); 46 services. addMetricsEndpoints (); 47 # endregion48 49 # Add JWT50 var audienceConfig = Configuration to region. getSection ("Audience"); 51 // inject OcelotJwtBearer52 services. addOcelotJwtBearer (audienceConfig ["Issuer"], audienceConfig ["Issuer"], audienceConfig ["Secret"], "GSWBearer"); 53 # endregion54/inject configuration file, addOcelot requires the parameter to be of the IConfigurationRoot type, so a conversion of 55 services is required. addOcelot (Configuration as ConfigurationRoot); 56} 57 public void Configure (IApplicationBuilder app, IHostingEnvironment env) 58 {59 # region Metrics middleware 60 app. useMetricsAllMiddleware (); 61 app. useMetricsAllEndpoints (); 62 # endregion63 app. useOcelot (). wait (); 64} 65} 66}View Code

Next, start AuthenticationAPI, DemoAAPI, DemoBAPI, OcelotGateway, and TestClient. After several requests, view the monitoring page of localhost: 3000 as follows:

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.