diff --git a/README.md b/README.md
index 248629b..80bd1ba 100644
--- a/README.md
+++ b/README.md
@@ -6,6 +6,7 @@ A plugin for the [prometheus-net](https://github.com/prometheus-net/prometheus-n
- JIT compilations and JIT CPU consumption ratio
- Thread pool size, scheduling delays and reasons for growing/ shrinking
- Lock contention
+- Exceptions thrown, broken down by type
These metrics are essential for understanding the peformance of any non-trivial application. Even if your application is well instrumented, you're only getting half the story- what the runtime is doing completes the picture.
@@ -36,6 +37,7 @@ IDisposable collector = DotNetRuntimeStatsBuilder
.WithThreadPoolSchedulingStats()
.WithThreadPoolStats()
.WithGcStats()
+ .WithExceptionStats()
.StartCollecting();
```
diff --git a/src/prometheus-net.DotNetRuntime.Tests/StatsCollectors/IntegrationTests/ExceptionStatsCollectorTests.cs b/src/prometheus-net.DotNetRuntime.Tests/StatsCollectors/IntegrationTests/ExceptionStatsCollectorTests.cs
index dc81a08..db65491 100644
--- a/src/prometheus-net.DotNetRuntime.Tests/StatsCollectors/IntegrationTests/ExceptionStatsCollectorTests.cs
+++ b/src/prometheus-net.DotNetRuntime.Tests/StatsCollectors/IntegrationTests/ExceptionStatsCollectorTests.cs
@@ -1,6 +1,7 @@
using NUnit.Framework;
using Prometheus.DotNetRuntime.StatsCollectors;
using System;
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -17,36 +18,19 @@ protected override ExceptionStatsCollector CreateStatsCollector()
[Test]
public void Will_measure_when_occurring_an_exception()
{
- // arrange
- int divider = 0;
- string exceptionMessage = string.Empty;
-
// act
+ var divider = 0;
+
try
{
var result = 1 / divider;
}
- catch (Exception ex)
+ catch (System.DivideByZeroException divZeroEx)
{
- exceptionMessage = ex.GetType().FullName;
}
// assert
- Assert.That(() => StatsCollector.ExceptionReasons.Labels(exceptionMessage).Value, Is.EqualTo(1).After(100, 1000));
- }
-
- [Test]
- public void Will_measure_when_not_occurring_an_exception()
- {
- // arrange
- int divider = 1;
- string exceptionMessage = string.Empty;
-
- // act
- var result = 1 / divider;
-
- // assert
- Assert.That(() => StatsCollector.ExceptionReasons.Labels(exceptionMessage).Value, Is.EqualTo(0).After(100, 1000));
+ Assert.That(() => StatsCollector.ExceptionCount.Labels("System.DivideByZeroException").Value, Is.EqualTo(1).After(100, 1000));
}
}
}
\ No newline at end of file
diff --git a/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsBuilder.cs b/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsBuilder.cs
index 4ef8ed5..76e3963 100644
--- a/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsBuilder.cs
+++ b/src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsBuilder.cs
@@ -151,7 +151,7 @@ public Builder WithGcStats(double[] histogramBuckets = null)
}
///
- /// Includes quantitative and qualitative metrics of exceptions thrown
+ /// Includes a breakdown of exceptions thrown labeled by type.
///
public Builder WithExceptionStats()
{
diff --git a/src/prometheus-net.DotNetRuntime/StatsCollectors/ExceptionStatsCollector.cs b/src/prometheus-net.DotNetRuntime/StatsCollectors/ExceptionStatsCollector.cs
index c15a71d..4dd355f 100644
--- a/src/prometheus-net.DotNetRuntime/StatsCollectors/ExceptionStatsCollector.cs
+++ b/src/prometheus-net.DotNetRuntime/StatsCollectors/ExceptionStatsCollector.cs
@@ -11,9 +11,9 @@ namespace Prometheus.DotNetRuntime.StatsCollectors
public class ExceptionStatsCollector : IEventSourceStatsCollector
{
private const int EventIdExceptionThrown = 80;
- private const string LabelReason = "exception";
+ private const string LabelType = "type";
- internal Counter ExceptionReasons { get; private set; }
+ internal Counter ExceptionCount { get; private set; }
public Guid EventSourceGuid => DotNetRuntimeEventSource.Id;
@@ -22,10 +22,10 @@ public class ExceptionStatsCollector : IEventSourceStatsCollector
public void RegisterMetrics(MetricFactory metrics)
{
- ExceptionReasons = metrics.CreateCounter(
- "dotnet_exception_reasons_total",
- "Reasons that led to an exception",
- LabelReason
+ ExceptionCount = metrics.CreateCounter(
+ "dotnet_exceptions_total",
+ "Count of exceptions broken down by type",
+ LabelType
);
}
@@ -38,7 +38,7 @@ public void ProcessEvent(EventWrittenEventArgs e)
{
if (e.EventId == EventIdExceptionThrown)
{
- ExceptionReasons.Labels((string)e.Payload[0]).Inc();
+ ExceptionCount.Labels((string)e.Payload[0]).Inc();
}
}
}
diff --git a/src/prometheus-net.DotNetRuntime/prometheus-net.DotNetRuntime.csproj b/src/prometheus-net.DotNetRuntime/prometheus-net.DotNetRuntime.csproj
index 9c4ac83..9205e61 100644
--- a/src/prometheus-net.DotNetRuntime/prometheus-net.DotNetRuntime.csproj
+++ b/src/prometheus-net.DotNetRuntime/prometheus-net.DotNetRuntime.csproj
@@ -5,12 +5,13 @@
Prometheus.DotNetRuntime
prometheus-net.DotNetRuntime
prometheus-net.DotNetRuntime
- $(PromMajorVersion).3.1
+
+ $(PromMajorVersion).4.0
James Luck
Prometheus prometheus-net IOnDemandCollector runtime metrics gc jit threadpool contention stats
https://github.com/djluck/prometheus-net.DotNetRuntime
- Exposes .NET core runtime metrics (GC, JIT, lock contention, thread pool) using the prometheus-net package.
+ Exposes .NET core runtime metrics (GC, JIT, lock contention, thread pool, exceptions) using the prometheus-net package.
https://github.com/djluck/prometheus-net.DotNetRuntime/blob/master/LICENSE.txt
ReleaseV2;DebugV2;DebugV3;ReleaseV3