Metrics

Overview

Coravel Pro gives you a beautiful dashboard to view metrics for your app.

By default, Coravel Pro looks through all your loaded assemblies and automatically registers all classes that implement any of the Metric types below!

Let's say that again - you don't have to manually add your metrics to .NET Core's service provider! Coravel automatically detects all your metrics and takes care of all the configuration!

TIP

If you wish to have a custom configuration (specify metric order, exclude metrics, etc.) see Customizing Metrics

Accessing Your Dashboard

You may access your dashboard by navigating to /Coravel/Dashboard/ in your internet browser.

Metric Card

A metric card is a small widget/card that displays some metric for your system.

cards

Implement IMetricCard

Create a class that implements Coravel.Pro.Features.Metrics.IMetricCard.

You will need to implement the method ExecuteAsync - which is where you should fetch your data and set your metric card's properties.

Properties

You must implement these properties (get and set):

  • Value is the metric value you want displayed
  • Title is the title at the top of your metric card
  • SubTitle is the smaller grey text in the title (which is automatically wrapped with parenthesis)
  • IsPositiveMetric determines whether your card will be green or red
  • IncludeArrow will toggle the visibility of the metric card's green/red arrow

Required Services

Since Coravel Pro is designed as a native .NET Core library, you may simply inject any required services through your class' constructor.

Example

sample user metric

This is a metric card that you might create to fetch and display the amount of users in your database (using EF Core):

public class UserCountMetric : IMetricCard
{
    private ApplicationDbContext _context;

    // Inject dbContext from service provider.
    public UserCountMetric(ApplicationDbContext context) => 
        this._context = context;

    // Fetch and assign values in this method.  
    public async Task ExecuteAsync()
    {
        int count = await this._context.Users.CountAsync();
        this.Value = $"{count} Users";
        this.Title = "User Count";
        this.IsPositiveMetric = true;
        this.IncludeArrow = true;
    }

    // These are implemented from IMetric Card.
    public string Value { get; set; }
    public string Title { get; set; }
    public string SubTitle { get; set; }
    public bool IsPositiveMetric { get; set; }    
    public bool IncludeArrow { get; set; }
}   

Other Notes

Keep in mind that you can fetch anything!

Inject an HttpClientFactory into your metric and you can display metrics from an API (don't forget to cache it 😉).

Aggregate data that's stored in a file!

Etc.