Skip to content

globocom/mongo-go-prometheus

Repository files navigation

mongo-go-prometheus

Monitors that export Prometheus metrics for the MongoDB Go driver

Installation

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

Usage

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.

About

Monitors that export Prometheus metrics for the MongoDB Go driver

Topics

Resources

License

Stars

8 stars

Watchers

10 watching

Forks

Contributors