prometheus-net

Форк
0
44 строки · 1.2 Кб
1
// This sample demonstrates how to integrate prometheus-net into a web app while instructing it
2
// to export metrics on a dedicated port (e.g. so it can be firewalled off from the internet).
3
// 
4
// NuGet packages required:
5
// * prometheus-net.AspNetCore
6

7
using Prometheus;
8

9
var builder = WebApplication.CreateBuilder(args);
10

11
builder.Services.AddRazorPages();
12

13
// Start the metrics exporter as a background service.
14
// Open http://localhost:5167 to see the web app.
15
// Open http://localhost:1234/metrics to see the metrics.
16
//
17
// Metrics published:
18
// * built-in process metrics giving basic information about the .NET runtime (enabled by default)
19
// * metrics from .NET Event Counters (enabled by default, updated every 10 seconds)
20
// * metrics from .NET Meters (enabled by default)
21
// * metrics about requests handled by the web app (configured below)
22
builder.Services.AddMetricServer(options =>
23
{
24
    options.Port = 1234;
25
});
26

27
var app = builder.Build();
28

29
if (!app.Environment.IsDevelopment())
30
{
31
    app.UseExceptionHandler("/Error");
32
}
33
app.UseStaticFiles();
34

35
app.UseRouting();
36

37
// Capture metrics about all received HTTP requests.
38
app.UseHttpMetrics();
39

40
app.UseAuthorization();
41

42
app.MapRazorPages();
43

44
app.Run();
45

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.