mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-11 03:31:26 +00:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
8c3604b85e | ||
|
803e131ee4 | ||
|
bad8b233d8 | ||
|
392d8ca16a | ||
|
0850b195a0 | ||
|
dd87ad094a |
@ -1,3 +1,9 @@
|
||||
## 0.13.2 / 2023-07-21
|
||||
|
||||
* [BUGFIX] Fix type issues on pg_postmaster metrics #828
|
||||
* [BUGFIX] Fix pg_replication collector instantiation #854
|
||||
* [BUGFIX] Fix pg_process_idle metrics #855
|
||||
|
||||
## 0.13.1 / 2023-06-27
|
||||
|
||||
* [BUGFIX] Make collectors not fail on null values #823
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
const postmasterSubsystem = "postmaster"
|
||||
|
||||
func init() {
|
||||
registerCollector(postmasterSubsystem, defaultEnabled, NewPGPostmasterCollector)
|
||||
registerCollector(postmasterSubsystem, defaultDisabled, NewPGPostmasterCollector)
|
||||
}
|
||||
|
||||
type PGPostmasterCollector struct {
|
||||
@ -44,7 +44,7 @@ var (
|
||||
[]string{}, nil,
|
||||
)
|
||||
|
||||
pgPostmasterQuery = "SELECT pg_postmaster_start_time from pg_postmaster_start_time();"
|
||||
pgPostmasterQuery = "SELECT extract(epoch from pg_postmaster_start_time) from pg_postmaster_start_time();"
|
||||
)
|
||||
|
||||
func (c *PGPostmasterCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
|
||||
|
@ -18,6 +18,7 @@ import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/go-kit/log"
|
||||
"github.com/lib/pq"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -43,8 +44,8 @@ var pgProcessIdleSeconds = prometheus.NewDesc(
|
||||
prometheus.Labels{},
|
||||
)
|
||||
|
||||
func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch chan<- prometheus.Metric) error {
|
||||
db := inst.getDB()
|
||||
func (PGProcessIdleCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
|
||||
db := instance.getDB()
|
||||
row := db.QueryRowContext(ctx,
|
||||
`WITH
|
||||
metrics AS (
|
||||
@ -82,22 +83,22 @@ func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch cha
|
||||
GROUP BY 1, 2, 3;`)
|
||||
|
||||
var applicationName sql.NullString
|
||||
var secondsSum sql.NullInt64
|
||||
var secondsSum sql.NullFloat64
|
||||
var secondsCount sql.NullInt64
|
||||
var seconds []int64
|
||||
var secondsBucket []uint64
|
||||
var seconds []float64
|
||||
var secondsBucket []int64
|
||||
|
||||
err := row.Scan(&applicationName, &secondsSum, &secondsCount, &seconds, &secondsBucket)
|
||||
err := row.Scan(&applicationName, &secondsSum, &secondsCount, pq.Array(&seconds), pq.Array(&secondsBucket))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var buckets = make(map[float64]uint64, len(seconds))
|
||||
for i, second := range seconds {
|
||||
if i >= len(secondsBucket) {
|
||||
break
|
||||
}
|
||||
buckets[float64(second)] = secondsBucket[i]
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
buckets[second] = uint64(secondsBucket[i])
|
||||
}
|
||||
|
||||
applicationNameLabel := "unknown"
|
||||
@ -111,7 +112,7 @@ func (PGProcessIdleCollector) Update(ctx context.Context, inst *instance, ch cha
|
||||
}
|
||||
secondsSumMetric := 0.0
|
||||
if secondsSum.Valid {
|
||||
secondsSumMetric = float64(secondsSum.Int64)
|
||||
secondsSumMetric = secondsSum.Float64
|
||||
}
|
||||
ch <- prometheus.MustNewConstHistogram(
|
||||
pgProcessIdleSeconds,
|
||||
|
@ -15,7 +15,6 @@ package collector
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
@ -30,7 +29,7 @@ type PGReplicationCollector struct {
|
||||
}
|
||||
|
||||
func NewPGReplicationCollector(collectorConfig) (Collector, error) {
|
||||
return &PGPostmasterCollector{}, nil
|
||||
return &PGReplicationCollector{}, nil
|
||||
}
|
||||
|
||||
var (
|
||||
@ -64,7 +63,8 @@ var (
|
||||
END as is_replica`
|
||||
)
|
||||
|
||||
func (c *PGReplicationCollector) Update(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric) error {
|
||||
func (c *PGReplicationCollector) Update(ctx context.Context, instance *instance, ch chan<- prometheus.Metric) error {
|
||||
db := instance.getDB()
|
||||
row := db.QueryRowContext(ctx,
|
||||
pgReplicationQuery,
|
||||
)
|
||||
|
@ -29,6 +29,8 @@ func TestPgReplicationCollector(t *testing.T) {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
inst := &instance{db: db}
|
||||
|
||||
columns := []string{"lag", "is_replica"}
|
||||
rows := sqlmock.NewRows(columns).
|
||||
AddRow(1000, 1)
|
||||
@ -39,7 +41,7 @@ func TestPgReplicationCollector(t *testing.T) {
|
||||
defer close(ch)
|
||||
c := PGReplicationCollector{}
|
||||
|
||||
if err := c.Update(context.Background(), db, ch); err != nil {
|
||||
if err := c.Update(context.Background(), inst, ch); err != nil {
|
||||
t.Errorf("Error calling PGReplicationCollector.Update: %s", err)
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user