-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test meter to stress app with meter and instrument tags (#5046)
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Diagnostics; | ||
using System.Diagnostics.Metrics; | ||
|
||
namespace Stress.ApiService; | ||
|
||
public class TestMetrics : IDisposable | ||
{ | ||
public const string MeterName = "TestMeter"; | ||
|
||
private readonly Meter _meter; | ||
private readonly Counter<int> _counter; | ||
|
||
public TestMetrics() | ||
{ | ||
_meter = new Meter(MeterName, "1.0.0", new[] | ||
{ | ||
new KeyValuePair<string, object?>("meter-tag", Guid.NewGuid().ToString()) | ||
}); | ||
|
||
_counter = _meter.CreateCounter<int>("test-counter", unit: null, description: null, tags: new[] | ||
{ | ||
new KeyValuePair<string, object?>("instrument-tag", Guid.NewGuid().ToString()) | ||
}); | ||
} | ||
|
||
public void IncrementCounter(int value, in TagList tags) | ||
{ | ||
_counter.Add(value, in tags); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_meter.Dispose(); | ||
} | ||
} |