diff --git a/Builder/MetricsAspNetResourceWebHostBuilderExtensions.cs b/Builder/MetricsAspNetResourceWebHostBuilderExtensions.cs
new file mode 100755
index 0000000..28db3b3
--- /dev/null
+++ b/Builder/MetricsAspNetResourceWebHostBuilderExtensions.cs
@@ -0,0 +1,118 @@
+using App.Metrics.AspNetCore.Resource;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using System;
+
+// ReSharper disable CheckNamespace
+namespace Microsoft.AspNetCore.Hosting
+// ReSharper restore CheckNamespace
+{
+ public static class MetricsAspNetResourceWebHostBuilderExtensions
+ {
+ ///
+ /// Adds App Metrics services, configuration and middleware to the
+ /// .
+ ///
+ /// The .
+ /// A reference to this instance after the operation has completed.
+ ///
+ /// cannot be null
+ ///
+ public static IWebHostBuilder UseResourceMetrics(this IWebHostBuilder hostBuilder)
+ {
+ hostBuilder.ConfigureMetrics();
+
+ hostBuilder.ConfigureServices(
+ (context, services) =>
+ {
+ services.AddResourceMetricsMiddleware(context.Configuration);
+ services.AddSingleton(new DefaultResourceMetricsStartupFilter());
+ });
+
+ return hostBuilder;
+ }
+
+ ///
+ /// Adds App Metrics services, configuration and middleware to the
+ /// .
+ ///
+ /// The .
+ /// A callback to configure .
+ /// A reference to this instance after the operation has completed.
+ ///
+ /// cannot be null
+ ///
+ public static IWebHostBuilder UseResourceMetrics(
+ this IWebHostBuilder hostBuilder,
+ Action optionsDelegate)
+ {
+ hostBuilder.ConfigureMetrics();
+
+ hostBuilder.ConfigureServices(
+ (context, services) =>
+ {
+ services.AddResourceMetricsMiddleware(optionsDelegate, context.Configuration);
+ services.AddSingleton(new DefaultResourceMetricsStartupFilter());
+ });
+
+ return hostBuilder;
+ }
+
+ ///
+ /// Adds App Metrics services, configuration and middleware to the
+ /// .
+ ///
+ /// The .
+ /// A callback to configure .
+ /// A reference to this instance after the operation has completed.
+ ///
+ /// cannot be null
+ ///
+ public static IWebHostBuilder UseResourceMetrics(
+ this IWebHostBuilder hostBuilder,
+ Action setupDelegate)
+ {
+ hostBuilder.ConfigureMetrics();
+
+ hostBuilder.ConfigureServices(
+ (context, services) =>
+ {
+ var ResourceOptions = new ResourceMetricsOptions();
+ services.AddResourceMetricsMiddleware(
+ options => setupDelegate(context, ResourceOptions),
+ context.Configuration);
+ services.AddSingleton(new DefaultResourceMetricsStartupFilter());
+ });
+
+ return hostBuilder;
+ }
+
+ ///
+ /// Adds App Metrics services, configuration and middleware to the
+ /// .
+ ///
+ /// The .
+ /// The containing
+ /// A callback to configure .
+ /// A reference to this instance after the operation has completed.
+ ///
+ /// cannot be null
+ ///
+ public static IWebHostBuilder UseResourceMetrics(
+ this IWebHostBuilder hostBuilder,
+ IConfiguration configuration,
+ Action optionsDelegate)
+ {
+ hostBuilder.ConfigureMetrics();
+
+ hostBuilder.ConfigureServices(
+ services =>
+ {
+ services.AddResourceMetricsMiddleware(optionsDelegate, configuration);
+ services.AddSingleton(new DefaultResourceMetricsStartupFilter());
+ });
+
+ return hostBuilder;
+ }
+ }
+}
diff --git a/Builder/ResourceMetricsApplicationBuilderExtensions.cs b/Builder/ResourceMetricsApplicationBuilderExtensions.cs
new file mode 100755
index 0000000..05ff153
--- /dev/null
+++ b/Builder/ResourceMetricsApplicationBuilderExtensions.cs
@@ -0,0 +1,74 @@
+using App.Metrics;
+using App.Metrics.AspNetCore.Resource;
+using App.Metrics.AspNetCore.Resource.Middleware;
+using App.Metrics.Extensions.DependencyInjection.Internal;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
+
+// ReSharper disable CheckNamespace
+namespace Microsoft.AspNetCore.Builder
+// ReSharper restore CheckNamespace
+{
+ ///
+ /// Extension methods for to add App Metrics Middleware to the request execution
+ /// pipeline which measure typical web metrics.
+ ///
+ public static class ResourceMetricsApplicationBuilderExtensions
+ {
+ ///
+ /// Adds Resource metrics to the request execution pipeline.
+ ///
+ /// The .
+ /// A reference to this instance after the operation has completed.
+ public static IApplicationBuilder UseAllResourceMetricsMiddleware(this IApplicationBuilder app)
+ {
+ EnsureRequiredServices(app);
+
+ app.UseResourceMetricsMiddleware();
+
+ return app;
+ }
+
+ ///
+ /// Adds Resource metrics to the request execution pipeline.
+ ///
+ /// The .
+ /// A reference to this instance after the operation has completed.
+ public static IApplicationBuilder UseResourceMetricsMiddleware(this IApplicationBuilder app)
+ {
+ EnsureRequiredServices(app);
+
+ var metricsOptions = app.ApplicationServices.GetRequiredService();
+ var ResourceMiddlwareOptionsAccessor = app.ApplicationServices.GetRequiredService>();
+
+ UseMetricsMiddleware(app, metricsOptions, ResourceMiddlwareOptionsAccessor);
+
+ return app;
+ }
+ private static void EnsureRequiredServices(IApplicationBuilder app)
+ {
+ // Verify if AddMetrics was done before calling UseMetricsAllMiddleware
+ // We use the MetricsMarkerService to make sure if all the services were added.
+ AppMetricsServicesHelper.ThrowIfMetricsNotRegistered(app.ApplicationServices);
+ }
+
+ private static bool ShouldUseMetricsEndpoint(IOptions ResourceMetricsOptionsAccessor,
+ MetricsOptions metricsOptions,
+ HttpContext context)
+ {
+ return metricsOptions.Enabled;
+ }
+
+ private static void UseMetricsMiddleware(
+ IApplicationBuilder app,
+ MetricsOptions metricsOptions,
+ IOptions ResourceMiddlwareOptionsAccessor)
+ {
+ app.UseWhen(
+ context => ShouldUseMetricsEndpoint(ResourceMiddlwareOptionsAccessor, metricsOptions, context),
+ appBuilder => { appBuilder.UseMiddleware(); });
+ }
+ }
+
+}
diff --git a/DefaultResourceMetricsStartupFilter.cs b/DefaultResourceMetricsStartupFilter.cs
new file mode 100755
index 0000000..d180142
--- /dev/null
+++ b/DefaultResourceMetricsStartupFilter.cs
@@ -0,0 +1,25 @@
+using Microsoft.AspNetCore.Builder;
+using Microsoft.AspNetCore.Hosting;
+using System;
+
+namespace App.Metrics.AspNetCore.Resource
+{
+ ///
+ /// Inserts the Resource metrics at the beginning of the pipeline.
+ ///
+ public class DefaultResourceMetricsStartupFilter : IStartupFilter
+ {
+ ///
+ public Action Configure(Action next)
+ {
+ return AddResourceMetricsMiddleware;
+
+ void AddResourceMetricsMiddleware(IApplicationBuilder builder)
+ {
+ builder.UseAllResourceMetricsMiddleware();
+
+ next(builder);
+ }
+ }
+ }
+}
diff --git a/DependencyInjection/MetricsAspNetCoreResourceMetricsMiddlewareServiceCollectionExtensions.cs b/DependencyInjection/MetricsAspNetCoreResourceMetricsMiddlewareServiceCollectionExtensions.cs
new file mode 100755
index 0000000..b9b8d7b
--- /dev/null
+++ b/DependencyInjection/MetricsAspNetCoreResourceMetricsMiddlewareServiceCollectionExtensions.cs
@@ -0,0 +1,186 @@
+using App.Metrics.AspNetCore.Resource;
+using App.Metrics.AspNetCore.Resource.Internal;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection.Extensions;
+using Microsoft.Extensions.Options;
+using System;
+
+// ReSharper disable CheckNamespace
+namespace Microsoft.Extensions.DependencyInjection
+// ReSharper restore CheckNamespace
+{
+ public static class MetricsAspNetCoreResourceMetricsMiddlewareServiceCollectionExtensions
+ {
+ private static readonly string DefaultConfigSection = nameof(ResourceMetricsOptions);
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(this IServiceCollection services)
+ {
+ AddResourceMetricsMiddlewareServices(services);
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ /// The from where to load .
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ IConfiguration configuration)
+ {
+ services.AddResourceMetricsMiddleware(configuration.GetSection(DefaultConfigSection));
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ /// The from where to load .
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ IConfigurationSection configuration)
+ {
+ services.AddResourceMetricsMiddleware();
+
+ services.Configure(configuration);
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ /// The from where to load .
+ ///
+ /// An to configure the provided .
+ ///
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ IConfiguration configuration,
+ Action setupAction)
+ {
+ services.AddResourceMetricsMiddleware(configuration.GetSection(DefaultConfigSection), setupAction);
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ /// The from where to load .
+ ///
+ /// An to configure the provided .
+ ///
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ IConfigurationSection configuration,
+ Action setupAction)
+ {
+ services.AddResourceMetricsMiddleware();
+
+ services.Configure(configuration);
+ services.Configure(setupAction);
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ ///
+ /// An to configure the provided .
+ ///
+ /// The from where to load .
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ Action setupAction,
+ IConfiguration configuration)
+ {
+ services.AddResourceMetricsMiddleware(setupAction, configuration.GetSection(DefaultConfigSection));
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ ///
+ /// An to configure the provided .
+ ///
+ /// The from where to load .
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ Action setupAction,
+ IConfigurationSection configuration)
+ {
+ services.AddResourceMetricsMiddleware();
+
+ services.Configure(setupAction);
+ services.Configure(configuration);
+
+ return services;
+ }
+
+ ///
+ /// Adds App Metrics AspNet Core Resource metrics middleware services to the specified .
+ ///
+ /// The to add services to.
+ ///
+ /// An to configure the provided .
+ ///
+ ///
+ /// An that can be used to further configure services.
+ ///
+ public static IServiceCollection AddResourceMetricsMiddleware(
+ this IServiceCollection services,
+ Action setupAction)
+ {
+ services.AddResourceMetricsMiddleware();
+
+ services.Configure(setupAction);
+
+ return services;
+ }
+
+ internal static void AddResourceMetricsMiddlewareServices(IServiceCollection services)
+ {
+ //
+ // Options
+ //
+ var descriptor = ServiceDescriptor.Singleton, ResourceMetricsMiddlewareOptionsSetup>();
+ services.TryAddEnumerable(descriptor);
+ }
+ }
+}
diff --git a/Internal/AppMetricsMiddlewareLoggerExtensions.cs b/Internal/AppMetricsMiddlewareLoggerExtensions.cs
new file mode 100755
index 0000000..83cbb41
--- /dev/null
+++ b/Internal/AppMetricsMiddlewareLoggerExtensions.cs
@@ -0,0 +1,35 @@
+using System.Diagnostics.CodeAnalysis;
+
+// ReSharper disable CheckNamespace
+namespace Microsoft.Extensions.Logging
+// ReSharper restore CheckNamespace
+{
+ [ExcludeFromCodeCoverage]
+ internal static class AppMetricsMiddlewareLoggerExtensions
+ {
+ public static void MiddlewareExecuted(this ILogger logger)
+ {
+ if (logger.IsEnabled(LogLevel.Trace))
+ {
+ logger.LogTrace(AppMetricsEventIds.Middleware.MiddlewareExecutedId, $"Executed App Metrics Middleware {typeof(TMiddleware).FullName}");
+ }
+ }
+
+ public static void MiddlewareExecuting(this ILogger logger)
+ {
+ if (logger.IsEnabled(LogLevel.Trace))
+ {
+ logger.LogTrace(AppMetricsEventIds.Middleware.MiddlewareExecutingId, $"Executing App Metrics Middleware {typeof(TMiddleware).FullName}");
+ }
+ }
+
+ private static class AppMetricsEventIds
+ {
+ public static class Middleware
+ {
+ public const int MiddlewareExecutedId = 1;
+ public const int MiddlewareExecutingId = 2;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Internal/ResourceMetricsMiddlewareOptionsSetup.cs b/Internal/ResourceMetricsMiddlewareOptionsSetup.cs
new file mode 100755
index 0000000..847d26f
--- /dev/null
+++ b/Internal/ResourceMetricsMiddlewareOptionsSetup.cs
@@ -0,0 +1,15 @@
+using Microsoft.Extensions.Options;
+
+namespace App.Metrics.AspNetCore.Resource.Internal
+{
+ ///
+ /// Sets up default Resource metrics middleware options for .
+ ///
+ public class ResourceMetricsMiddlewareOptionsSetup : IConfigureOptions
+ {
+ ///
+ public void Configure(ResourceMetricsOptions options)
+ {
+ }
+ }
+}
diff --git a/Metrics/ResourceMetrics.cs b/Metrics/ResourceMetrics.cs
new file mode 100755
index 0000000..9742b60
--- /dev/null
+++ b/Metrics/ResourceMetrics.cs
@@ -0,0 +1,108 @@
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace App.Metrics.AspNetCore.Resource.Metrics
+{
+ public class ResourceMetrics
+ {
+ private volatile Boolean running;
+
+ public ResourceMetrics()
+ {
+ running = true;
+ CheckGCTime();
+ }
+
+ public long MaxWorkingSet { get { return Process.GetCurrentProcess().MaxWorkingSet.ToInt64(); } }
+
+ public long NonpagedSystemMemorySize64 { get { return Process.GetCurrentProcess().NonpagedSystemMemorySize64; } }
+
+ public long PagedMemorySize64 { get { return Process.GetCurrentProcess().PagedMemorySize64; } }
+
+ public long PeakPagedMemorySize64 { get { return Process.GetCurrentProcess().PeakPagedMemorySize64; } }
+
+ public long PeakWorkingSet64 { get { return Process.GetCurrentProcess().PeakWorkingSet64; } }
+
+ public double TotalProcessorTime { get { return Process.GetCurrentProcess().TotalProcessorTime.TotalMilliseconds; } }
+
+ public double UserProcessorTime { get { return Process.GetCurrentProcess().UserProcessorTime.TotalMilliseconds; } }
+
+ public long VirtualMemorySize64 { get { return Process.GetCurrentProcess().VirtualMemorySize64; } }
+
+ public long WorkingSet64 { get { return Process.GetCurrentProcess().WorkingSet64; } }
+
+ public int ThreadsCount { get { return Process.GetCurrentProcess().Threads.Count; } }
+
+ public int GCCollectionCount { get {
+ int total = 0;
+ for (var i = 0; i < GC.MaxGeneration; i++)
+ {
+ total += GC.CollectionCount(i);
+ }
+ return total;
+ }
+ }
+
+ public long GCTotalMemory { get { return GC.GetTotalMemory(false); } }
+
+ private long _lastGCTime;
+
+ public long LastGCTime { get
+ {
+ Interlocked.Increment(ref _lastGCTime);
+ try
+ {
+ return _lastGCTime;
+ }
+ finally
+ {
+ Interlocked.Decrement(ref _lastGCTime);
+ }
+ }
+ }
+
+ private void CheckGCTime()
+ {
+ var pollGC = new Action(() =>
+ {
+ // Register for a notification.
+ GC.RegisterForFullGCNotification(10, 10);
+
+ Stopwatch gcTimer = new Stopwatch();
+
+ while (running)
+ {
+ // Check for a notification of an approaching collection.
+ GCNotificationStatus s = GC.WaitForFullGCApproach();
+ if (s == GCNotificationStatus.Succeeded)
+ {
+ // GC is about to start.
+ gcTimer.Restart();
+ }
+
+ // Check for a notification of a completed collection.
+ s = GC.WaitForFullGCComplete();
+ if (s == GCNotificationStatus.Succeeded)
+ {
+ Interlocked.Increment(ref _lastGCTime);
+ try
+ {
+ _lastGCTime = gcTimer.ElapsedMilliseconds;
+ }
+ finally
+ {
+ Interlocked.Decrement(ref _lastGCTime);
+ }
+ }
+
+ Thread.Sleep(500);
+ }
+ // Finishing monitoring GC.
+ GC.CancelFullGCNotification();
+ });
+ Task.Run(pollGC);
+ }
+ }
+}
diff --git a/Metrics/ResourceMetricsRegistry.cs b/Metrics/ResourceMetricsRegistry.cs
new file mode 100755
index 0000000..bfd1b51
--- /dev/null
+++ b/Metrics/ResourceMetricsRegistry.cs
@@ -0,0 +1,86 @@
+using App.Metrics;
+using App.Metrics.Gauge;
+
+namespace App.Metrics.AspNetCore.Resource.Metrics
+{
+ public static class ResourceMetricsRegistry
+ {
+ public static GaugeOptions MaxWorkingSetGauge => new GaugeOptions
+ {
+ Name = "Process maximum physical memory set",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions NonpagedSystemMemorySize64Gauge => new GaugeOptions
+ {
+ Name = "Process nonpaged system memory size",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions PagedMemorySize64Gauge => new GaugeOptions
+ {
+ Name = "Process paged memory size",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions PeakPagedMemorySize64Gauge => new GaugeOptions
+ {
+ Name = "Process peak paged memory size",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions PeakWorkingSet64Gauge => new GaugeOptions
+ {
+ Name = "Process peak working set",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions TotalProcessorTimeGauge => new GaugeOptions
+ {
+ Name = "Process total processor time",
+ MeasurementUnit = Unit.Custom("ms")
+ };
+
+ public static GaugeOptions UserProcessorTimeGauge => new GaugeOptions
+ {
+ Name = "Process user processor time",
+ MeasurementUnit = Unit.Custom("ms")
+ };
+
+ public static GaugeOptions VirtualMemorySize64Gauge => new GaugeOptions
+ {
+ Name = "Process virtual memory size",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions WorkingSet64Gauge => new GaugeOptions
+ {
+ Name = "Process working set",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions ThreadsCountGauge => new GaugeOptions
+ {
+ Name = "Process threads count",
+ MeasurementUnit = Unit.Threads
+ };
+
+ public static GaugeOptions GCCollectionCountGauge => new GaugeOptions
+ {
+ Name = "GC total collection count",
+ MeasurementUnit = Unit.Custom("#")
+ };
+
+ public static GaugeOptions GCTotalMemoryGauge => new GaugeOptions
+ {
+ Name = "GC total memory",
+ MeasurementUnit = Unit.Bytes
+ };
+
+ public static GaugeOptions LastGCTimeGauge => new GaugeOptions
+ {
+ Name = "GC last GC time",
+ MeasurementUnit = Unit.Custom("ms")
+ };
+ }
+}
diff --git a/Middleware/ResourceMiddleware.cs b/Middleware/ResourceMiddleware.cs
new file mode 100755
index 0000000..9f9f58c
--- /dev/null
+++ b/Middleware/ResourceMiddleware.cs
@@ -0,0 +1,86 @@
+using App.Metrics.AspNetCore.Resource.Metrics;
+using App.Metrics.Gauge;
+using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using System.Threading.Tasks;
+
+namespace App.Metrics.AspNetCore.Resource.Middleware
+{
+ // ReSharper disable ClassNeverInstantiated.Global
+ public class ResourceMiddleware
+ // ReSharper restore ClassNeverInstantiated.Global
+ {
+ private const string ResourceItemsKey = "__App.Metrics.Resource__";
+ private readonly ILogger _logger;
+ private readonly RequestDelegate _next;
+ private IMetrics _metrics;
+
+ private IGauge _maxWorkingSet;
+ private IGauge _pagedMemorySize64;
+ private IGauge _nonpagedSystemMemorySize64;
+ private IGauge _peakPagedMemorySize64;
+ private IGauge _peakWorkingSet64;
+ private IGauge _totalProcessorTime;
+ private IGauge _userProcessorTime;
+ private IGauge _virtualMemorySize64;
+ private IGauge _workingSet64;
+ private IGauge _threadsCount;
+ private IGauge _gcCollectionCount;
+ private IGauge _gcTotalMemory;
+ private IGauge _lastGCTime;
+
+ private ResourceMetrics _ResourceMetrics = new ResourceMetrics();
+
+ public ResourceMiddleware(
+ RequestDelegate next,
+ ILogger logger,
+ IOptions ResourceMetricsOptionsAccessor,
+ IMetrics metrics)
+ {
+ _logger = logger;
+ _next = next;
+ _metrics = metrics;
+
+ // Setup the metrics.
+ _maxWorkingSet = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.MaxWorkingSetGauge);
+ _pagedMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PagedMemorySize64Gauge);
+ _nonpagedSystemMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.NonpagedSystemMemorySize64Gauge);
+ _peakPagedMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PeakPagedMemorySize64Gauge);
+ _peakWorkingSet64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.PeakWorkingSet64Gauge);
+ _totalProcessorTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.TotalProcessorTimeGauge);
+ _userProcessorTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.UserProcessorTimeGauge);
+ _virtualMemorySize64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.VirtualMemorySize64Gauge);
+ _workingSet64 = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.WorkingSet64Gauge);
+ _threadsCount = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.ThreadsCountGauge);
+ _gcCollectionCount = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.GCCollectionCountGauge);
+ _gcTotalMemory = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.GCTotalMemoryGauge);
+ _lastGCTime = _metrics.Provider.Gauge.Instance(ResourceMetricsRegistry.LastGCTimeGauge);
+ }
+
+ // ReSharper disable UnusedMember.Global
+ public async Task Invoke(HttpContext context)
+ // ReSharper restore UnusedMember.Global
+ {
+ _logger.MiddlewareExecuting();
+
+ _maxWorkingSet.SetValue(_ResourceMetrics.MaxWorkingSet);
+ _pagedMemorySize64.SetValue(_ResourceMetrics.PagedMemorySize64);
+ _nonpagedSystemMemorySize64.SetValue(_ResourceMetrics.NonpagedSystemMemorySize64);
+ _peakPagedMemorySize64.SetValue(_ResourceMetrics.PeakPagedMemorySize64);
+ _peakWorkingSet64.SetValue(_ResourceMetrics.PeakWorkingSet64);
+ _totalProcessorTime.SetValue(_ResourceMetrics.TotalProcessorTime);
+ _userProcessorTime.SetValue(_ResourceMetrics.UserProcessorTime);
+ _virtualMemorySize64.SetValue(_ResourceMetrics.VirtualMemorySize64);
+ _workingSet64.SetValue(_ResourceMetrics.WorkingSet64);
+ _threadsCount.SetValue(_ResourceMetrics.ThreadsCount);
+ _gcCollectionCount.SetValue(_ResourceMetrics.GCCollectionCount);
+ _gcTotalMemory.SetValue(_ResourceMetrics.GCTotalMemory);
+ _lastGCTime.SetValue(_ResourceMetrics.LastGCTime);
+
+ await _next(context);
+
+ _logger.MiddlewareExecuted();
+ }
+ }
+}
diff --git a/ResourceMetrics.csproj b/ResourceMetrics.csproj
new file mode 100755
index 0000000..5b3ba8c
--- /dev/null
+++ b/ResourceMetrics.csproj
@@ -0,0 +1,11 @@
+
+
+
+ netcoreapp2.0
+
+
+
+
+
+
+
diff --git a/ResourceMetricsOptions.cs b/ResourceMetricsOptions.cs
new file mode 100755
index 0000000..89e1780
--- /dev/null
+++ b/ResourceMetricsOptions.cs
@@ -0,0 +1,12 @@
+namespace App.Metrics.AspNetCore.Resource
+{
+ ///
+ /// Provides programmatic configuration for Resource metrics middleware in the App Metrics framework.
+ ///
+ public class ResourceMetricsOptions
+ {
+ public ResourceMetricsOptions()
+ {
+ }
+ }
+}