Monitors that export Prometheus metrics for the MongoDB Go driver
go get github.com/tracepath/mongo-go-prometheus
package main
import (
"github.com/tracepath/mongo-go-prometheus"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
monitor := mongoprom.NewCommandMonitor(
mongoprom.WithInstanceName("database"),
mongoprom.WithNamespace("my_namespace"),
mongoprom.WithDurationBuckets([]float64{.001, .005, .01}),
)
poolMonitor := mongoprom.NewPoolMonitor(
mongoprom.PoolWithInstanceName("database"),
mongoprom.PoolWithNamespace("my_namespace"),
)
opts := options.Client().
ApplyURI("mongodb://localhost:27019").
SetMonitor(monitor).SetPoolMonitor(poolMonitor)
client, err := mongo.Connect(context.TODO(), opts)
if err != nil {
panic(err)
}
// run MongoDB commands...
}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"}
- Histogram of commands:
- Pool:
- Max number of connections allowed in Connection Pool:
mongodb_connection_pool_max{instance="db"} - Min number of connections allowed in Connection Pool:
mongodb_connection_pool_min{instance="db"} - Actual connections in usage:
mongodb_connection_pool_usage{instance="db"}
- Max number of connections allowed in Connection Pool:
The API is unstable at this point and it might change before v1.0.0 is released.