Home

Awesome

go-pg-monitor

Go Reference Maintenance main Go Report Card

Provides Prometheus metrics for go-pg database client.

Example Grafana dashboards:

grafana

Status

This package is now stable.

As the go-pg is in a maintenance mode, it is unlikely that new features will be introduced in this package. Fixing bugs and security issues will continue.

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/gopgv10
    
  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

Reference Grafana Dashboards

You can find two example Grafana dashboards in grafana/ directory. One may be suitable when you use only one database object in your application code, and the other when you use different objects (pools) for different parts of the application.

Note that your dashboard may be different if you use metric namespace, different k8s labels, etc. So these dashboards are provided only as a starting point for making your own.