部署 Kafka-exporter
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka-exporter
namespace: monitoring
labels:
app: kafka-exporter
spec:
selector:
matchLabels:
app: kafka-exporter
template:
metadata:
labels:
app: kafka-exporter
spec:
containers:
- name: kafka-exporter
image: danielqsj/kafka-exporter:latest
imagePullPolicy: IfNotPresent
args: ["--kafka.server=10.0.1.235:9092"]
---
apiVersion: v1
kind: Service
metadata:
labels:
app: kafka-exporter
name: kafka-exporter
namespace: monitoring
spec:
type: ClusterIP
ports:
- name: api
port: 9308
protocol: TCP
targetPort: 9308
selector:
app: kafka-exporter
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app.kubernetes.io/name: kafka-exporter
app.kubernetes.io/part-of: kube-prometheus
name: kafka-exporter
namespace: monitoring
spec:
endpoints:
- honorLabels: true
interval: 30s
path: /metrics
port: api
scheme: http
namespaceSelector:
matchNames:
- monitoring
selector:
matchLabels:
app: kafka-exporter
KafkaRule 规则
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
labels:
app.kubernetes.io/name: kafka-exporter-rule
prometheus: k8s
role: alert-rules
name: kafka-exporter-rule
namespace: monitoring
spec:
groups:
- name: kafka-exporter-rule
rules:
- alert: kafka有消息未被消费
expr: |
kafka_consumergroup_lag_sum > 300
for: 2m
labels:
level: warning
annotations:
value: "{{ $value }}"
unit: ""