prometheus의 단점은 polling방식의 수집으로 인해서, 새로운 exporter가 추가될 경우, prometheus서버의 config 또는 configmap의 해당 exporter수집경로를 등록하고, prometheus를 재시작해야한다는점이다.
prometheus operator를 통해서 해결할수있다.
기존에는 app -> exporter -> prometehus서버 순으로 수집된다면,
app->exporter->servicemonitor->prometheus 서버로 수집된다.
조금더 보면
servicemonitor는 k8s CRD 리소스로 샘플 매니페스트는 다음과같다.
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: example-app
labels:
team: frontend
spec:
selector:
matchLabels:
app: example-app
endpoints:
-port: web
이 servicemonitor는 selector에 입력된 label을 가지고 있는 모든 k8s 서비스 리소스에서 metric을 수집하게된다.
이때 port는 web이라는 이름으로된 port로 접근하게 된다.
servicemonitor는 서비스를 통해 대상pod의 ip를 알아내고 이걸가지고 prometheus서버에 알려주게되어
prometheus서버에 등록된 endpoint는 pod ip:port가 된다.
*참고: servicemonitor외에 prometheus operator는 podmonitor도 지원하는데, 차이는, 특정 label을 가진 모든 서비스가 아닌 pod을 선택한다는 점이다. k8s api를 통해 이 라벨을 가진 모든 pod정보를 알아내어 prometheus서버에 전달한다.
그렇게 prometheus서버는 저장된 pod ip목록을 가지고 해당 pod io:port/metrics 경로에서 metric을 polling하게된다.
'k8s 및 인프라 > prometheus' 카테고리의 다른 글
prometheus operator- alertmanagerConfig (0) | 2024.03.30 |
---|---|
prometheus operator (0) | 2024.03.16 |
grafana metric 수집이슈 (0) | 2024.03.15 |