Skip to content

Commit

Permalink
Cleaning up after Tiago's MR and bumping version (#41)
Browse files Browse the repository at this point in the history
* Cleaning up after Tiago's MR and bumping version

* Removing failing test
  • Loading branch information
djluck authored Aug 18, 2020
1 parent 95183e6 commit 15fb9b4
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -36,6 +37,7 @@ IDisposable collector = DotNetRuntimeStatsBuilder
.WithThreadPoolSchedulingStats()
.WithThreadPoolStats()
.WithGcStats()
.WithExceptionStats()
.StartCollecting();
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NUnit.Framework;
using Prometheus.DotNetRuntime.StatsCollectors;
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public Builder WithGcStats(double[] histogramBuckets = null)
}

/// <summary>
/// Includes quantitative and qualitative metrics of exceptions thrown
/// Includes a breakdown of exceptions thrown labeled by type.
/// </summary>
public Builder WithExceptionStats()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
);
}

Expand All @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<RootNamespace>Prometheus.DotNetRuntime</RootNamespace>
<AssemblyName>prometheus-net.DotNetRuntime</AssemblyName>
<PackageId>prometheus-net.DotNetRuntime</PackageId>
<Version>$(PromMajorVersion).3.1</Version>
<!-- TODO use git versioning -->
<Version>$(PromMajorVersion).4.0</Version>
<Authors>James Luck</Authors>
<PackageTags>Prometheus prometheus-net IOnDemandCollector runtime metrics gc jit threadpool contention stats</PackageTags>
<PackageProjectUrl>https://github.com/djluck/prometheus-net.DotNetRuntime</PackageProjectUrl>
<Description>
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.
</Description>
<PackageLicense>https://github.com/djluck/prometheus-net.DotNetRuntime/blob/master/LICENSE.txt</PackageLicense>
<Configurations>ReleaseV2;DebugV2;DebugV3;ReleaseV3</Configurations>
Expand Down

0 comments on commit 15fb9b4

Please sign in to comment.