Skip to content
This repository has been archived by the owner on Mar 13, 2020. It is now read-only.

Commit

Permalink
feat : 增加使用App Metrics 度量服务器性能监控
Browse files Browse the repository at this point in the history
  • Loading branch information
geffzhang committed Dec 3, 2017
1 parent 7770d78 commit 794dd39
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
3 changes: 3 additions & 0 deletions src/NanoFabric.Ocelot/NanoFabric.Ocelot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="App.Metrics" Version="2.0.0-alpha" />
<PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="2.0.0-alpha" />
<PackageReference Include="App.Metrics.AspNetCore.Reporting" Version="2.0.0-alpha" />
<PackageReference Include="App.Metrics.AspNetCore.Tracking" Version="2.0.0-alpha" />
<PackageReference Include="App.Metrics.Formatters.Json" Version="2.0.0-alpha" />
<PackageReference Include="Ocelot" Version="2.0.4" />
</ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/NanoFabric.Ocelot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public static void Main(string[] args)
builder.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseMetricsWebTracking()
.UseMetricsEndpoints()
.UseStartup<Startup>();
var host = builder.Build();
host.Run();
Expand Down
24 changes: 10 additions & 14 deletions src/NanoFabric.Ocelot/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.Extensions.Configuration;
using Ocelot.Middleware;
using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder;
using App.Metrics;

namespace NanoFabric.Ocelot
{
Expand Down Expand Up @@ -51,20 +52,13 @@ public void ConfigureServices(IServiceCollection services)

services.AddOcelot(Configuration);

//services.AddMetrics(options =>
//{
// options.DefaultContextLabel = "NanoFabric API Gateway";
// options.MetricsEnabled = true;
// options.WithGlobalTags((globalTags, envInfo) =>
// {
// globalTags.Add("host", envInfo.HostName);
// globalTags.Add("machine_name", envInfo.MachineName);
// globalTags.Add("app_name", envInfo.EntryAssemblyName);
// globalTags.Add("app_version", envInfo.EntryAssemblyVersion);
// });
//})
//.AddJsonSerialization()
//.AddHealthChecks();//这里是健康检查的注入
var metrics = AppMetrics.CreateDefaultBuilder()
.Build();

services.AddMetrics(metrics);
services.AddMetricsTrackingMiddleware();
services.AddMetricsEndpoints();
services.AddMetricsReportScheduler();
}

public IConfigurationRoot Configuration { get; }
Expand All @@ -73,6 +67,8 @@ public void ConfigureServices(IServiceCollection services)
public async void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime applicationLifetime)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
app.UseMetricsAllMiddleware();
app.UseMetricsAllEndpoints();
await app.UseOcelot();
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/NanoFabric.Ocelot/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,18 @@
"System": "Error",
"Microsoft": "Error"
}
},
"MetricsWebTrackingOptions": {
"ApdexTrackingEnabled": true,
"ApdexTSeconds": 0.1,
"IgnoredHttpStatusCodes": [ 404 ],
"IgnoredRoutesRegexPatterns": [],
"OAuth2TrackingEnabled": true
},
"MetricEndpointsOptions": {
"MetricsEndpointEnabled": true,
"MetricsTextEndpointEnabled": true,
"EnvironmentInfoEndpointEnabled": true
}

}

0 comments on commit 794dd39

Please sign in to comment.