redisprom

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: MIT Imports: 4 Imported by: 3

README

go-redis-prometheus

go-redis hook that exports Prometheus metrics.

Installation

go get github.com/globocom/go-redis-prometheus

Usage

package main

import (
    "github.com/go-redis/redis/v8"
    "github.com/globocom/go-redis-prometheus"
)

func main() {
    hook := redisprom.NewHook(
        redisprom.WithInstanceName("cache"),
        redisprom.WithNamespace("my_namespace"),
        redisprom.WithDurationBuckets([]float64{.001, .005, .01}),
    )

    client := redis.NewClient(&redis.Options{
        Addr:     "localhost:6379",
        Password: "",
    })
    client.AddHook(hook)

    // run redis commands...
}

Exported metrics

The hook exports the following metrics:

  • Single commands (not pipelined):
    • Histogram of commands: redis_single_commands_bucket{instance="main",command="get"}
    • Counter of errors: redis_single_errors{instance="main",command="get"}
  • Pipelined commands:
    • Counter of commands: redis_pipelined_commands{instance="main",command="get"}
    • Counter of errors: redis_pipelined_errors{instance="main",command="get"}

Note on pipelines

It isn't possible to measure the duration of individual pipelined commands, but the duration of the pipeline itself is calculated and exported as a pseudo-command called "pipeline" under the single command metric.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hook

type Hook struct {
	// contains filtered or unexported fields
}

Hook represents a go-redis hook that exports metrics of commands and pipelines.

The following metrics are exported:

- Single commands (not-pipelined)

  • Histogram of duration
  • Counter of errors

- Pipelined commands

  • Counter of commands
  • Counter of errors

The duration of individual pipelined commands won't be collected, but the overall duration of the pipeline will, with a pseudo-command called "pipeline".

func NewHook

func NewHook(opts ...Option) *Hook

NewHook creates a new go-redis hook instance and registers Prometheus collectors.

func (*Hook) AfterProcess

func (hook *Hook) AfterProcess(ctx context.Context, cmd redis.Cmder) error

func (*Hook) AfterProcessPipeline

func (hook *Hook) AfterProcessPipeline(ctx context.Context, cmds []redis.Cmder) error

func (*Hook) BeforeProcess

func (hook *Hook) BeforeProcess(ctx context.Context, cmd redis.Cmder) (context.Context, error)

func (*Hook) BeforeProcessPipeline

func (hook *Hook) BeforeProcessPipeline(ctx context.Context, cmds []redis.Cmder) (context.Context, error)

type Option

type Option func(*Options)

func WithDurationBuckets

func WithDurationBuckets(buckets []float64) Option

WithDurationBuckets sets the duration buckets of single commands metrics.

func WithInstanceName added in v0.2.0

func WithInstanceName(name string) Option

WithInstanceName sets the name of the Redis instance.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the namespace of all metrics.

type Options

type Options struct {
	InstanceName    string
	Namespace       string
	DurationBuckets []float64
}

Options represents options to customize the exported metrics.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default options.

func (*Options) Merge

func (options *Options) Merge(opts ...Option)

Jump to

Keyboard shortcuts

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