MSHelper.Metrics.Prometheus 1.0.0

dotnet add package MSHelper.Metrics.Prometheus --version 1.0.0
NuGet\Install-Package MSHelper.Metrics.Prometheus -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSHelper.Metrics.Prometheus" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MSHelper.Metrics.Prometheus --version 1.0.0
#r "nuget: MSHelper.Metrics.Prometheus, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MSHelper.Metrics.Prometheus as a Cake Addin
#addin nuget:?package=MSHelper.Metrics.Prometheus&version=1.0.0

// Install MSHelper.Metrics.Prometheus as a Cake Tool
#tool nuget:?package=MSHelper.Metrics.Prometheus&version=1.0.0

MSHelper.Metrics.Prometheus : Prometheus Integration

⭐ Star us on GitHub � it motivates us a lot!

Overview

Adds capability of generating application metrics and exposing them via HTTP endpoint.

Installation

This document is for the latest MSHelper.Metrics.Prometheus 1.0.0 release and later.

dotnet add package MSHelper.Metrics.Prometheus

Dependencies

-- MSHelper

Options

--- enabled - determines whether metrics endpoint is going to be available.

--- influxEnabled - if true metrics will be reported to InfluxDB.

--- prometheusEnabled - if true metrics will be formatted using Prometheus data model.

--- prometheusFormatter - if set to protobuf then protobuf output formatter is going to be used. Otherwise, text output formatter is picked.

--- InfluxUrl - connection string to InfluxDB instance e.g. http://localhost:8086. Required only if influxEnabled is true.

--- database - InfluxDB database name. Required only if influxEnabled is true.

--- interval - InfluxDB flush interval expressed in seconds. Required only if influxEnabled is true.

appsettings.json

"prometheus": {
  "enabled": true,
  "endpoint": "/metrics"
}

Usage

Inside Startup.cs extend IMSHelperBuilder with AddMetrics() and IApplicationBuilder with UseMetrics():

public IServiceProvider ConfigureServices(this IServiceCollection services)
{
    var builder = services.AddMSHelper()
        .AddMetrics();

    //other registrations    
    return builder.Build();
}

public void Configure(this IApplicationBuilder app)
{
    app.UseMetrics();
}

The above code registers all required services and exposes some default application metrics at two HTTP endpoints:

--- http://host/metrics - depending on prometheusEnabled option, this endpoint exposes metrics that are either formatted using Prometheus data model or using standard, text formatter --- http://host/metrics-text - this endpoint exposes metrics that are always formated using standard, text formatter

Creating custom metrics

Once you finish MSHelper registration, you can create custom application metrics using the AppMetrics library for .NET Core. There are six different metrics types you can use:

-- Gauges

-- Counters

-- Meters

-- Histograms

-- Timers

-- Apdex

To create a custom metrics inject IMetricsRoot into selected class:

public class MetricsRegistry
{
    private readonly IMetricsRoot _metricsRoot;
    private readonly CounterOptions _findDiscountsQueries = new CounterOptions { Name = "find-discount" };

    public MetricsRegistry(IMetricsRoot metricsRoot)
        => _metricsRoot = metricsRoot;
    
    public void IncrementFindDiscountsQuery()
        => _metricsRoot.Measure.Counter.Increment(_findDiscountsQueries);
}

Important Note:

All the MSHelper packages are for self learning purposes inspired by Devmentors.io

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 195 10/25/2022