summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/redis/collect_ping_latency.go
blob: 063673c2c2679e62e02c83d96c1a4f53bd542408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// SPDX-License-Identifier: GPL-3.0-or-later

package redis

import (
	"context"
	"time"
)

func (r *Redis) collectPingLatency(mx map[string]int64) {
	r.pingSummary.Reset()

	for i := 0; i < r.PingSamples; i++ {
		now := time.Now()
		_, err := r.rdb.Ping(context.Background()).Result()
		elapsed := time.Since(now)

		if err != nil {
			r.Debug(err)
			continue
		}

		r.pingSummary.Observe(float64(elapsed.Microseconds()))
	}

	r.pingSummary.WriteTo(mx, "ping_latency", 1, 1)
}