An open API service indexing awesome lists of open source software.

https://github.com/globocom/mongo-go-prometheus

Monitors that export Prometheus metrics for the MongoDB Go driver
https://github.com/globocom/mongo-go-prometheus

go golang mongodb prometheus

Last synced: 11 months ago
JSON representation

Monitors that export Prometheus metrics for the MongoDB Go driver

Awesome Lists containing this project

README

          

# mongo-go-prometheus










Monitors that export Prometheus metrics for the MongoDB Go driver

## Installation

go get github.com/globocom/mongo-go-prometheus

## Usage

```golang
package main

import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"github.com/globocom/mongo-go-prometheus"
)

func main() {
monitor := mongoprom.NewCommandMonitor(
mongoprom.WithInstanceName("database"),
mongoprom.WithNamespace("my_namespace"),
mongoprom.WithDurationBuckets([]float64{.001, .005, .01}),
)
opts := options.Client().
ApplyURI("mongodb://localhost:27019").
SetMonitor(monitor)

client, err := mongo.Connect(context.TODO(), opts)
if err != nil {
panic(err)
}

// run MongoDB commands...
}
```

## Exported metrics

The command monitor exports the following metrics:

- Commands:
- Histogram of commands: `mongo_commands{instance="db", command="insert"}`
- Counter of errors: `mongo_command_errors{instance="db", command="update"}`

## API stability

The API is unstable at this point and it might change before `v1.0.0` is released.