Golang maxPoolSize monitoring?

@alexbevi Thanks for the reply and for your great blogs!

This looks like a reasonable approach, although I can’t help but feel that these counters must already exist within the “driver”, so it’s double handling.

Are those increments in HandlePoolEvent concurrency safe? I would have thought atomic increments are required ( Not sure if you’ve seen this talk https://www.youtube.com/watch?v=1V7eJ0jN8-E ). We might try using prometheus counters I guess. Something like:

import (
   hmmm this forum thingy won't let me post links
)

var (
	pC = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Subsystem: "mongo_counters",
			Name:      "my_service",
			Help:      "my_service mongo_counters counts",
		},
		[]string{"event"},
	)


func (d *dbClient) HandlePoolEvent(evt *event.PoolEvent) {
	pC.WithLabelValues(evt.Type).Inc()
}


Although it would be kind of nice to have increments and decrements, so we know the current number

	pG = promauto.NewGauge(
		prometheus.GaugeOpts{
			Subsystem: "connections_gauge",
			Name:      "my_service",
			Help:      "my_service connection gauge",
		},
	)

func (d *dbClient) HandlePoolEvent(evt *event.PoolEvent) {
	pC.WithLabelValues(evt.Type).Inc()
	switch evt.Type {
	case event.ConnectionCreated:
		pG.Inc()
	case event.ConnectionClosed:
		pG.Dec()

I will play around and see what I can come up with.

Thanks again!