MDMRestApiStats 1.0.2
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MDMRestApiStats --version 1.0.2
NuGet\Install-Package MDMRestApiStats -Version 1.0.2
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="MDMRestApiStats" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MDMRestApiStats --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MDMRestApiStats, 1.0.2"
#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 MDMRestApiStats as a Cake Addin #addin nuget:?package=MDMRestApiStats&version=1.0.2 // Install MDMRestApiStats as a Cake Tool #tool nuget:?package=MDMRestApiStats&version=1.0.2
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
- Automated counting implementet as middleware that counts automated the requests, response time and response bytes depending on white-, or blackfilterlists.
- Heart Beat that is periodically calling callback methods in Web Application
- User Counts where the developer can measure importent methods with response times and counts
Usage
In a WEB Application
Setup
Setup in startup.cs
- 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;
- 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
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
.NET Core | netcoreapp2.0 is compatible. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 2.0
- Microsoft.AspNetCore (>= 2.0.3)
- Newtonsoft.Json (>= 11.0.2)
- quartz (>= 3.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.