https://github.com/prom-client-net/prom-client-metricserver
Standalone Kestrel server
https://github.com/prom-client-net/prom-client-metricserver
metrics prometheus prometheus-client
Last synced: 5 months ago
JSON representation
Standalone Kestrel server
- Host: GitHub
- URL: https://github.com/prom-client-net/prom-client-metricserver
- Owner: prom-client-net
- License: mit
- Created: 2017-05-05T23:06:02.000Z (about 9 years ago)
- Default Branch: main
- Last Pushed: 2025-12-13T04:04:15.000Z (6 months ago)
- Last Synced: 2025-12-14T16:40:18.401Z (6 months ago)
- Topics: metrics, prometheus, prometheus-client
- Language: C#
- Homepage:
- Size: 388 KB
- Stars: 15
- Watchers: 2
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Prometheus.Client.MetricServer
[](https://github.com/prom-client-net/prom-client-metricserver/actions/workflows/ci.yml)
[](https://www.nuget.org/packages/Prometheus.Client.MetricServer)
[](https://www.nuget.org/packages/Prometheus.Client.MetricServer)
[](https://app.codecov.io/gh/prom-client-net/prom-client-metricserver)
[](https://github.com/prom-client-net/prom-client-metricserver/blob/main/LICENSE)
Extension for [Prometheus.Client](https://github.com/prom-client-net/prom-client)
## Install
```sh
dotnet add package Prometheus.Client.MetricServer
```
## Use
[Examples](https://github.com/prom-client-net/prom-examples)
Simple Console App with static MetricFactory:
```c#
public static void Main(string[] args)
{
var options = new MetricServerOptions
{
Port = 9091
};
var metricServer = new MetricServer(options);
metricServer.Start();
var counter = Metrics.DefaultFactory.CreateCounter("test_count", "helptext");
counter.Inc();
metricServer.Stop();
}
```
Worker with DI [Prometheus.Client.DependencyInjection](https://github.com/prom-client-net/prom-client-dependencyinjection):
```c#
public static async Task Main(string[] args)
{
var host = Host.CreateDefaultBuilder(args)
.ConfigureServices((_, services) =>
{
services.AddMetricFactory();
services.AddSingleton(sp => new MetricServer(
new MetricServerOptions
{
CollectorRegistry = sp.GetRequiredService(),
UseDefaultCollectors = true
}));
services.AddHostedService();
}).Build();
var metricServer = host.Services.GetRequiredService();
try
{
metricServer.Start();
await host.RunAsync();
}
catch (Exception ex)
{
Console.WriteLine("Host Terminated Unexpectedly");
}
finally
{
metricServer.Stop();
}
}
```
## License
All contents of this package are licensed under the [MIT license](https://opensource.org/licenses/MIT).