Giter VIP home page Giter VIP logo

masstransit.prometheus's Introduction

MassTransit metrics for Prometheus

Description

This library allows you collecting four important metrics for MassTransit consumers and send them to Prometheus. Those metrics are:

  • app_message_processing_time_seconds - the time it takes to consume one message
  • app_message_critical_time_seconds - the total time between when the message was sent and when it was consumed
  • app_message_count - the total number of messages received
  • app_message_failures_count - the number of messages that failed processing

All metrics are labeled with two labels:

  • service_name - the name of your application or service
  • message_type - the type of message for which the metrics are collected

Prometheus client library

We use Nexogen.Libraries.Metrics library as a Prometheus client. The client itself is not included as a reference, we only use the core and the extension libraries.

Check the GitHub repository for more details about the client library we use.

Usage

First, you need to add metrics to your application. Start by adding the client library to your project using a NuGet package:

dotnet add package Nexogen.Libraries.Metrics.Prometheus

Metrics need to be available via an HTTP endpoint, by default it is /metrics. Add the ASP.NET Core integration package to get this endpoint out-of-the-box:

dotnet add package Nexogen.Libraries.Metrics.Prometheus.AspCore

Then, create Prometheus metrics object and register it in the services collection. The same instance should be used to configure the bus:

public void ConfigureServices(IServiceCollection services)
{
    var metrics = new PrometheusMetrics();
    
    services.AddSingleton(Bus.Factory.CreateUsingRabbitMq(cfg =>
    {
        cfg.UsePrometheusMetrics(metrics);
    
        var host = cfg.Host(new Uri("rabbitmq://localhost"), h => 
        {
            h.UserName("guest");
            h.Password("guest");
        });

        cfg.ReceiveEndpoint(host, "myqueue", e =>
        {
            e.Consumer<MyMessageConsumer>();
        });
    }));
    
    services.AddPrometheus(metrics);
    
    // other services
}

Finally, add Prometheus integration to the service configuration:

public void Configure(IApplicationBuilder app)
{
    app.UsePrometheus();
}

masstransit.prometheus's People

Contributors

alexeyzimarev avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.