Debian Codegraph @

CLAUDE.md

raw symbols SCIP
1 # Redis Exporter - Project Summary
2
3 ## Overview
4 Prometheus exporter for Redis, Sentinel, Cluster, Dragonfly, Valkey, and Tile38. Written in Go using `gomodule/redigo` for Redis and `prometheus/client_golang` for metrics.
5
6 ## Architecture
7
8 **Entry point:** `main.go` → creates `Exporter` struct → registers with Prometheus → starts HTTP server.
9
10 **Scrape flow:** HTTP request → `Collect()` → `scrapeRedisHost()` → connect → `CONFIG GET` → `INFO ALL` → feature-specific commands → register metrics.
11
12 **Key struct:** `Exporter` implements `prometheus.Collector` (Describe/Collect) and `http.Handler`.
13
14 ## Exporter Directory Structure
15
16 | File | Purpose |
17 |------|---------|
18 | `exporter.go` | Core: Exporter struct, Options, Collect(), scrapeRedisHost(), metric registration |
19 | `redis.go` | Connection helpers: connectToRedis(), connectToRedisCluster(), configureOptions() |
20 | `info.go` | INFO ALL parsing: extractInfoMetrics(), extractConfigMetrics(), commandstats, latencystats |
21 | `keys.go` | Key inspection: check-keys, check-single-keys, count-keys, pipelined batch operations |
22 | `streams.go` | XINFO STREAM/GROUPS/CONSUMERS metrics |
23 | `key_groups.go` | SCAN-based key grouping with memory analysis |
24 | `clients.go` | CLIENT LIST parsing with IPv4/IPv6 support |
25 | `sentinels.go` | Sentinel master/slave/sentinel metrics, ckquorum |
26 | `metrics.go` | Metric description helpers, counter/gauge map definitions |
27 | `http.go` | HTTP handlers: /metrics, /scrape, /health, /-/reload, /discover-cluster-nodes |
28 | `tls.go` | TLS config: client certs, CA loading, skip verification |
29 | `pwd_file.go` | JSON password file loading (URI→password map) |
30 | `nodes.go` | Cluster node discovery from CLUSTER INFO |
31 | `modules.go` | Redis module metrics from INFO MODULES |
32 | `search_indexes.go` | RediSearch FT._LIST / FT.INFO metrics |
33 | `slowlog.go` | SLOWLOG GET metrics |
34 | `latency.go` | LATENCY LATEST and LATENCY HISTOGRAM |
35 | `lua.go` | Custom Lua script execution via EVAL |
36 | `tile38.go` | Tile38-specific metrics |
37
38 ## Key Configuration (Options struct)
39
40 - **Auth:** User/Password, PasswordMap, RedisPwdFile, HTTP BasicAuth (bcrypt support)
41 - **TLS:** ClientCert/Key, CACert, SkipTLSVerification
42 - **Metric toggles:** InclConfigMetrics, InclModulesMetrics, InclSearchIndexesMetrics, InclSystemMetrics, ExportClientList
43 - **Key inspection:** CheckKeys, CheckSingleKeys, CheckStreams, CountKeys, CheckKeyGroups (with MaxDistinctKeyGroups)
44 - **Performance:** CheckKeysBatchSize (pipelining), ConnectionTimeouts, SkipCheckKeysForRoleMaster
45 - **DB type:** IsCluster, IsTile38; Valkey/Dragonfly auto-detected via URL scheme
46
47 ## HTTP Endpoints
48
49 - `/metrics` - Standard Prometheus scrape
50 - `/scrape?target=<uri>` - Dynamic single-target scraping (supports query param overrides)
51 - `/health` - Health check
52 - `/-/reload` - Reload password file
53 - `/discover-cluster-nodes` - JSON cluster node list for Prometheus relabeling
54
55 ## Notable Design Decisions
56
57 - **Pipelining:** Batched key operations for non-cluster; sequential for cluster mode
58 - **Role-aware:** Detects master/slave from INFO; can skip key checks on master
59 - **Keyspace parsing:** Supports 4-6 fields for Redis/Dragonfly/Valkey compatibility
60 - **URL normalization:** `valkey://` → `redis://`, `valkeys://` → `rediss://`
61 - **Error resilience:** Individual metric errors don't abort the scrape
62 - **Metric registration:** Two-phase (descriptions at init, values at scrape) with dynamic metrics for command stats, key names, etc.
63
64 ## Testing
65
66 19 test files. Integration tests use `TEST_REDIS_URI` env var for live Redis instances. Covers parsing, HTTP handlers, cluster, sentinel, streams, key groups, search indexes, and client list (IPv6, RESP versions).
67
68 ## Build & Run
69
70 ```bash
71 go build .
72 ./redis_exporter --redis.addr=redis://localhost:6379
73 ```
74
75 Key flags: `--redis.addr`, `--redis.password`, `--check-keys`, `--check-streams`, `--is-cluster`, `--tls-client-cert-file`, `--lua-script`, `--namespace`