forked from prometheus-net/prometheus-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (33 loc) · 1.19 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This sample demonstrates how to integrate prometheus-net into a web app while instructing it
// to export metrics on a dedicated port (e.g. so it can be firewalled off from the internet).
//
// NuGet packages required:
// * prometheus-net.AspNetCore
using Prometheus;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
// Start the metrics exporter as a background service.
// Open http://localhost:5167 to see the web app.
// Open http://localhost:1234/metrics to see the metrics.
//
// Metrics published:
// * built-in process metrics giving basic information about the .NET runtime (enabled by default)
// * metrics from .NET Event Counters (enabled by default, updated every 10 seconds)
// * metrics from .NET Meters (enabled by default)
// * metrics about requests handled by the web app (configured below)
builder.Services.AddMetricServer(options =>
{
options.Port = 1234;
});
var app = builder.Build();
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
// Capture metrics about all received HTTP requests.
app.UseHttpMetrics();
app.UseAuthorization();
app.MapRazorPages();
app.Run();