This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
63 lines (55 loc) · 1.76 KB
/
example_test.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package promredis_test
import (
"bufio"
"fmt"
"net/http"
"strings"
"time"
"github.com/go-redis/redis/v8"
"github.com/johejo/promredis"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func Example() {
c := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
})
if err := prometheus.Register(promredis.NewPoolStatsCollector(c)); err != nil {
panic(err)
}
go func() {
http.ListenAndServe(":8080", promhttp.Handler())
}()
time.Sleep(1 * time.Second)
resp, err := http.Get("http://localhost:8080")
if err != nil {
panic(err)
}
defer resp.Body.Close()
s := bufio.NewScanner(resp.Body)
for s.Scan() {
line := s.Text()
if strings.Contains(line, "redis") {
fmt.Println(line)
}
}
// Output:
//# HELP go_redis_pool_stats_hits Number of times free connection was found in the pool.
//# TYPE go_redis_pool_stats_hits gauge
//go_redis_pool_stats_hits 0
//# HELP go_redis_pool_stats_idle_conns Number of idle connections in the pool.
//# TYPE go_redis_pool_stats_idle_conns gauge
//go_redis_pool_stats_idle_conns 0
//# HELP go_redis_pool_stats_misses Number of times free connection was NOT found in the pool.
//# TYPE go_redis_pool_stats_misses gauge
//go_redis_pool_stats_misses 0
//# HELP go_redis_pool_stats_stale_conns Number of stale connections removed from the pool.
//# TYPE go_redis_pool_stats_stale_conns gauge
//go_redis_pool_stats_stale_conns 0
//# HELP go_redis_pool_stats_timeouts Number of times a wait timeout occurred.
//# TYPE go_redis_pool_stats_timeouts gauge
//go_redis_pool_stats_timeouts 0
//# HELP go_redis_pool_stats_total_conns Number of total connections in the pool.
//# TYPE go_redis_pool_stats_total_conns gauge
//go_redis_pool_stats_total_conns 0
}