redis

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

README

Redis 插件文档

这个目录包含 Redis 插件的实现代码、配置示例,以及面向单机 Redis 和 Redis 集群的验证资产。

文档索引

代码结构

文件 作用
redis.go 包入口与插件注册
types.go 常量定义,以及 Plugin / Instance / Partial 结构体
config.go partial 合并、Init 校验与配置归一化
gather.go 多目标采集、单目标流程与卡死处理
checks.go 节点级检查,例如角色、内存、持久化
cluster.go 集群相关检查与拓扑解析
accessor.go Redis 连接、RESP 协议处理与 INFO 解析
diagnose.go AI 诊断工具、预采集器与诊断提示
redis_test.go 基于 fake Redis server 的单元测试
diagnose_test.go 诊断工具注册与行为测试
redis_integration_test.go 通过 integration 构建标签启用的集成测试

插件覆盖范围

  • 单机 Redis 和主从部署
  • 使用保守默认策略的 Redis 集群硬故障检查
  • 可选的业务相关检查,例如复制延迟和 maxmemory 使用率
  • 面向集群拓扑和大 key 的按需诊断工具

插件明确不做的事

  • 不替代 redis-exporter
  • 不暴露 Prometheus 指标
  • 不执行 SCANMEMORY USAGE 这类周期性重扫描
  • 默认不假设必须满足某种拓扑策略,例如固定副本数

Documentation

Overview

Package redis provides a catpaw remote plugin for monitoring Redis instances across standalone, master/replica, and Redis Cluster deployments. It is the reference implementation for remote plugins that need accessor-based collection, partial config reuse, multi-target gather, AI diagnosis tools, and conservative default checks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterStateCheck added in v0.19.0

type ClusterStateCheck struct {
	Disabled *bool  `toml:"disabled"`
	Severity string `toml:"severity"`
}

type ClusterTopologyCheck added in v0.19.0

type ClusterTopologyCheck struct {
	Disabled *bool `toml:"disabled"`
}

type ConnectivityCheck

type ConnectivityCheck struct {
	Severity string `toml:"severity"`
}

type CountCheck

type CountCheck struct {
	WarnGe     int `toml:"warn_ge"`
	CriticalGe int `toml:"critical_ge"`
}

type Instance

type Instance struct {
	config.InternalConfig
	Partial string `toml:"partial"`

	Targets          []string             `toml:"targets"`
	Concurrency      int                  `toml:"concurrency"`
	Timeout          config.Duration      `toml:"timeout"`
	ReadTimeout      config.Duration      `toml:"read_timeout"`
	Username         string               `toml:"username"`
	Password         string               `toml:"password"`
	DB               int                  `toml:"db"`
	Mode             string               `toml:"mode"`
	ClusterName      string               `toml:"cluster_name"`
	Connectivity     ConnectivityCheck    `toml:"connectivity"`
	ResponseTime     ResponseTimeCheck    `toml:"response_time"`
	Role             RoleCheck            `toml:"role"`
	ReplLag          ReplLagCheck         `toml:"repl_lag"`
	ConnectedClients CountCheck           `toml:"connected_clients"`
	BlockedClients   CountCheck           `toml:"blocked_clients"`
	UsedMemory       MemoryUsageCheck     `toml:"used_memory"`
	UsedMemoryPct    PercentCheck         `toml:"used_memory_pct"`
	RejectedConn     CountCheck           `toml:"rejected_connections"`
	MasterLink       MasterLinkCheck      `toml:"master_link_status"`
	ConnectedSlaves  MinCountCheck        `toml:"connected_slaves"`
	EvictedKeys      CountCheck           `toml:"evicted_keys"`
	ExpiredKeys      CountCheck           `toml:"expired_keys"`
	OpsPerSecond     OpsPerSecondCheck    `toml:"instantaneous_ops_per_sec"`
	Persistence      PersistenceCheck     `toml:"persistence"`
	ClusterState     ClusterStateCheck    `toml:"cluster_state"`
	ClusterTopology  ClusterTopologyCheck `toml:"cluster_topology"`

	tlscfg.ClientConfig
	// contains filtered or unexported fields
}

func (*Instance) Gather

func (ins *Instance) Gather(q *safe.Queue[*types.Event])

func (*Instance) Init

func (ins *Instance) Init() error

type MasterLinkCheck

type MasterLinkCheck struct {
	Expect   string `toml:"expect"`
	Severity string `toml:"severity"`
}

type MemoryUsageCheck

type MemoryUsageCheck struct {
	WarnGe     config.Size `toml:"warn_ge"`
	CriticalGe config.Size `toml:"critical_ge"`
}

type MinCountCheck

type MinCountCheck struct {
	WarnLt     int `toml:"warn_lt"`
	CriticalLt int `toml:"critical_lt"`
}

type OpsPerSecondCheck

type OpsPerSecondCheck struct {
	WarnGe     int `toml:"warn_ge"`
	CriticalGe int `toml:"critical_ge"`
}

type Partial

type Partial struct {
	ID          string          `toml:"id"`
	Concurrency int             `toml:"concurrency"`
	Timeout     config.Duration `toml:"timeout"`
	ReadTimeout config.Duration `toml:"read_timeout"`
	Username    string          `toml:"username"`
	Password    string          `toml:"password"`
	DB          int             `toml:"db"`
	Mode        string          `toml:"mode"`
	ClusterName string          `toml:"cluster_name"`
	tlscfg.ClientConfig
	Connectivity     ConnectivityCheck    `toml:"connectivity"`
	ResponseTime     ResponseTimeCheck    `toml:"response_time"`
	Role             RoleCheck            `toml:"role"`
	ReplLag          ReplLagCheck         `toml:"repl_lag"`
	ConnectedClients CountCheck           `toml:"connected_clients"`
	BlockedClients   CountCheck           `toml:"blocked_clients"`
	UsedMemory       MemoryUsageCheck     `toml:"used_memory"`
	UsedMemoryPct    PercentCheck         `toml:"used_memory_pct"`
	RejectedConn     CountCheck           `toml:"rejected_connections"`
	MasterLink       MasterLinkCheck      `toml:"master_link_status"`
	ConnectedSlaves  MinCountCheck        `toml:"connected_slaves"`
	EvictedKeys      CountCheck           `toml:"evicted_keys"`
	ExpiredKeys      CountCheck           `toml:"expired_keys"`
	OpsPerSecond     OpsPerSecondCheck    `toml:"instantaneous_ops_per_sec"`
	Persistence      PersistenceCheck     `toml:"persistence"`
	ClusterState     ClusterStateCheck    `toml:"cluster_state"`
	ClusterTopology  ClusterTopologyCheck `toml:"cluster_topology"`
}

type PercentCheck added in v0.19.0

type PercentCheck struct {
	WarnGe     int `toml:"warn_ge"`
	CriticalGe int `toml:"critical_ge"`
}

type PersistenceCheck

type PersistenceCheck struct {
	Enabled  *bool  `toml:"enabled"`
	Severity string `toml:"severity"`
}

type RedisAccessor

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

RedisAccessor encapsulates a Redis connection and provides structured data access. It handles connection, authentication, protocol interaction, and response parsing. Thread-unsafe: callers must synchronize concurrent use.

func NewRedisAccessor

func NewRedisAccessor(cfg RedisAccessorConfig) (*RedisAccessor, error)

NewRedisAccessor creates a connected and authenticated RedisAccessor.

func (*RedisAccessor) ClientList

func (a *RedisAccessor) ClientList() (string, error)

ClientList executes CLIENT LIST and returns the raw response.

func (*RedisAccessor) Close

func (a *RedisAccessor) Close() error

Close releases the underlying TCP connection.

func (*RedisAccessor) ClusterInfo added in v0.19.0

func (a *RedisAccessor) ClusterInfo() (string, error)

ClusterInfo executes CLUSTER INFO and returns the raw output.

func (*RedisAccessor) ClusterNodes added in v0.19.0

func (a *RedisAccessor) ClusterNodes() (string, error)

ClusterNodes executes CLUSTER NODES and returns the raw topology output.

func (*RedisAccessor) Command

func (a *RedisAccessor) Command(args ...string) (string, error)

Command executes an arbitrary Redis command and returns the string reply. For use by diagnostic tools that need flexible access.

func (*RedisAccessor) ConfigGet

func (a *RedisAccessor) ConfigGet(pattern string) (string, error)

ConfigGet executes CONFIG GET <pattern> and returns the raw key-value pairs. Sensitive fields (passwords, auth keys) are redacted.

func (*RedisAccessor) DBSize

func (a *RedisAccessor) DBSize() (string, error)

DBSize executes DBSIZE and returns the reply.

func (*RedisAccessor) Info

func (a *RedisAccessor) Info(section string) (map[string]string, error)

Info executes INFO <section> and returns the parsed key-value map.

func (*RedisAccessor) InfoRaw

func (a *RedisAccessor) InfoRaw(section string) (string, error)

InfoRaw executes INFO <section> and returns the raw string output.

func (*RedisAccessor) Ping

func (a *RedisAccessor) Ping() error

Ping sends PING and returns nil if the reply is PONG.

func (*RedisAccessor) RawCommand added in v0.19.0

func (a *RedisAccessor) RawCommand(args ...string) (any, error)

RawCommand executes an arbitrary Redis command and returns the parsed RESP value. Intended for diagnostic helpers that need structured replies such as SCAN.

func (*RedisAccessor) SlowlogGet

func (a *RedisAccessor) SlowlogGet(count int) (string, error)

SlowlogGet executes SLOWLOG GET <count> and returns the raw response.

func (*RedisAccessor) Target

func (a *RedisAccessor) Target() string

Target returns the target address this accessor is connected to.

type RedisAccessorConfig

type RedisAccessorConfig struct {
	Target      string
	Username    string
	Password    string
	DB          int
	Timeout     time.Duration
	ReadTimeout time.Duration
	TLSConfig   *tls.Config
	DialFunc    func(network, address string) (net.Conn, error)
}

RedisAccessorConfig holds the connection parameters for creating a RedisAccessor.

type RedisPlugin

type RedisPlugin struct {
	config.InternalConfig
	Partials  []Partial   `toml:"partials"`
	Instances []*Instance `toml:"instances"`
}

func (*RedisPlugin) ApplyPartials

func (p *RedisPlugin) ApplyPartials() error

func (*RedisPlugin) GetInstances

func (p *RedisPlugin) GetInstances() []plugins.Instance

func (*RedisPlugin) RegisterDiagnoseTools

func (p *RedisPlugin) RegisterDiagnoseTools(registry *diagnose.ToolRegistry)

RegisterDiagnoseTools implements plugins.Diagnosable for RedisPlugin. It registers read-only diagnostic tools and the accessor factory.

type ReplLagCheck added in v0.19.0

type ReplLagCheck struct {
	WarnGe     config.Size `toml:"warn_ge"`
	CriticalGe config.Size `toml:"critical_ge"`
}

type ResponseTimeCheck

type ResponseTimeCheck struct {
	WarnGe     config.Duration `toml:"warn_ge"`
	CriticalGe config.Duration `toml:"critical_ge"`
}

type RoleCheck

type RoleCheck struct {
	Expect   string `toml:"expect"`
	Severity string `toml:"severity"`
}

Jump to

Keyboard shortcuts

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