Skip to content

Commit 3fe8ead

Browse files
committed
Add metrics and Prometheus support to WebApi
- Added project and package references for `Genocs.Metrics`. - Integrated `Genocs.Metrics.AppMetrics` and `Genocs.Metrics.Prometheus` in `Program.cs`. - Configured middleware for metrics and Prometheus in the request pipeline. - Updated `appsettings.json` for Jaeger monitoring and new metrics settings. - Removed outdated monitoring configurations and IIS Express settings. - Updated `README_NUGET.md` with new monitoring instructions. - Cleaned up and updated package references in `Genocs.Metrics.csproj`.
1 parent d9edd38 commit 3fe8ead

File tree

10 files changed

+39
-41
lines changed

10 files changed

+39
-41
lines changed

src/Genocs.Core.Demo.WebApi/Genocs.Core.Demo.WebApi.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<ProjectReference Include="..\Genocs.WebApi\Genocs.WebApi.csproj" />
1818
<ProjectReference Include="..\Genocs.WebApi.Security\Genocs.WebApi.Security.csproj" />
1919
<ProjectReference Include="..\Genocs.Secrets.AzureKeyVault\Genocs.Secrets.AzureKeyVault.csproj" />
20+
<ProjectReference Include="..\Genocs.Metrics\Genocs.Metrics.csproj" />
2021
</ItemGroup>
2122

2223
<ItemGroup Condition="'$(Configuration)' != 'Debug'">
@@ -29,6 +30,7 @@
2930
<PackageReference Include="Genocs.WebApi" Version="7.2.*" />
3031
<PackageReference Include="Genocs.WebApi.Security" Version="7.2.*" />
3132
<PackageReference Include="Genocs.Secrets.AzureKeyVault" Version="7.2.*" />
33+
<ProjectReference Include="Genocs.Metrics" Version="7.2.*"/>
3234
</ItemGroup>
3335

3436
<ItemGroup>

src/Genocs.Core.Demo.WebApi/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using Genocs.Tracing;
1111
using Microsoft.Extensions.Diagnostics.HealthChecks;
1212
using Serilog;
13+
using Genocs.Metrics.AppMetrics;
14+
using Genocs.Metrics.Prometheus;
1315
//using Genocs.Persistence.EFCore.Extensions;
1416

1517
StaticLogger.EnsureInitialized();
@@ -25,6 +27,8 @@
2527
.AddJwt()
2628
.AddOpenTelemetry()
2729
.AddMongoWithRegistration()
30+
.AddMetrics()
31+
.AddPrometheus()
2832
//.AddEFCorePersistence()
2933
.AddApplicationServices()
3034
.Build();
@@ -85,6 +89,9 @@
8589

8690
app.UseAuthorization();
8791

92+
app.UseMetrics()
93+
.UsePrometheus();
94+
8895
// Use it only if you need to authenticate with Firebase
8996
// app.UseFirebaseAuthentication();
9097

src/Genocs.Core.Demo.WebApi/Properties/launchSettings.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
"environmentVariables": {
1515
"ASPNETCORE_ENVIRONMENT": "Development"
1616
},
17-
"IIS Express": {
18-
"commandName": "IISExpress",
19-
"launchBrowser": true,
20-
"environmentVariables": {
21-
"ASPNETCORE_ENVIRONMENT": "Development"
22-
}
23-
},
2417
"applicationUrl": "https://localhost:5071;http://localhost:5070"
2518
}
2619
}

src/Genocs.Core.Demo.WebApi/appsettings.json

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@
2424
"connectionString": "<<connection_string>>"
2525
}
2626
},
27-
"monitoring": {
28-
"jaeger": "localhost"
27+
"jaeger": {
28+
"enabled": true,
29+
"serviceName": "users",
30+
"udpHost": "localhost",
31+
"udpPort": 6831,
32+
"maxPacketSize": 65000,
33+
"sampler": "const",
34+
"excludePaths": [
35+
"/",
36+
"/ping",
37+
"/metrics"
38+
]
2939
},
3040
"jwt": {
3141
"ValidIssuer": "http://localhost/Auth",
@@ -96,5 +106,20 @@
96106
"email": "[email protected]"
97107
}
98108
]
109+
},
110+
"metrics": {
111+
"enabled": true,
112+
"influxEnabled": false,
113+
"prometheusEnabled": false,
114+
"influxUrl": "http://localhost:8086",
115+
"influxDatabase": "demo",
116+
"influxUsername": "admin",
117+
"influxPassword": "yourpassword",
118+
"interval": 5
119+
},
120+
"prometheus": {
121+
"enabled": false,
122+
"endpoint": "http://localhost:5070"
99123
}
100124
}
125+

src/Genocs.Core.Demo.Worker/appsettings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
"database": "demo",
2929
"enableTracing": true
3030
},
31-
"Monitoring": {
32-
"Jaeger": "localhost"
33-
},
3431
"app": {
3532
"name": "Demo Worker",
3633
"service": "demo-worker-service",

src/Genocs.HTTP/README_NUGET.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ Following are the project settings needed to enable monitoring
2525
},
2626
"ConnectionStrings": {
2727
"ApplicationInsights": ""
28-
},
29-
"Monitoring": {
30-
"Jaeger": "localhost",
3128
}
3229
```
3330

src/Genocs.MessageBrokers.Outbox/Genocs.MessageBrokers.Outbox.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PackageReleaseNotes>
1818
The change log and breaking changes are listed here.
1919
https://github.com/Genocs/genocs-library/releases
20-
</PackageReleaseNotes>
20+
</PackageReleaseNotes>
2121
</PropertyGroup>
2222

2323
<ItemGroup Condition="'$(Configuration)' == 'Debug'">

src/Genocs.MessageBrokers/README_NUGET.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ Following are the project settings needed to enable monitoring
2525
},
2626
"ConnectionStrings": {
2727
"ApplicationInsights": ""
28-
},
29-
"Monitoring": {
30-
"Jaeger": "localhost",
3128
}
3229
```
3330

src/Genocs.Metrics/AppMetrics/Extensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public static class Extensions
2222
private const string RegistryName = "metrics.metrics";
2323
private static bool _initialized;
2424

25-
[Description("For the time being it sets Kestrel's AllowSynchronousIO = true, see https://github.com/AppMetrics/AppMetrics/issues/396")]
2625
public static IGenocsBuilder AddMetrics(
2726
this IGenocsBuilder builder,
2827
string metricsSectionName = Configurations.MetricsOptions.Position,
@@ -44,7 +43,6 @@ public static IGenocsBuilder AddMetrics(
4443
return builder.AddMetrics(metricsOptions, appOptions);
4544
}
4645

47-
[Description("For the time being it sets Kestrel's AllowSynchronousIO = true, see https://github.com/AppMetrics/AppMetrics/issues/396")]
4846
public static IGenocsBuilder AddMetrics(
4947
this IGenocsBuilder builder,
5048
Func<IMetricsOptionsBuilder, IMetricsOptionsBuilder> buildOptions,
@@ -61,7 +59,6 @@ public static IGenocsBuilder AddMetrics(
6159
return builder.AddMetrics(metricsOptions, appOptions);
6260
}
6361

64-
[Description("For the time being it sets Kestrel's and IIS ServerOptions AllowSynchronousIO = true, see https://github.com/AppMetrics/AppMetrics/issues/396")]
6562
public static IGenocsBuilder AddMetrics(
6663
this IGenocsBuilder builder,
6764
Configurations.MetricsOptions metricsSettings,

src/Genocs.Metrics/Genocs.Metrics.csproj

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,16 @@
3030

3131
<ItemGroup>
3232
<PackageReference Include="App.Metrics.AspNetCore" Version="4.3.0" />
33-
<PackageReference Include="App.Metrics.AspNetCore.Core" Version="4.3.0" />
34-
<PackageReference Include="App.Metrics.AspNetCore.Endpoints" Version="4.3.0" />
35-
<PackageReference Include="App.Metrics.AspNetCore.Health" Version="3.2.0" />
3633
<PackageReference Include="App.Metrics.AspNetCore.Health.Endpoints" Version="3.2.0" />
37-
<PackageReference Include="App.Metrics.AspNetCore.Hosting" Version="4.3.0" />
38-
<PackageReference Include="App.Metrics.AspNetCore.Mvc" Version="4.3.0" />
39-
<PackageReference Include="App.Metrics.AspNetCore.Reporting" Version="4.0.0" />
40-
<PackageReference Include="App.Metrics.AspNetCore.Routing" Version="4.3.0" />
41-
<PackageReference Include="App.Metrics.AspNetCore.Tracking" Version="4.3.0" />
4234
<PackageReference Include="App.Metrics.Core" Version="4.3.0" />
43-
<PackageReference Include="App.Metrics.Extensions.Configuration" Version="4.3.0" />
44-
<PackageReference Include="App.Metrics.Extensions.DependencyInjection" Version="4.3.0" />
4535
<PackageReference Include="App.Metrics.Formatters.InfluxDB" Version="4.3.0" />
46-
<PackageReference Include="App.Metrics.Formatters.Json" Version="4.3.0" />
4736
<PackageReference Include="App.Metrics.Formatters.Prometheus" Version="4.3.0" />
48-
<PackageReference Include="App.Metrics.Health.Checks.Http" Version="3.2.0" />
49-
<PackageReference Include="App.Metrics.Reporting.Console" Version="4.3.0" />
50-
<PackageReference Include="App.Metrics.Reporting.Http" Version="4.3.0" />
5137
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.3.0" />
5238
</ItemGroup>
5339

5440
<ItemGroup>
55-
<PackageReference Include="prometheus-net" Version="8.2.1" />
56-
<PackageReference Include="prometheus-net.AspNetCore" Version="5.0.2" />
57-
<PackageReference Include="prometheus-net.AspNetCore.Grpc" Version="5.0.2" />
58-
<PackageReference Include="prometheus-net.AspNetCore.HealthChecks" Version="5.0.2" />
41+
<PackageReference Include="prometheus-net.AspNetCore.Grpc" Version="8.2.1" />
5942
<PackageReference Include="prometheus-net.DotNetRuntime" Version="4.4.1" />
60-
<PackageReference Include="prometheus-net.SystemMetrics" Version="2.0.0" />
43+
<PackageReference Include="prometheus-net.SystemMetrics" Version="3.1.0" />
6144
</ItemGroup>
6245
</Project>

0 commit comments

Comments
 (0)