forked from prometheus-net/prometheus-net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
33 lines (27 loc) · 1.17 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
using Prometheus;
// This sample demonstrates how to integrate prometheus-net into a console app (e.g. a worker service).
//
// NuGet packages required:
// * prometheus-net.AspNetCore
// Start the metrics server on your preferred port number.
using var server = new KestrelMetricServer(port: 1234);
server.Start();
// Generate some sample data from fake business logic.
var recordsProcessed = Metrics.CreateCounter("sample_records_processed_total", "Total number of records processed.");
_ = Task.Run(async delegate
{
while (true)
{
// Pretend to process a record approximately every second, just for changing sample data.
recordsProcessed.Inc();
await Task.Delay(TimeSpan.FromSeconds(1));
}
});
// Metrics published in this sample:
// * 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)
// * the custom sample counter defined above
Console.WriteLine("Open http://localhost:1234/metrics in a web browser.");
Console.WriteLine("Press enter to exit.");
Console.ReadLine();