Skip to content

Commit

Permalink
Add prometheus metric for postgres GC duration
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Schorr <josephschorr@users.noreply.github.com>
  • Loading branch information
josephschorr committed Oct 5, 2021
1 parent 708dab5 commit 75b5a6f
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/datastore/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,15 @@ const (
batchDeleteSize = 1000
)

var gcDurationHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Name: "postgres_gc_duration",
Help: "postgres garbage collection duration distribution in seconds.",
Buckets: []float64{0.01, 0.1, 0.5, 1, 5, 10, 25, 60, 120},
})

func init() {
dbsql.Register(tracingDriverName, sqlmw.Driver(stdlib.GetDefaultDriver(), new(traceInterceptor)))
prometheus.MustRegister(gcDurationHistogram)
}

var (
Expand Down Expand Up @@ -204,6 +211,11 @@ func (pgd *pgDatastore) getNow(ctx context.Context) (time.Time, error) {
}

func (pgd *pgDatastore) collectGarbage() error {
startTime := time.Now()
defer func() {
gcDurationHistogram.Observe(float64(time.Since(startTime).Seconds()))
}()

ctx, cancel := context.WithTimeout(context.Background(), pgd.gcMaxOperationTime)
defer cancel()

Expand Down

0 comments on commit 75b5a6f

Please sign in to comment.