-
Notifications
You must be signed in to change notification settings - Fork 316
Supporting Event counter in .Net core #719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cb00f28
Add event counters
DavoudEshtehari a56c1c0
Merge remote-tracking branch 'UpStream/master' into EventCounter
DavoudEshtehari ada285a
Add support netstandard 2.1 & fix the conflict in event source
DavoudEshtehari 0df6a55
Support new event source types & add the test unit
DavoudEshtehari 74bb4da
Remove supporting obsolete types
DavoudEshtehari 33b6fe5
Merge remote-tracking branch 'UpStream/master' into EventCounter
DavoudEshtehari 7c2be9e
fix unit test
DavoudEshtehari 377fb33
Add snippet sample code
DavoudEshtehari fceefd9
Address comments
DavoudEshtehari 638827f
Merge remote-tracking branch 'UpStream/master' into EventCounter
7ec5012
Fix minor typo (#3)
karinazhou 6e264bc
Reformatting counter methods
karinazhou 7a52156
Unit tests for Microsoft.Data.SqlClient.SqlClientEventSource (#2)
winseros 190e304
Add more tests (#5)
karinazhou 86e9541
Merge remote-tracking branch 'UpStream/master' into EventCounter
a915aeb
Address comments
94bd2a2
Merge remote-tracking branch 'UpStream/master' into EventCounter
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,62 @@ | ||
| // <Snippet1> | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics.Tracing; | ||
| using System.Linq; | ||
|
|
||
| // This listener class will listen for events from the SqlClientEventSource class. | ||
| // SqlClientEventSource is an implementation of the EventSource class which gives | ||
| // it the ability to create events. | ||
| public class EventCounterListener : EventListener | ||
| { | ||
| protected override void OnEventSourceCreated(EventSource eventSource) | ||
| { | ||
| // Only enable events from SqlClientEventSource. | ||
| if (eventSource.Name.Equals("Microsoft.Data.SqlClient.EventSource")) | ||
| { | ||
| var options = new Dictionary<string, string>(); | ||
| // define time interval 1 second | ||
| // without defining this parameter event counters will not enabled | ||
| options.Add("EventCounterIntervalSec", "1"); | ||
| // enable for the None keyword | ||
| EnableEvents(eventSource, EventLevel.Informational, EventKeywords.None, options); | ||
| } | ||
| } | ||
|
|
||
| // This callback runs whenever an event is written by SqlClientEventSource. | ||
| // Event data is accessed through the EventWrittenEventArgs parameter. | ||
| protected override void OnEventWritten(EventWrittenEventArgs eventData) | ||
| { | ||
| if (eventData.Payload.FirstOrDefault(p => p is IDictionary<string, object> x && x.ContainsKey("Name")) is IDictionary<string, object> counters) | ||
| { | ||
| if (counters.TryGetValue("DisplayName", out object name) && name is string cntName | ||
| && counters.TryGetValue("Mean", out object value) && value is double cntValue) | ||
| { | ||
| // print event counter's name and mean value | ||
| Console.WriteLine($"{cntName}\t\t{cntValue}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class Program | ||
| { | ||
| static void Main(string[] args) | ||
| { | ||
| // Create a new event listener | ||
| using (var listener = new EventCounterListener()) | ||
| { | ||
| string connectionString = "Data Source=localhost; Integrated Security=true"; | ||
|
|
||
| for (int i = 0; i < 50; i++) | ||
| { | ||
| // Open a connection | ||
| SqlConnection cnn = new SqlConnection(connectionString); | ||
| cnn.Open(); | ||
| // wait for sampling interval happens | ||
| System.Threading.Thread.Sleep(500); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // </Snippet1> |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.