Skip to content

Commit d21e5e5

Browse files
committed
Fix
1 parent 9a4c187 commit d21e5e5

File tree

1 file changed

+39
-28
lines changed

1 file changed

+39
-28
lines changed

collector/pg_stat_user_tables.go

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,16 @@ var (
208208
pg_total_relation_size(relid) as total_size,
209209
CASE WHEN current_setting('server_version_num')::int >= 180000
210210
THEN total_vacuum_time
211-
ELSE NULL precision END as total_vacuum_time,
211+
ELSE NULL END as total_vacuum_time,
212212
CASE WHEN current_setting('server_version_num')::int >= 180000
213213
THEN total_autovacuum_time
214-
ELSE NULL precision END as total_autovacuum_time,
214+
ELSE NULL END as total_autovacuum_time,
215215
CASE WHEN current_setting('server_version_num')::int >= 180000
216216
THEN total_analyze_time
217-
ELSE NULL precision END as total_analyze_time,
217+
ELSE NULL END as total_analyze_time,
218218
CASE WHEN current_setting('server_version_num')::int >= 180000
219219
THEN total_autoanalyze_time
220-
ELSE NULL precision END as total_autoanalyze_time
220+
ELSE NULL END as total_autoanalyze_time
221221
FROM
222222
pg_stat_user_tables`
223223
)
@@ -480,38 +480,49 @@ func (c *PGStatUserTablesCollector) Update(ctx context.Context, instance *instan
480480

481481
if after18 {
482482
// PostgreSQL 18+ vacuum/analyze timing metrics
483+
totalVacuumTimeValue := 0.0
483484
if totalVacuumTime.Valid {
484-
ch <- prometheus.MustNewConstMetric(
485-
statUserTablesTotalVacuumTime,
486-
prometheus.CounterValue,
487-
totalVacuumTime.Float64,
488-
datnameLabel, schemanameLabel, relnameLabel,
489-
)
485+
totalVacuumTimeValue = totalVacuumTime.Float64
490486
}
487+
ch <- prometheus.MustNewConstMetric(
488+
statUserTablesTotalVacuumTime,
489+
prometheus.CounterValue,
490+
totalVacuumTimeValue,
491+
datnameLabel, schemanameLabel, relnameLabel,
492+
)
493+
494+
totalAutovacuumTimeValue := 0.0
491495
if totalAutovacuumTime.Valid {
492-
ch <- prometheus.MustNewConstMetric(
493-
statUserTablesTotalAutovacuumTime,
494-
prometheus.CounterValue,
495-
totalAutovacuumTime.Float64,
496-
datnameLabel, schemanameLabel, relnameLabel,
497-
)
496+
totalAutovacuumTimeValue = totalAutovacuumTime.Float64
498497
}
498+
ch <- prometheus.MustNewConstMetric(
499+
statUserTablesTotalAutovacuumTime,
500+
prometheus.CounterValue,
501+
totalAutovacuumTimeValue,
502+
datnameLabel, schemanameLabel, relnameLabel,
503+
)
504+
505+
totalAnalyzeTimeValue := 0.0
499506
if totalAnalyzeTime.Valid {
500-
ch <- prometheus.MustNewConstMetric(
501-
statUserTablesTotalAnalyzeTime,
502-
prometheus.CounterValue,
503-
totalAnalyzeTime.Float64,
504-
datnameLabel, schemanameLabel, relnameLabel,
505-
)
507+
totalAnalyzeTimeValue = totalAnalyzeTime.Float64
506508
}
509+
ch <- prometheus.MustNewConstMetric(
510+
statUserTablesTotalAnalyzeTime,
511+
prometheus.CounterValue,
512+
totalAnalyzeTimeValue,
513+
datnameLabel, schemanameLabel, relnameLabel,
514+
)
515+
516+
totalAutoanalyzeTimeValue := 0.0
507517
if totalAutoanalyzeTime.Valid {
508-
ch <- prometheus.MustNewConstMetric(
509-
statUserTablesTotalAutoanalyzeTime,
510-
prometheus.CounterValue,
511-
totalAutoanalyzeTime.Float64,
512-
datnameLabel, schemanameLabel, relnameLabel,
513-
)
518+
totalAutoanalyzeTimeValue = totalAutoanalyzeTime.Float64
514519
}
520+
ch <- prometheus.MustNewConstMetric(
521+
statUserTablesTotalAutoanalyzeTime,
522+
prometheus.CounterValue,
523+
totalAutoanalyzeTimeValue,
524+
datnameLabel, schemanameLabel, relnameLabel,
525+
)
515526
}
516527
}
517528

0 commit comments

Comments
 (0)