Skip to content

Commit 6e53796

Browse files
Move gaugeInt32 into collector.go.
Signed-off-by: Peter Nuttall <[email protected]>
1 parent aa004f6 commit 6e53796

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

collector/collector.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package collector
1515

1616
import (
1717
"context"
18+
"database/sql"
1819
"errors"
1920
"fmt"
2021
"log/slog"
@@ -228,3 +229,11 @@ var ErrNoData = errors.New("collector returned no data")
228229
func IsNoDataError(err error) bool {
229230
return err == ErrNoData
230231
}
232+
233+
func Int32(m sql.NullInt32) float64 {
234+
mM := 0.0
235+
if m.Valid {
236+
mM = float64(m.Int32)
237+
}
238+
return mM
239+
}

collector/pg_buffercache_summary.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ var (
8989
`
9090
)
9191

92-
func gaugeInt32(ch chan<- prometheus.Metric, desc *prometheus.Desc, m sql.NullInt32) {
93-
mM := 0.0
94-
if m.Valid {
95-
mM = float64(m.Int32)
96-
}
97-
ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, mM)
98-
}
99-
10092
// Update implements Collector
10193
// It is called by the Prometheus registry when collecting metrics.
10294
func (c BuffercacheSummaryCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
@@ -133,10 +125,10 @@ func (c BuffercacheSummaryCollector) Update(ctx context.Context, instance *insta
133125
usageCountAvgDesc,
134126
prometheus.GaugeValue,
135127
usagecountAvgMetric)
136-
gaugeInt32(used, buffersUsedDesc, ch)
137-
gaugeInt32(unused, buffersUnusedDesc, ch)
138-
gaugeInt32(dirty, buffersDirtyDesc, ch)
139-
gaugeInt32(pinned, buffersPinnedDesc, ch)
128+
ch <- prometheus.MustNewConstMetric(buffersUsedDesc, prometheus.GaugeValue, Int32(used))
129+
ch <- prometheus.MustNewConstMetric(buffersUnusedDesc, prometheus.GaugeValue, Int32(unused))
130+
ch <- prometheus.MustNewConstMetric(buffersDirtyDesc, prometheus.GaugeValue, Int32(dirty))
131+
ch <- prometheus.MustNewConstMetric(buffersPinnedDesc, prometheus.GaugeValue, Int32(pinned))
140132
}
141133

142134
return rows.Err()

0 commit comments

Comments
 (0)