@@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
20
20
"github.com/go-kit/log"
21
+ "github.com/go-kit/log/level"
21
22
"github.com/prometheus/client_golang/prometheus"
22
23
)
23
24
@@ -158,132 +159,147 @@ func (c *PGStatWalReceiverCollector) Update(ctx context.Context, instance *insta
158
159
}
159
160
}
160
161
if ! upstreamHost .Valid {
162
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because upstream host is null" )
161
163
continue
162
164
}
163
165
164
166
if ! slotName .Valid {
167
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because slotname host is null" )
165
168
continue
166
169
}
167
170
labels := []string {upstreamHost .String , slotName .String }
171
+ if ! status .Valid {
172
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because status is null" )
173
+ continue
174
+ }
168
175
169
- statusMetric := - 3.0
170
- if status .Valid {
171
- switch status .String {
172
- case "stopped" :
173
- statusMetric = 0.0
174
- break
175
- case "starting" :
176
- statusMetric = 1.0
177
- break
178
- case "streaming" :
179
- statusMetric = 2.0
180
- break
181
- case "waiting" :
182
- statusMetric = 3.0
183
- break
184
- case "restarting" :
185
- statusMetric = 4.0
186
- break
187
- case "stopping" :
188
- statusMetric = - 1.0
189
- break
190
- default :
191
- statusMetric = - 2.0
192
- break
193
- }
176
+ var statusMetric float64
177
+ switch status .String {
178
+ case "stopped" :
179
+ statusMetric = 0.0
180
+ break
181
+ case "starting" :
182
+ statusMetric = 1.0
183
+ break
184
+ case "streaming" :
185
+ statusMetric = 2.0
186
+ break
187
+ case "waiting" :
188
+ statusMetric = 3.0
189
+ break
190
+ case "restarting" :
191
+ statusMetric = 4.0
192
+ break
193
+ case "stopping" :
194
+ statusMetric = - 1.0
195
+ break
196
+ default :
197
+ statusMetric = - 2.0
198
+ break
199
+ }
200
+
201
+ if ! receiveStartLsn .Valid {
202
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because receive_start_lsn is null" )
203
+ continue
204
+ }
205
+ if ! receiveStartTli .Valid {
206
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because receive_start_tli is null" )
207
+ continue
208
+ }
209
+ if hasFlushedLSN && ! flushedLsn .Valid {
210
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because flushed_lsn is null" )
211
+ continue
212
+ }
213
+ if ! receivedTli .Valid {
214
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because received_tli is null" )
215
+ continue
216
+ }
217
+ if ! lastMsgSendTime .Valid {
218
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because last_msg_send_time is null" )
219
+ continue
220
+ }
221
+ if ! lastMsgReceiptTime .Valid {
222
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because last_msg_receipt_time is null" )
223
+ continue
194
224
}
225
+ if ! latestEndLsn .Valid {
226
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because latest_end_lsn is null" )
227
+ continue
228
+ }
229
+ if ! latestEndTime .Valid {
230
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because latest_end_time is null" )
231
+ continue
232
+ }
233
+ if ! upstreamNode .Valid {
234
+ level .Debug (c .log ).Log ("msg" , "Skipping wal receiver stats because upstream_node is null" )
235
+ continue
236
+ }
237
+
238
+ receiveStartLsnMetric := float64 (receiveStartLsn .Int64 )
195
239
ch <- prometheus .MustNewConstMetric (
196
240
statWalReceiverStatus ,
197
241
prometheus .GaugeValue ,
198
242
statusMetric ,
199
243
labels ... )
200
244
201
- receiveStartLsnMetric := 0.0
202
- if receiveStartLsn .Valid {
203
- receiveStartLsnMetric = float64 (receiveStartLsn .Int64 )
204
- }
205
245
ch <- prometheus .MustNewConstMetric (
206
246
statWalReceiverReceiveStartLsn ,
207
247
prometheus .CounterValue ,
208
248
receiveStartLsnMetric ,
209
249
labels ... )
210
250
211
- receiveStartTliMetric := 0.0
212
- if receiveStartTli .Valid {
213
- receiveStartTliMetric = float64 (receiveStartTli .Int64 )
214
- }
251
+ receiveStartTliMetric := float64 (receiveStartTli .Int64 )
215
252
ch <- prometheus .MustNewConstMetric (
216
253
statWalReceiverReceiveStartTli ,
217
254
prometheus .GaugeValue ,
218
255
receiveStartTliMetric ,
219
256
labels ... )
220
257
221
258
if hasFlushedLSN {
222
- flushedLsnMetric := 0.0
223
- if flushedLsn .Valid {
224
- flushedLsnMetric = float64 (flushedLsn .Int64 )
225
- }
259
+ flushedLsnMetric := float64 (flushedLsn .Int64 )
226
260
ch <- prometheus .MustNewConstMetric (
227
261
statWalReceiverFlushedLSN ,
228
262
prometheus .CounterValue ,
229
263
flushedLsnMetric ,
230
264
labels ... )
231
265
}
232
266
233
- receivedTliMetric := 0.0
234
- if receivedTli .Valid {
235
- receivedTliMetric = float64 (receivedTli .Int64 )
236
- }
267
+ receivedTliMetric := float64 (receivedTli .Int64 )
237
268
ch <- prometheus .MustNewConstMetric (
238
269
statWalReceiverReceivedTli ,
239
270
prometheus .GaugeValue ,
240
271
receivedTliMetric ,
241
272
labels ... )
242
273
243
- lastMsgSendTimeMetric := 0.0
244
- if lastMsgSendTime .Valid {
245
- lastMsgSendTimeMetric = float64 (lastMsgSendTime .Float64 )
246
- }
274
+ lastMsgSendTimeMetric := float64 (lastMsgSendTime .Float64 )
247
275
ch <- prometheus .MustNewConstMetric (
248
276
statWalReceiverLastMsgSendTime ,
249
277
prometheus .CounterValue ,
250
278
lastMsgSendTimeMetric ,
251
279
labels ... )
252
280
253
- lastMsgReceiptTimeMetric := 0.0
254
- if lastMsgReceiptTime .Valid {
255
- lastMsgReceiptTimeMetric = float64 (lastMsgReceiptTime .Float64 )
256
- }
281
+ lastMsgReceiptTimeMetric := float64 (lastMsgReceiptTime .Float64 )
257
282
ch <- prometheus .MustNewConstMetric (
258
283
statWalReceiverLastMsgReceiptTime ,
259
284
prometheus .CounterValue ,
260
285
lastMsgReceiptTimeMetric ,
261
286
labels ... )
262
287
263
- latestEndLsnMetric := 0.0
264
- if latestEndLsn .Valid {
265
- latestEndLsnMetric = float64 (latestEndLsn .Int64 )
266
- }
288
+ latestEndLsnMetric := float64 (latestEndLsn .Int64 )
267
289
ch <- prometheus .MustNewConstMetric (
268
290
statWalReceiverLatestEndLsn ,
269
291
prometheus .CounterValue ,
270
292
latestEndLsnMetric ,
271
293
labels ... )
272
294
273
- latestEndTimeMetric := 0.0
274
- if latestEndTime .Valid {
275
- latestEndTimeMetric = float64 (latestEndTime .Float64 )
276
- }
295
+ latestEndTimeMetric := float64 (latestEndTime .Float64 )
277
296
ch <- prometheus .MustNewConstMetric (
278
297
statWalReceiverLatestEndTime ,
279
298
prometheus .CounterValue ,
280
299
latestEndTimeMetric ,
281
300
labels ... )
282
301
283
- upstreamNodeMetric := 0.0
284
- if upstreamNode .Valid {
285
- upstreamNodeMetric = float64 (upstreamNode .Int64 )
286
- }
302
+ upstreamNodeMetric := float64 (upstreamNode .Int64 )
287
303
ch <- prometheus .MustNewConstMetric (
288
304
statWalReceiverUpstreamNode ,
289
305
prometheus .GaugeValue ,
0 commit comments