Prometheus가 많아질수록 Datasource도 점점 많아진다.
Datasource가 많아지면 Grafana에서 metrics 조회 쿼리를 작성할 경우
조건에 따라 매번 다른 Datasource를 선택해줘야 하기 때문에 굉장히 번거롭다.
이런 불편함을 해소하기 위한 방법으론
여러 child prometheus의 datasource를 parents prometheus datasource가 스크랩을 하면
parents datasource에서 모든 child의 datasource를 사용할 수 있다.
(명칭이 맞는지 모르겠으나 간편하게 표시하기 위해 chid, parent라는 표현을 쓰도록 하겠다)
그림을 통해 보면 child, parents 구성은 아래와 같다.
물론 같은 서버에서 prometheus를 중복으로 설치도 가능하다.
단 port를 다르게 지정해야 하면 가능하다.
통합 Prometheus를 사용하기 위해선 config에 federate라는 옵션을 설정해 주면 된다.
프로메테우스 공식 홈페이지에 나와있는 config 사용 방법이다.
scrape_configs:
- job_name: 'federate'
scrape_interval: 15s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="prometheus"}'
- '{__name__=~"job:.*"}'
static_configs:
- targets:
- 'source-prometheus-1:9090'
- 'source-prometheus-2:9090'
- 'source-prometheus-3:9090'
그럼 해당 내용을 적용해서 통합 prometheus를 만들어보자.
Child Prometheus Config
scrape_configs:
- job_name: 'child1'
scrape_interval: 15s
static_configs:
- targets: ['serverip:port']
labels:
instance: server-001
- targets: ['serverip:port']
labels:
instance: server-002
- targets: ['serverip:port']
labels:
instance: server-003
.....
원하는 target을 하나의 job_name에 추가하면 된다
Parents Prometheus Config
- job_name: 'combine'
scrape_interval: 15s
honor_labels: true
metrics_path: '/federate'
params:
'match[]':
- '{job="child1"}'
- '{job="child2"}'
- '{job="child3"}'
.....
{원하는 job을 넣어주면 된다}
- '{__name__=~"job:.*"}'
static_configs:
- targets:
- '{prometheus_child_ip:port}'
- '{prometheus_child_ip:port}'
labels:
alias : child1
- targets:
- '{prometheus_child_ip:port}'
- '{prometheus_child_ip:port}'
labels:
alias : child2
job은 Prometheus status에 Target을 누르면 확인 가능하고
원하는 job만 추가해서 사용도 가능하다.
parents config를 보면 alias를 통해 구분값을 줬는데
이렇게 구분하면 grafana에서 metrics 조회 query를 작성할 때 구분하기 편하다.
'모니터링(Grafana, Prometheus) > Prometheus' 카테고리의 다른 글
통합 Prometheus federate 옵션 사용 시 metrics 보관 주기 (0) | 2023.07.14 |
---|---|
한 서버에 prometheus n개 설치하기 (0) | 2023.07.05 |
Prometheus 이슈 및 troubleshooting (0) | 2023.05.04 |
Prometheus metric 보관 주기 변경 (0) | 2023.05.03 |
Prometheus Helm 설치 (0) | 2023.05.01 |