MDMRestApiStats 1.0.3

Sampling Rest API statistics in a Ringlist

Install-Package MDMRestApiStats -Version 1.0.3
dotnet add package MDMRestApiStats --version 1.0.3
<PackageReference Include="MDMRestApiStats" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MDMRestApiStats --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MDMRestApiStats, 1.0.3"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install MDMRestApiStats as a Cake Addin
#addin nuget:?package=MDMRestApiStats&version=1.0.3

// Install MDMRestApiStats as a Cake Tool
#tool nuget:?package=MDMRestApiStats&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Readme

About

MDM API Stats is a small library thats collect measurements in memory in a ring list. There are three main section that are working and counting independly

  1. Automated counting implementet as middleware that counts automated the requests, response time and response bytes depending on white-, or blackfilterlists.
  2. Heart Beat that is periodically calling callback methods in Web Application
  3. User Counts where the developer can measure importent methods with response times and counts

Usage

In a WEB Application


Setup

Setup in startup.cs

  1. Add StatsManager as service
IStatsManager mgr = new StatsManager(new StatsManagerOptions())
    .UseKpiGroupsEnabled(StatsKpiGroups.All)                                                 // <- Use all three capabilities
    .UseAsUrlWhiteListFilter(key => (new string[] { "/main/" })                              // URL should contain main
                                                    .Any(key.ToLower().Contains))            // <- Define a whitelist
    .UseAsUrlBlackListFilter(key => (new string[] { ".svg", ".js", ".css", ".ico", ".png" }) // <- Define a blacklist (ignore everything ending with...)
                                                    .Any(key.ToLower().Contains));

services.AddSingleton(mgr); // <- Add as Singleton service


Configure Service
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IStatsManager stats)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseStatsManager(stats);         // <- Usie statsmanager

    app.UseStaticFiles();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Main}/{action=Index}/{id?}");
    });
}

Setup and usage in Controller
Define a local property
private readonly IStatsManager stats;
  1. Inject services into constructor here is the config example of Hertbeats. Its possible to define more then one HeartBeat. Each HeratBeat should use a unique name.
public MainController(IStatsManager stats, ILogger<MainController> logger)
{
    this.stats = stats;
    this.stats
    .UseKpiGroupsEnabled(StatsKpiGroups.HeartBeat)      // Enable HeratBeat
    .UseAsHeartBeatHandler(() => HeartBeatHandler(),    // HeartBeat callback
        new HeartBeatCallBack()                         // HeartBeat Setup
        .WithName("MainController")
        .WithIntervaInSec(10)
        .WithExpectedDurationMs(90))
    .StartHeartBeats();                                 // Start Heart Beat

    this.logger = logger;
}

HeartBeat handler (here a dummy)
private HeartBeatReturns HeartBeatHandler()
{
    Random rnd = new Random(DateTime.Now.Millisecond);
    // Do some fast checks to see if everything works
    int rndval = rnd.Next(5, 100);
    Thread.Sleep(rndval);
    if (rndval % 2 == 0)
        return HeartBeatReturns.Failed("Failed because of the code " + rndval);
    return HeartBeatReturns.Ok();
}

Usage in Method

All KPI's are identified by Key that should be unique

// GET: Main/Details/5
public IActionResult Details(int id)
{
    stats.Start($"time:path:/main/details{id}");        // Starts Time KPI 
    //do some useful staff
    stats.Increment($"coun:path:/main/details{id}");    // Increment count KPI
    ViewResult rc = View();
    stats.Stop($"time:path:/main/details{id}");         // Stops Time KPI
    return rc;
}

Dependencies


History

  • 1.0.0 Initial version
  • 1.0.1 Minor bugfixes
  • 1.0.2 NEW Possible to Error Messages in case of failed heart beat
  • 1.0.3 NEW Filter for stats to json FIX ToJson Failed due to parallel acces on list

Readme

About

MDM API Stats is a small library thats collect measurements in memory in a ring list. There are three main section that are working and counting independly

  1. Automated counting implementet as middleware that counts automated the requests, response time and response bytes depending on white-, or blackfilterlists.
  2. Heart Beat that is periodically calling callback methods in Web Application
  3. User Counts where the developer can measure importent methods with response times and counts

Usage

In a WEB Application


Setup

Setup in startup.cs

  1. Add StatsManager as service
IStatsManager mgr = new StatsManager(new StatsManagerOptions())
    .UseKpiGroupsEnabled(StatsKpiGroups.All)                                                 // <- Use all three capabilities
    .UseAsUrlWhiteListFilter(key => (new string[] { "/main/" })                              // URL should contain main
                                                    .Any(key.ToLower().Contains))            // <- Define a whitelist
    .UseAsUrlBlackListFilter(key => (new string[] { ".svg", ".js", ".css", ".ico", ".png" }) // <- Define a blacklist (ignore everything ending with...)
                                                    .Any(key.ToLower().Contains));

services.AddSingleton(mgr); // <- Add as Singleton service


Configure Service
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IStatsManager stats)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseStatsManager(stats);         // <- Usie statsmanager

    app.UseStaticFiles();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Main}/{action=Index}/{id?}");
    });
}

Setup and usage in Controller
Define a local property
private readonly IStatsManager stats;
  1. Inject services into constructor here is the config example of Hertbeats. Its possible to define more then one HeartBeat. Each HeratBeat should use a unique name.
public MainController(IStatsManager stats, ILogger<MainController> logger)
{
    this.stats = stats;
    this.stats
    .UseKpiGroupsEnabled(StatsKpiGroups.HeartBeat)      // Enable HeratBeat
    .UseAsHeartBeatHandler(() => HeartBeatHandler(),    // HeartBeat callback
        new HeartBeatCallBack()                         // HeartBeat Setup
        .WithName("MainController")
        .WithIntervaInSec(10)
        .WithExpectedDurationMs(90))
    .StartHeartBeats();                                 // Start Heart Beat

    this.logger = logger;
}

HeartBeat handler (here a dummy)
private HeartBeatReturns HeartBeatHandler()
{
    Random rnd = new Random(DateTime.Now.Millisecond);
    // Do some fast checks to see if everything works
    int rndval = rnd.Next(5, 100);
    Thread.Sleep(rndval);
    if (rndval % 2 == 0)
        return HeartBeatReturns.Failed("Failed because of the code " + rndval);
    return HeartBeatReturns.Ok();
}

Usage in Method

All KPI's are identified by Key that should be unique

// GET: Main/Details/5
public IActionResult Details(int id)
{
    stats.Start($"time:path:/main/details{id}");        // Starts Time KPI 
    //do some useful staff
    stats.Increment($"coun:path:/main/details{id}");    // Increment count KPI
    ViewResult rc = View();
    stats.Stop($"time:path:/main/details{id}");         // Stops Time KPI
    return rc;
}

Dependencies


History

  • 1.0.0 Initial version
  • 1.0.1 Minor bugfixes
  • 1.0.2 NEW Possible to Error Messages in case of failed heart beat
  • 1.0.3 NEW Filter for stats to json FIX ToJson Failed due to parallel acces on list

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.3 531 6/5/2018
1.0.2 519 6/5/2018
1.0.1 509 5/28/2018
1.0.0 554 5/28/2018