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
- Host: GitHub
- URL: https://github.com/globocom/mongo-go-prometheus
- Owner: globocom
- License: mit
- Created: 2021-08-28T01:11:18.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-03-22T00:03:28.000Z (over 4 years ago)
- Last Synced: 2025-08-09T21:38:15.109Z (12 months ago)
- Topics: go, golang, mongodb, prometheus
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 9
- Watchers: 11
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.