From d3dc319c6774b77a8cb2177979945b96659ddc31 Mon Sep 17 00:00:00 2001 From: rezaxd Date: Sun, 19 Nov 2023 17:15:05 +0330 Subject: [PATCH] feat: add usename label Signed-off-by: rezaxd --- collector/pg_process_idle.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/collector/pg_process_idle.go b/collector/pg_process_idle.go index 72620dab1..1a0057503 100644 --- a/collector/pg_process_idle.go +++ b/collector/pg_process_idle.go @@ -89,12 +89,13 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch var state sql.NullString var applicationName sql.NullString + var usename sql.NullString var secondsSum sql.NullFloat64 var secondsCount sql.NullInt64 var seconds []float64 var secondsBucket []int64 - err := row.Scan(&state, &applicationName, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket)) + err := row.Scan(&state, &applicationName, &usename, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket)) if err != nil { return err } @@ -117,6 +118,11 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch applicationNameLabel = applicationName.String } + usenameLabel := "unknown" + if usename.Valid { + usenameLabel = usename.String + } + var secondsCountMetric uint64 if secondsCount.Valid { secondsCountMetric = uint64(secondsCount.Int64) @@ -128,7 +134,7 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch ch <- prometheus.MustNewConstHistogram( pgProcessIdleSeconds, secondsCountMetric, secondsSumMetric, buckets, - stateLabel, applicationNameLabel, + stateLabel, applicationNameLabel, usenameLabel, ) return nil }