Skip to content

Commit

Permalink
feat: add usename label
Browse files Browse the repository at this point in the history
Signed-off-by: rezaxd <[email protected]>
  • Loading branch information
rezaxd committed Nov 19, 2023
1 parent 74cf90d commit d3dc319
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions collector/pg_process_idle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -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
}

0 comments on commit d3dc319

Please sign in to comment.