Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/PrometheusClientNet/Prometheus.Client.MetricServer

Standalone Kestrel server for the Prometheus.Client
https://github.com/PrometheusClientNet/Prometheus.Client.MetricServer

metrics prometheus prometheus-client

Last synced: about 2 months ago
JSON representation

Standalone Kestrel server for the Prometheus.Client

Awesome Lists containing this project

README

        

# Prometheus.Client.MetricServer

[![ci](https://img.shields.io/github/actions/workflow/status/prom-client-net/prom-client-metricserver/ci.yml?branch=main&label=ci&logo=github&style=flat-square)](https://github.com/prom-client-net/prom-client-metricserver/actions/workflows/ci.yml)
[![nuget](https://img.shields.io/nuget/v/Prometheus.Client.MetricServer?logo=nuget&style=flat-square)](https://www.nuget.org/packages/Prometheus.Client.MetricServer)
[![nuget](https://img.shields.io/nuget/dt/Prometheus.Client.MetricServer?logo=nuget&style=flat-square)](https://www.nuget.org/packages/Prometheus.Client.MetricServer)
[![codecov](https://img.shields.io/codecov/c/github/prom-client-net/prom-client-metricserver?logo=codecov&style=flat-square)](https://app.codecov.io/gh/prom-client-net/prom-client-metricserver)
[![codefactor](https://img.shields.io/codefactor/grade/github/prom-client-net/prom-client-metricserver?logo=codefactor&style=flat-square)](https://www.codefactor.io/repository/github/prom-client-net/prom-client-metricserver)
[![license](https://img.shields.io/github/license/prom-client-net/prom-client-metricserver?style=flat-square)](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
{
CollectorRegistryInstance = 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).