在我的本地 KinD 集群上,我使用默认值文件部署了
kube-prometheus-stack
。 Prometheus 在我的 prometheus
命名空间内配置。
在另一个命名空间
redis
中,我使用以下值文件安装了redis-ha
:
image:
repository: redis/redis-stack-server
tag: 7.2.0-v6
pullPolicy: IfNotPresent
replicas: 1
redis:
config:
protected-mode: "no"
min-replicas-to-write: 0
loadmodule: /opt/redis-stack/lib/redisbloom.so
disableCommands:
- FLUSHALL
exporter:
enabled: true
image: oliver006/redis_exporter
tag: v1.57.0
pullPolicy: IfNotPresent
# prometheus port & scrape path
port: 9121
portName: exporter-port
scrapePath: /metrics
# Address/Host for Redis instance. Default: localhost
# Exists to circumvent issues with IPv6 dns resolution that occurs on certain environments
##
address: localhost
## Set this to true if you want to connect to redis tls port
# sslEnabled: true
# cpu/memory resource limits/requests
resources: {}
# Additional args for redis exporter
extraArgs: {}
serviceMonitor:
# When set true then use a ServiceMonitor to configure scraping
enabled: true
# Set the namespace the ServiceMonitor should be deployed
namespace: "prometheus"
# Set how frequently Prometheus should scrape
interval: 15s
# Set path to redis-exporter telemtery-path
# telemetryPath: /metrics
# Set labels for the ServiceMonitor, use this to define your scrape label for Prometheus Operator
labels:
app: redis-ha
# Set timeout for scrape
# timeout: 10s
# Set additional properties for the ServiceMonitor endpoints such as relabeling, scrapeTimeout, tlsConfig, and more.
endpointAdditionalProperties: {}
# prometheus exporter SCANS redis db which can take some time
# allow different probe settings to not let container crashloop
livenessProbe:
initialDelaySeconds: 15
timeoutSeconds: 3
periodSeconds: 15
readinessProbe:
initialDelaySeconds: 15
timeoutSeconds: 3
periodSeconds: 15
successThreshold: 2
上述值文件创建了以下 ServiceMonitor:
Name: redis-ha
Namespace: prometheus
Labels: app=redis-ha
app.kubernetes.io/managed-by=Helm
chart=redis-ha-4.26.1
heritage=Helm
release=redis-ha
Annotations: meta.helm.sh/release-name: redis-ha
meta.helm.sh/release-namespace: redis
API Version: monitoring.coreos.com/v1
Kind: ServiceMonitor
Metadata:
Creation Timestamp: 2024-02-27T08:45:59Z
Generation: 2
Resource Version: 2036
UID: 44d3e5c7-2ca1-4434-adaa-e29c1e3cb4da
Spec:
Endpoints:
Interval: 15s
Path: /metrics
Target Port: 9121
Job Label: redis-ha
Namespace Selector:
Match Names:
redis
Selector:
Match Labels:
App: redis-ha
Exporter: enabled
Release: redis-ha
Events: <none>
在 Prometheus 中,由于输入
redis
时自动完成,我可以看到与 Redis 相关的指标,但是当我转到“目标”或“服务发现”时,我看不到我的 Redis 导出器。
我检查了 Prometheus 导出器日志,但没有发现任何错误。 redis-exporter 已启动并正在运行,标签似乎匹配。
我不明白为什么我会看到指标而不是目标。
我最终在 Prometheus 设置中更改了
serviceMonitorSelector
和 serviceMonitorNamespaceSelector
以匹配 redis 应用程序的命名空间和标签。我认为将其设置为 {}
会起作用,所以这似乎是一个权限问题。