1、InfluxDBjavascript
一、下載InfluxDBjava
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.5.2.x86_64.rpm
二、安裝InfluxDBweb
rpm -ivh influxdb-1.5.2.x86_64.rpm
systemctl start influxdb.service
三、建立庫、用戶json
influx
CREATE DATABASE qkaweb
use qkaweb
create user "leizhihui" with password '123456'
2、Grafanaapp
一、下載、安裝:ui
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
二、設置開機自動啓動:spa
systemctl daemon-reload
systemctl enable grafana-server.service
三、啓動服務並查看服務狀態:code
systemctl start grafana-server.service
systemctl status grafana-server.service
四、訪問ip+3000端口,用戶名和密碼均爲admin進行登陸,orm
五、建立數據源,以下圖所示:server
六、導入Dashboard:
輸入2125後點擊Import按鈕即導入App Metrics模板。
3、網關項目中添加App Metrics
一、添加下面nuget引用:
App.Metrics App.Metrics.Extensions.Middleware App.Metrics.Extensions.Mvc App.Metrics.Extensions.Reporting.InfluxDB App.Metrics.Extensions.Middleware App.Metrics.Formatters.Json
二、修改appsettings.json文件:
"AppMetrics": { "DataBaseName": "qkaweb", "ConnectionString": "http://192.168.2.168:8086", "UserName": "leizhihui", "Password": "123456", "App": "QkaWebApis", "Env": "develop" }
三、添加以下代碼:
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(); }