Files
ljwx-k8s/servicemonitor-template.yaml
2026-02-20 22:50:45 +08:00

56 lines
1.7 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ServiceMonitor 企业标准模板
#
# 用途:所有应用必须在部署清单中包含此配置
# 责任:应用开发团队
# 位置:Helm Chart templates/ 或 Kustomize overlay/
#
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ APP_NAME }} # 替换为应用名
namespace: {{ NAMESPACE }} # 替换为命名空间
labels:
app: {{ APP_NAME }}
release: monitoring # ← 必需!Prometheus Operator 要求
team: {{ TEAM_NAME }} # 可选:团队标识
spec:
# 选择要监控的 Service
selector:
matchLabels:
app: {{ APP_NAME }}
# 采集端点配置
endpoints:
- port: http # Service 的 port.name
interval: 30s # 采集间隔
scrapeTimeout: 10s # 采集超时
# Metrics 路径(根据技术栈选择):
# - Spring Boot: /actuator/prometheus
# - Python/FastAPI: /metrics
# - Go: /metrics
# - Node.js: /metrics
path: /metrics
# 可选:Metric 重标签
# metricRelabelings:
# - sourceLabels: [__name__]
# regex: "go_.*"
# action: drop # 丢弃 go_ 开头的指标
---
# 配置检查清单:
#
# ✅ metadata.labels.release: monitoring 是否存在?
# ✅ spec.selector 是否匹配 Service labels?
# ✅ spec.endpoints.port 是否与 Service port.name 一致?
# ✅ spec.endpoints.path 是否正确?
# ✅ 是否已在 Git 仓库中版本控制?
#
# 验证命令:
# kubectl get servicemonitor {{ APP_NAME }} -n {{ NAMESPACE }}
# kubectl describe servicemonitor {{ APP_NAME }} -n {{ NAMESPACE }}
#
# Prometheus Target 验证:
# curl http://prometheus:9090/api/v1/targets | jq '.data.activeTargets[] | select(.labels.job == "{{ APP_NAME }}")'