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

Commit b4c7e21

Browse files
authored
Reseting gauge on metrics
* Reseting gauge metrics After some value is setted to metricss `postgresql_backends_by_wait_event_type_total`, `postgresql_backends_by_state_total` and `postgresql_locks_total `, the value is not updated if the query returns no rows. To fix that, the gauge is reseted every time when the query is executed, thus grants that the old value was cleared.
1 parent 91cb00c commit b4c7e21

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

gauges/backends.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (g *Gauges) BackendsByState() *prometheus.GaugeVec {
5656

5757
go func() {
5858
for {
59+
gauge.Reset()
5960
var backendsByState []backendsByState
6061
if err := g.query(backendsByStateQuery, &backendsByState, emptyParams); err == nil {
6162
for _, row := range backendsByState {
@@ -110,6 +111,7 @@ func (g *Gauges) BackendsByWaitEventType() *prometheus.GaugeVec {
110111

111112
go func() {
112113
for {
114+
gauge.Reset()
113115
var backendsByWaitEventType []backendsByWaitEventType
114116
if err := g.query(g.backendsByWaitEventTypeQuery(),
115117
&backendsByWaitEventType, emptyParams); err == nil {

gauges/locks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
2323
)
2424
go func() {
2525
for {
26+
gauge.Reset()
2627
var locks []locks
2728
if err := g.query(
2829
`

0 commit comments

Comments
 (0)