Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit c82d8e8

Browse files
committed
Little code adjusts
1 parent 1786e23 commit c82d8e8

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

gauges/table_rows.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import (
66
"github.com/prometheus/client_golang/prometheus"
77
)
88

9-
var tableDeadRowsQuery = `
10-
SELECT relname
11-
, coalesce(n_dead_tup, 0) as n_dead_tup
12-
FROM pg_stat_user_tables
13-
`
14-
159
type tableDeadRows struct {
1610
Table string `db:"relname"`
1711
DeadTuples float64 `db:"n_dead_tup"`
@@ -22,11 +16,16 @@ func (g *Gauges) TableDeadRows() *prometheus.GaugeVec {
2216
var gauge = prometheus.NewGaugeVec(
2317
prometheus.GaugeOpts{
2418
Name: "postgresql_table_dead_rows",
25-
Help: "Number of dead rows in table",
19+
Help: "Estimated number of dead rows in table",
2620
ConstLabels: g.labels,
2721
},
2822
[]string{"table"},
2923
)
24+
25+
const tableDeadRowsQuery = `
26+
SELECT relname, coalesce(n_dead_tup, 0) as n_dead_tup FROM pg_stat_user_tables
27+
`
28+
3029
go func() {
3130
for {
3231
var tableDeadRows []tableDeadRows
@@ -43,17 +42,14 @@ func (g *Gauges) TableDeadRows() *prometheus.GaugeVec {
4342
return gauge
4443
}
4544

46-
var databaseDeadRowsQuery = `
47-
SELECT sum(coalesce(n_dead_tup, 0)) as n_dead_tup
48-
FROM pg_stat_user_tables
49-
`
50-
5145
// DatabaseDeadRows returns the sum of estimated number of dead rows of all tables in a database
5246
func (g *Gauges) DatabaseDeadRows() prometheus.Gauge {
5347
return g.new(
5448
prometheus.GaugeOpts{
5549
Name: "postgresql_database_dead_rows",
56-
Help: "Number of dead rows in database",
50+
Help: "Estimated number of dead rows in database",
5751
ConstLabels: g.labels,
58-
}, databaseDeadRowsQuery)
52+
},
53+
"SELECT sum(coalesce(n_dead_tup, 0)) as n_dead_tup FROM pg_stat_user_tables",
54+
)
5955
}

0 commit comments

Comments
 (0)