Last active
October 22, 2021 00:39
-
-
Save itn3000/9001546f1a0a9bcd53b7bc0ae4184bbd to your computer and use it in GitHub Desktop.
MetricEventSource and its parameters test
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
using System.Diagnostics.Tracing; | |
using System.Text.Json; | |
using var m = new System.Diagnostics.Metrics.Meter("m1"); | |
using var evlistener = new MyEventListener(); | |
// var c1 = m.CreateCounter<int>("c1"); | |
var h1 = m.CreateHistogram<int>("h1"); | |
Console.WriteLine($"1"); | |
h1.Record(1, new KeyValuePair<string, object?>("htag1", 1)); | |
Console.WriteLine($"2"); | |
h1.Record(1, new KeyValuePair<string, object?>("htag1", 2)); | |
Console.WriteLine($"3"); | |
h1.Record(1, new KeyValuePair<string, object?>("htag1", 3)); | |
Console.WriteLine($"4"); | |
h1.Record(1, new KeyValuePair<string, object?>("htag1", 3)); | |
Console.WriteLine($"5"); | |
class MyEventListener : EventListener | |
{ | |
protected override void OnEventSourceCreated(EventSource ev) | |
{ | |
if (ev.Name == "System.Diagnostics.Metrics") | |
{ | |
var args = new Dictionary<string, string>() | |
{ | |
{"Metrics", "m1"}, | |
{"RefreshInterval", "10"}, | |
{"MaxTimeSeries", "3"}, | |
{"MaxHistograms", "2"}, | |
}; | |
this.EnableEvents(ev, EventLevel.LogAlways, (EventKeywords)0xffffffff, args); | |
} | |
} | |
protected override void OnEventWritten(EventWrittenEventArgs evarg) | |
{ | |
var jsonstr = JsonSerializer.Serialize(new | |
{ | |
name = evarg.EventName, | |
keywords = evarg.Keywords, | |
payload = evarg.PayloadNames.Zip(evarg.Payload).ToDictionary(x => x.First, x => x.Second) | |
}); | |
Console.WriteLine(jsonstr); | |
} | |
} |
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
{"name":"Message","keywords":263882790666241,"payload":{"Message":"New session started. SessionId auto-generated: 9039b8e4-b93e-431c-a851-506d19ec1893"}} | |
{"name":"Message","keywords":263882790666241,"payload":{"Message":"RefreshInterval argument received: 10"}} | |
{"name":"Message","keywords":263882790666241,"payload":{"Message":"MaxTimeSeries argument received: 3"}} | |
{"name":"Message","keywords":263882790666241,"payload":{"Message":"MaxHistograms argument received: 2"}} | |
{"name":"Message","keywords":263882790666241,"payload":{"Message":"Metrics argument received: m1"}} | |
{"name":"Message","keywords":263882790666241,"payload":{"Message":"Parsed metric: {spec}"}} | |
{"name":"InitialInstrumentEnumerationComplete","keywords":263882790666246,"payload":{"sessionId":"9039b8e4-b93e-431c-a851-506d19ec1893"}} | |
{"name":"InstrumentPublished","keywords":263882790666244,"payload":{"sessionId":"9039b8e4-b93e-431c-a851-506d19ec1893","meterName":"m1","meterVersion":"","instrumentName":"h1","instrumentType":"Histogram\u00601","unit":"","description":""}} | |
{"name":"BeginInstrumentReporting","keywords":263882790666242,"payload":{"sessionId":"9039b8e4-b93e-431c-a851-506d19ec1893","meterName":"m1","meterVersion":"","instrumentName":"h1","instrumentType":"Histogram\u00601","unit":"","description":""}} | |
1 | |
2 | |
3 | |
{"name":"HistogramLimitReached","keywords":263882790666242,"payload":{"sessionId":"9039b8e4-b93e-431c-a851-506d19ec1893"}} | |
4 | |
{"name":"TimeSeriesLimitReached","keywords":263882790666242,"payload":{"sessionId":"9039b8e4-b93e-431c-a851-506d19ec1893"}} | |
5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
htag1=0
,htag1=1
,htag1=2
,htag1=3