Servicemonitor Concept
ServiceMonitorService 오브젝트에서 Endpoints 를 검색하고 해당 Pod를 모니터링하도록 Prometheus를 구성하는 Prometheus Operator에서 제공하는 사용자 정의 리소스임.
# Service targeting gitlab instances
apiVersion: v1
kind: Service
metadata:
name: test-metrics
labels:
app: test-app
spec:
ports:
- name: metrics # expose metrics port
port: 9109 # defined in port
targetPort: metrics
protocol: TCP
selector:
app: test-app # target app label
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: testapp-servicemonitor
# Change this to the namespace the Prometheus instance is running in
# namespace: default
labels:
app: test-app
release: prometheus
spec:
selector:
matchLabels:
app: test-app # target gitlab service
endpoints:
- port: metrics
interval: 15s # scrape interval