prometheus-net.Contrib.MongoDb 0.6.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package prometheus-net.Contrib.MongoDb --version 0.6.0
NuGet\Install-Package prometheus-net.Contrib.MongoDb -Version 0.6.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="prometheus-net.Contrib.MongoDb" Version="0.6.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add prometheus-net.Contrib.MongoDb --version 0.6.0
#r "nuget: prometheus-net.Contrib.MongoDb, 0.6.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install prometheus-net.Contrib.MongoDb as a Cake Addin
#addin nuget:?package=prometheus-net.Contrib.MongoDb&version=0.6.0

// Install prometheus-net.Contrib.MongoDb as a Cake Tool
#tool nuget:?package=prometheus-net.Contrib.MongoDb&version=0.6.0

prometheus-net.Contrib.MongoDb

Overview

prometheus-net.Contrib.MongoDb is a C# library that provides client-side Prometheus instrumentation for MongoDB operations (instrumenting MongoDB C# Driver)
It captures various metrics related to MongoDB commands, errors, and performance, and exports them to Prometheus for monitoring and alerting.

The Why

Why create another metrics library for MongoDB when there's already mongodb_exporter?
It is true that mongodb_exporter is a great tool for monitoring MongoDB, but it is a server-side tool that requires a separate process to run, possibly docker or other mode of deployment. On top of that, it "actively" gathers information by polling MongoDB while this exporter will do it "passively" by instrumenting the MongoDB C# Driver, without the need to run a separate process.

Note: This library is still in development and more metrics will be added

Metrics Exposed

Command Duration (mongodb_client_command_duration)

Histogram metric that measures the duration of MongoDB commands in seconds.

  • Labels: command_type, status, target_collection, target_db

Open Cursors Count (mongodb_client_open_cursors_count)

Gauge metric that tracks the number of open cursors.

  • Labels: target_collection, target_db

Open Cursors Duration (mongodb_client_open_cursors_duration)

Histogram metric that tracks the number of open cursors.

  • Labels: target_collection, target_db

Open Cursor Document Count (mongodb_client_cursor_document_count)

Summary metric that measures the document count fetched by a cursor.

  • Labels: target_collection, target_db

Command Errors (mongodb_client_command_errors_total)

Counter metric that counts the total number of MongoDB command errors.

  • Labels: command_type, error_type, target_collection, target_db

Command Size (mongodb_command_response_size)

Histogram metric that measures the size of MongoDB commands in bytes.

  • Labels: command_type, target_collection, target_db

Connection Creation Rate (mongodb_client_connection_creation_rate)

Counter metric that captures the rate at which new MongoDB connections are created.

  • Labels: cluster_id, end_point

Connection Duration (mongodb_client_connection_duration)

Histogram metric that measures the time it takes to close a MongoDB connection, in seconds.

  • Labels: cluster_id, end_point

Query Filter Size (mongodb_client_query_filter_size)

Histogram metric that tracks the size of MongoDB query filters.

  • Labels: query_type, target_collection, target_db

Query Count (mongodb_client_query_count)

Counter metric that measures the number of "find" and "aggregate" MongoDB queries.

  • Labels: query_type, target_collection, target_db

Note: This metric tries to capture the complexity of the filters being used in MongoDB queries. It recursively counts the number of clauses and items in the filters, which could be a useful metric for understanding query performance. Note that the performance in this case also depends on any indexes or their lack in the collection.

Usage Example

Here's a simple example to instrument your MongoDB client:

using MongoDB.Driver;

var settings = MongoClientSettings.FromConnectionString("your_connection_string_here");
settings = settings.InstrumentForPrometheus();

var client = new MongoClient(settings);

Installation

This library is available as a NuGet package. To install, run:

Install-Package prometheus-net.Contrib.MongoDb

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.9 191 9/29/2023
3.0.2 103 9/28/2023
3.0.0 105 9/28/2023
2.0.6 113 9/28/2023
2.0.4 110 9/27/2023
2.0.2 112 9/27/2023
2.0.0 114 9/27/2023
1.0.0 113 9/27/2023
0.8.6 126 9/27/2023
0.8.4 112 9/27/2023
0.8.2 123 9/26/2023
0.8.0 97 9/26/2023
0.7.10 127 9/26/2023
0.7.8 111 9/26/2023
0.7.6 113 9/26/2023
0.7.4 103 9/26/2023
0.7.2 115 9/26/2023
0.7.0 111 9/26/2023
0.6.0 113 9/25/2023
0.5.5 112 9/25/2023
0.5.0 110 9/24/2023
0.3.1 108 9/23/2023
0.2.6 110 9/23/2023

Changes since version v0.5.0.0

:bug: Bug Fixes:
- [`2410a68`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/2410a68b7454177411e0ffa68486279382fdcc1d) - try to take care of race condition in a test *(commit by [@myarichuk](https://github.com/myarichuk))*

:white_check_mark: Tests:
- [`c85c611`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/c85c611d6b62873a609c2801daf2363999758221) - "migrate" tests to use MongoTestContext - a more structured way to write tests *(commit by [@myarichuk](https://github.com/myarichuk))*

:wrench: Chores:
- [`6f6dffe`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/6f6dffee6e3c29da77688b9e956456f9bd3cb45b) - adjust readme file (add a "motivation" section) *(commit by [@myarichuk](https://github.com/myarichuk))*
- [`1275b8d`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/1275b8d217622a062b1d76a26d4764c08dd0d3ea) - **deps**: bump Microsoft.NET.Test.Sdk from 17.6.0 to 17.7.2 *(commit by [@dependabot[bot]](https://github.com/apps/dependabot))*
- [`999ede2`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/999ede20cf32b5cc2b9d0996a09a63cad4857594) - **deps**: bump coverlet.collector from 3.2.0 to 6.0.0 *(commit by [@dependabot[bot]](https://github.com/apps/dependabot))*
- [`dd66b48`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/dd66b48f5452bb04352c2553e3add23d37a798b9) - **deps**: bump xunit.runner.visualstudio from 2.4.5 to 2.5.1 *(commit by [@dependabot[bot]](https://github.com/apps/dependabot))*
- [`3beb686`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/3beb686ce3f2edb3d11189f73a308e3f97ed9945) - fix tests so they work properly *(commit by [@myarichuk](https://github.com/myarichuk))*
- [`baf2a63`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/baf2a639d16a965ef9eb105e9d585527eeed04ca) - **tests**: remove unnecessary code *(commit by [@myarichuk](https://github.com/myarichuk))*
- [`9d6d392`](https://github.com/myarichuk/prometheus-net.Contrib.MongoDb/commit/9d6d3925b94d4210573771e69bdd37c16601129e) - minor code change *(commit by [@myarichuk](https://github.com/myarichuk))*