Skip to content

Commit 15fb9b4

Browse files
authored
Cleaning up after Tiago's MR and bumping version (#41)
* Cleaning up after Tiago's MR and bumping version * Removing failing test
1 parent 95183e6 commit 15fb9b4

File tree

5 files changed

+18
-31
lines changed

5 files changed

+18
-31
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A plugin for the [prometheus-net](https://github.com/prometheus-net/prometheus-n
66
- JIT compilations and JIT CPU consumption ratio
77
- Thread pool size, scheduling delays and reasons for growing/ shrinking
88
- Lock contention
9+
- Exceptions thrown, broken down by type
910

1011
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.
1112

@@ -36,6 +37,7 @@ IDisposable collector = DotNetRuntimeStatsBuilder
3637
.WithThreadPoolSchedulingStats()
3738
.WithThreadPoolStats()
3839
.WithGcStats()
40+
.WithExceptionStats()
3941
.StartCollecting();
4042
```
4143

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NUnit.Framework;
22
using Prometheus.DotNetRuntime.StatsCollectors;
33
using System;
4+
using System.Linq;
45
using System.Threading;
56
using System.Threading.Tasks;
67

@@ -17,36 +18,19 @@ protected override ExceptionStatsCollector CreateStatsCollector()
1718
[Test]
1819
public void Will_measure_when_occurring_an_exception()
1920
{
20-
// arrange
21-
int divider = 0;
22-
string exceptionMessage = string.Empty;
23-
2421
// act
22+
var divider = 0;
23+
2524
try
2625
{
2726
var result = 1 / divider;
2827
}
29-
catch (Exception ex)
28+
catch (System.DivideByZeroException divZeroEx)
3029
{
31-
exceptionMessage = ex.GetType().FullName;
3230
}
3331

3432
// assert
35-
Assert.That(() => StatsCollector.ExceptionReasons.Labels(exceptionMessage).Value, Is.EqualTo(1).After(100, 1000));
36-
}
37-
38-
[Test]
39-
public void Will_measure_when_not_occurring_an_exception()
40-
{
41-
// arrange
42-
int divider = 1;
43-
string exceptionMessage = string.Empty;
44-
45-
// act
46-
var result = 1 / divider;
47-
48-
// assert
49-
Assert.That(() => StatsCollector.ExceptionReasons.Labels(exceptionMessage).Value, Is.EqualTo(0).After(100, 1000));
33+
Assert.That(() => StatsCollector.ExceptionCount.Labels("System.DivideByZeroException").Value, Is.EqualTo(1).After(100, 1000));
5034
}
5135
}
5236
}

src/prometheus-net.DotNetRuntime/DotNetRuntimeStatsBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public Builder WithGcStats(double[] histogramBuckets = null)
151151
}
152152

153153
/// <summary>
154-
/// Includes quantitative and qualitative metrics of exceptions thrown
154+
/// Includes a breakdown of exceptions thrown labeled by type.
155155
/// </summary>
156156
public Builder WithExceptionStats()
157157
{

src/prometheus-net.DotNetRuntime/StatsCollectors/ExceptionStatsCollector.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ namespace Prometheus.DotNetRuntime.StatsCollectors
1111
public class ExceptionStatsCollector : IEventSourceStatsCollector
1212
{
1313
private const int EventIdExceptionThrown = 80;
14-
private const string LabelReason = "exception";
14+
private const string LabelType = "type";
1515

16-
internal Counter ExceptionReasons { get; private set; }
16+
internal Counter ExceptionCount { get; private set; }
1717

1818
public Guid EventSourceGuid => DotNetRuntimeEventSource.Id;
1919

@@ -22,10 +22,10 @@ public class ExceptionStatsCollector : IEventSourceStatsCollector
2222

2323
public void RegisterMetrics(MetricFactory metrics)
2424
{
25-
ExceptionReasons = metrics.CreateCounter(
26-
"dotnet_exception_reasons_total",
27-
"Reasons that led to an exception",
28-
LabelReason
25+
ExceptionCount = metrics.CreateCounter(
26+
"dotnet_exceptions_total",
27+
"Count of exceptions broken down by type",
28+
LabelType
2929
);
3030
}
3131

@@ -38,7 +38,7 @@ public void ProcessEvent(EventWrittenEventArgs e)
3838
{
3939
if (e.EventId == EventIdExceptionThrown)
4040
{
41-
ExceptionReasons.Labels((string)e.Payload[0]).Inc();
41+
ExceptionCount.Labels((string)e.Payload[0]).Inc();
4242
}
4343
}
4444
}

src/prometheus-net.DotNetRuntime/prometheus-net.DotNetRuntime.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
<RootNamespace>Prometheus.DotNetRuntime</RootNamespace>
66
<AssemblyName>prometheus-net.DotNetRuntime</AssemblyName>
77
<PackageId>prometheus-net.DotNetRuntime</PackageId>
8-
<Version>$(PromMajorVersion).3.1</Version>
8+
<!-- TODO use git versioning -->
9+
<Version>$(PromMajorVersion).4.0</Version>
910
<Authors>James Luck</Authors>
1011
<PackageTags>Prometheus prometheus-net IOnDemandCollector runtime metrics gc jit threadpool contention stats</PackageTags>
1112
<PackageProjectUrl>https://github.com/djluck/prometheus-net.DotNetRuntime</PackageProjectUrl>
1213
<Description>
13-
Exposes .NET core runtime metrics (GC, JIT, lock contention, thread pool) using the prometheus-net package.
14+
Exposes .NET core runtime metrics (GC, JIT, lock contention, thread pool, exceptions) using the prometheus-net package.
1415
</Description>
1516
<PackageLicense>https://github.com/djluck/prometheus-net.DotNetRuntime/blob/master/LICENSE.txt</PackageLicense>
1617
<Configurations>ReleaseV2;DebugV2;DebugV3;ReleaseV3</Configurations>

0 commit comments

Comments
 (0)