Skip to content

tracepath/mongo-go-prometheus

 
 

Repository files navigation

mongo-go-prometheus

Monitors that export Prometheus metrics for the MongoDB Go driver

Installation

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

Usage

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...
}

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"}
  • 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"}

API stability

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

About

Monitors that export Prometheus metrics for the MongoDB Go driver

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 99.8%
  • Makefile 0.2%