promredis

package module
v0.0.0-...-f5f30d6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2022 License: MIT Imports: 2 Imported by: 0

README

promredis

DEPRECATED Use https://pkg.go.dev/github.com/go-redis/redis/extra/redisprometheus/v9 instead

ci Go Reference codecov Go Report Card

Package promredis exports pool stats of go-redis/redis as prometheus metrics.

Example

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
}

License

MIT

Author

Mitsuo Heijo

Documentation

Overview

Package promredis exports pool stats of go-redis/redis as prometheus metrics.

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPoolStatsCollector

func NewPoolStatsCollector(client PoolStatsClient) prometheus.Collector

NewPoolStatsCollector returns a new collector implements prometheus.Collector.

Types

type PoolStatsClient

type PoolStatsClient interface {
	PoolStats() *redis.PoolStats
}

PoolStatsClient describes a getter for *redis.PoolStats.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL