https://github.com/alastairwyse/applicationmetrics.metricloggers.sqlserver
An ApplicationMetrics metric logger which writes metric and instrumentation events to a Microsoft SQL Server database
https://github.com/alastairwyse/applicationmetrics.metricloggers.sqlserver
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (8.7%) to scientific vocabulary
Repository
An ApplicationMetrics metric logger which writes metric and instrumentation events to a Microsoft SQL Server database
Basic Info
- Host: GitHub
- Owner: alastairwyse
- License: apache-2.0
- Language: C#
- Default Branch: master
- Size: 132 KB
Statistics
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Metadata Files
README.md
ApplicationMetrics.MetricLoggers.SqlServer
An implementation of an ApplicationMetrics metric logger which writes metrics and instrumentation information to a Microsoft SQL Server database.
Setup
1) Create/Update the Database and Objects
For new installations, run the CreateDatabase.sql script against a SQL Server instance to create the 'ApplicationMetrics' database and objects to store the metrics. The 'CREATE DATABASE' statement needs to be run separately, before the remainder of the script. The name of the database can be changed via a find/replace operation on the script (replacing all instances of 'ApplicationMetrics' with a desired database name). Alternatively, the objects can be created in an existing database. In any case, the 'InitialCatalog' component of the connection string passed to the SqlServerMetricLogger class should be set to the matching database name.
For existing installations, the database schema can be upgraded to the latest version by running the UpdateDatabase.sql script against the existing 'ApplicationMetrics' database. However if upgrading through multiple intermediate versions to get to the latest, the UpdateDatabase.sql scripts for the intermediate versions must also be run in sequence.
2) Setup and Call the SqlServerMetricLogger Class
The code below demonstrates the setup and use case (with fake metrics logged) of the SqlServerMetricLogger class...
````C# var connStringBuilder = new SqlConnectionStringBuilder(); connStringBuilder.DataSource = "127.0.0.1"; connStringBuilder.InitialCatalog = "ApplicationMetrics"; connStringBuilder.Encrypt = false; connStringBuilder.Authentication = SqlAuthenticationMethod.SqlPassword; connStringBuilder.UserID = "sa"; connStringBuilder.Password = "password";
using (var bufferProcessor = new SizeLimitedBufferProcessor(5)) using (var metricLogger = new SqlServerMetricLogger("DefaultCategory", connStringBuilder.ToString(), 20, 10, 0, bufferProcessor, IntervalMetricBaseTimeUnit.Millisecond, true)) { metricLogger.Start();
Guid beginId = metricLogger.Begin(new MessageSendTime());
Thread.Sleep(20);
metricLogger.Increment(new MessageSent());
metricLogger.Add(new MessageSize(), 2661);
metricLogger.End(beginId, new MessageSendTime());
metricLogger.Stop();
} ````
SqlServerMetricLogger accepts the following constructor parameters...
| Parameter Name | Description |
| category | The category to log the metrics under. The ability to specify a category allows instances of the same metrics to be logged, but also distinguished from each other... e.g. in the case of a multi-threaded application, the category could be set to reflect an individual thread. |
| connectionString | The connection string to connect to SQL Server. |
| retryCount | The number of times an operation against the database should be retried in the case of execution failure. |
| retryInterval | The time in seconds between operation retries. |
| operationTimeout | The timeout in seconds before terminating an operation against the SQL Server database. A value of 0 indicates no limit. |
| bufferProcessingStrategy | An object implementing IBufferProcessingStrategy which decides when the buffers holding logged metric events should be flushed (and be written to SQL Server). |
| intervalMetricBaseTimeUnit | The base time unit to use to log interval metrics. |
| intervalMetricChecking | Specifies whether an exception should be thrown if the correct order of interval metric logging is not followed (e.g. End() method called before Begin()). This parameter is ignored when the the SqlServerMetricLogger operates in 'interleaved' mode. |
| logger | An optional instance of an ApplicationLogging IApplicationLogger instance used to log statistical and performance information (see the 'Logging' section below). |
Retries are implemented using the configurable retry logic functionality in the Microsoft.Data.SqlClient library.
3) Viewing and Querying Logged Metrics
A view is available for each of the 4 different types of metrics (e.g. 'CountMetricInstancesView', 'AmountMetricInstancesView', etc...). Additionally a view which consolidates all logged metrics ('AllMetricInstancesView') can be queried. Standard SQL can be used to filter and aggregate the contents of these views.
A sample of the contents of 'AllMetricInstancesView' appears below...

Logging
Its possible that ApplicationMetrics and its client application could generate metrics more quickly than a SQL Server instance is able to consume them. In these situations the number of metrics processed, and/or the time taken to process them (depending on the buffer processing strategy used) would continue to increase over time (and eventually lead to out of memory or timeout errors). If an instance of IApplicationLogger is provided to the constructor, SqlServerMetricLogger will create log similar to the following...
Processed 550 metric events in 123 milliseconds.
...each time a set of buffered metrics are processed, allowing performance to be monitored and the aforementioned situations avoided.
Links
The documentation below was written for version 1.* of ApplicationMetrics. Minor implementation details may have changed in versions 2.0.0 and above, however the basic principles and use cases documented are still valid. Note also that this documentation demonstrates the older 'non-interleaved' method of logging interval metrics.
Full documentation for the project...
http://www.alastairwyse.net/methodinvocationremoting/application-metrics.html
A detailed sample implementation...
http://www.alastairwyse.net/methodinvocationremoting/sample-application-5.html
Release History
| Version | Changes |
| 2.6.0 |
Updated for compatibility with ApplicationMetrics version 7.0.0. |
| 2.5.0 |
Updated for compatibility with ApplicationMetrics version 6.4.1. |
| 2.4.0 |
Updated to use Microsoft.Data.SqlClient version 5.2.2. |
| 2.3.0 |
Updated for compatibility with ApplicationMetrics version 6.3.0. |
| 2.2.0 | Updated for compatibility with ApplicationMetrics version 6.2.0. |
| 2.1.0 | Updated for compatibility with ApplicationMetrics version 6.1.0. |
| 2.0.0 |
Updated for compatibility with ApplicationMetrics version 6.0.0. Allow specifying the SQL command timeout property via the 'operationTimeout' constructor parameter. Concurrency fix to Insert*Metrics stored procedures, to resolve 'cannot insert the value NULL into column' and 'transaction has been chosen as the deadlock victim' errors when inserting new categories or metric instances for the first time. Added unique index to 'Name' columns in *Metrics tables. |
| 1.2.0 | Added logging of buffer processing time and metric count. |
| 1.1.0 | Updated for compatibility with ApplicationMetrics version 5.1.0. |
| 1.0.0 | Initial release. |
Owner
- Name: Alastair Wyse
- Login: alastairwyse
- Kind: user
- Repositories: 20
- Profile: https://github.com/alastairwyse
GitHub Events
Total
- Push event: 3
- Create event: 3
Last Year
- Push event: 3
- Create event: 3
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- nuget 4,822 total
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 11
- Total maintainers: 1
nuget.org: applicationmetrics.metricloggers.sqlserver
An ApplicationMetrics metric logger which writes metric and instrumentation events to a Microsoft SQL Server database.
- Homepage: https://github.com/alastairwyse/ApplicationMetrics.MetricLoggers.SqlServer/
- License: Apache-2.0
-
Latest release: 2.6.0
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- ApplicationLogging 2.0.0
- ApplicationMetrics 6.0.0
- Microsoft.Data.SqlClient 5.1.1
- StandardAbstraction 1.1.0
- Microsoft.NET.Test.Sdk 17.3.0
- NSubstitute 4.4.0
- NUnit 3.13.3
- NUnit3TestAdapter 4.2.1