Skip to content

Commit 6b56e2f

Browse files
authored
Unpack postgres arrays for process idle times correctly (prometheus-community#855)
Signed-off-by: Ben Kochie <[email protected]>
1 parent 401711b commit 6b56e2f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

collector/pg_process_idle.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"database/sql"
1919

2020
"github.com/go-kit/log"
21+
"github.com/lib/pq"
2122
"github.com/prometheus/client_golang/prometheus"
2223
)
2324

@@ -82,22 +83,22 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
8283
GROUP BY 1, 2, 3;`)
8384

8485
var applicationName sql.NullString
85-
var secondsSum sql.NullInt64
86+
var secondsSum sql.NullFloat64
8687
var secondsCount sql.NullInt64
87-
var seconds []uint64
88-
var secondsBucket []uint64
88+
var seconds []float64
89+
var secondsBucket []int64
8990

90-
err := row.Scan(&applicationName, &secondsSum, &secondsCount, &seconds, &secondsBucket)
91+
err := row.Scan(&applicationName, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket))
92+
if err != nil {
93+
return err
94+
}
9195

9296
var buckets = make(map[float64]uint64, len(seconds))
9397
for i, second := range seconds {
9498
if i >= len(secondsBucket) {
9599
break
96100
}
97-
buckets[float64(second)] = secondsBucket[i]
98-
}
99-
if err != nil {
100-
return err
101+
buckets[second] = uint64(secondsBucket[i])
101102
}
102103

103104
applicationNameLabel := "unknown"
@@ -111,7 +112,7 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
111112
}
112113
secondsSumMetric := 0.0
113114
if secondsSum.Valid {
114-
secondsSumMetric = float64(secondsSum.Int64)
115+
secondsSumMetric = secondsSum.Float64
115116
}
116117
ch <- prometheus.MustNewConstHistogram(
117118
pgProcessIdleSeconds,

0 commit comments

Comments
 (0)