/go-pg-monitor

Exposes Prometheus metrics for go-pg database client stats.

Primary LanguageGoApache License 2.0Apache-2.0

go-pg-monitor

Provides Prometheus metrics for go-pg database client.

Example Grafana dashboards:

grafana

Usage

  1. Your application should already be using go-pg and exporting Prometheus metrics.

  2. Add the module to your project:

    go get github.com/hypnoglow/go-pg-monitor

    Also add the submodule with the go-pg version you use:

    go get github.com/hypnoglow/go-pg-monitor/gopg10
  3. Add monitor to your application entrypoint:

    // Create monitor based on your *pg.DB
    mon := monitor.NewMonitor(
    	gopgv10.NewObserver(db),
    	monitor.NewMetrics(),
    )
    
    // Call this on application startup. 
    mon.Open()
    
    // Call this on application shutdown.
    mon.Close()

See example for details.

Exported metrics

  • go_pg_pool_hits - (Gauge) Number of times free connection was found in the pool
  • go_pg_pool_misses - (Gauge) Number of times free connection was NOT found in the pool
  • go_pg_pool_timeouts - (Gauge) Number of times a wait timeout occurred
  • go_pg_pool_total_connections - (Gauge) Number of total connections in the pool
  • go_pg_pool_idle_connections - (Gauge) Number of idle connections in the pool
  • go_pg_pool_stale_connections - (Gauge) Number of stale connections removed from the pool