Skip to content

EpThreshold is a tiny middleware for Asp.Net Core which can be used to take action on requests which takes longers than a given threshold.

Notifications You must be signed in to change notification settings

WilliamGanrot/EpThreshold

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EpThreshold

EpThreshold is a tiny middleware for Asp.Net Core which can be used to take action on requests which takes longers than a given threshold. Such action could for example be to log the request in order to track unexpectedly demanding requests in order to optimize them.

Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
    ....
    
    app.UseEpThreshold(o =>
    {
        o.Threshold = 1300; // The default threshold in ms for an endpoint. If a request takes longer than this the ThresholdMetAction will be invoked.
        o.ThresholdMetAction = async (ThresholdLogModel model) => await _queueClient.SendAsync(model);
    });

    ....
}

If you want to set a custom threshold on an endpoint you can use the Attribute [Threshold(100)].

[Threshold(100)] //if the request takes any longer than 100 ms, invoke ThresholdMetAction
[HttpGet("GetWeatherForecast/{id}")]
public async Task<WeatherForecast> GetWeatherForecast(int id)
{
    ....
}

You can install the nuget here: https://www.nuget.org/packages/EpThreshold/1.0.0

About

EpThreshold is a tiny middleware for Asp.Net Core which can be used to take action on requests which takes longers than a given threshold.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages