Skip to content

Commit 80b01e9

Browse files
committed
Unpack postgres arrays for process idle times correctly
Signed-off-by: Tom Hughes <[email protected]>
1 parent 2477aba commit 80b01e9

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

collector/pg_process_idle.go

+8-7
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

@@ -84,20 +85,20 @@ func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch
8485
var applicationName sql.NullString
8586
var secondsSum sql.NullInt64
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"

0 commit comments

Comments
 (0)