cAdvisor 메트릭을 Prometheus에 저장하고 Grafana에서 확인
cAdvisor란?
cAdvisor(Container Advisor)는 실행 중인 컨테이너의 리소스와 성능 상황을 알려주는 도구입니다.
Kubernetes의 운영 비용이 높고, 도입하기 어려운 경우에 매우 도움이 될 것 같네요.
Kubernetes에서 cAdvisor는 Kubelet 바이너리에 통합됩니다.
즉, cAdvisor는 kubelet의 일부로 작동하여 CPU, 메모리, 파일 시스템 및 네트워크 사용 통계를 수집합니다.
cAdvisor 설치
다음 명령을 치기만 하면 됩니다.
# docker run --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete
44a45bb65cdf: Pull complete
0bbe1a2fe2a6: Pull complete
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
2bce8b923942a90d8114649d9067abd3daf476b0cec6e6bf4eb6512ade014ca7
확인해 보자.
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bce8b923942 google/cadvisor:latest "/usr/bin/cadvisor -…" 11 seconds ago Up 6 seconds 0.0.0.0:8080->8080/tcp
cAdvisor에 로그인
http://[ip]:8080/containers/에 연결합니다.
이 GUI만으로도 충분할지도 모르는 정도, 제대로 되어 있습니다.

다음은 CPU에 관한 것입니다.

그 외에도 Memory나 Network의 사용률 등을 확인할 수 있습니다.


Prometheus와 협력
설정 파일 편집
job_name: cadvisor
의 부분으로부터를 추가해 주세요.
[cAdvisor IP]는 cAdvisor가 있는 서버의 IP입니다.
port 포워딩을 변경하고 있는 경우는, port 쪽도 변경을 합니다.
prometheus.yml# vi /etc/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets: ['<cAdvisor IP>:8080']
그럼 prometheus를 다시 시작하고 보러 가자.
# systemctl restart prometheus
# systemctl status prometheus
Prometheus GUI
cadvisor_version_info
에서 execute를 선택하여 cAdvisor의 Version 정보가 출력되는지 확인

이것만으로는, 지금 핀과 오지 않으므로, 이하에서도 확인합니다.container_memory_usage_bytes

왠지, 그렇게 되어 왔네요.
Grafana
이제 마지막으로 Grafana에서 dashboard를 만들어 보겠습니다.
왼쪽의 +
버튼에서 Dashboard
를 선택합니다.

그렇다면 Add Query
를 선택하십시오.
방금 사용한 container_memory_usage_bytes
를 사용해보십시오.

title을 붙여 봅시다.

이것을 반복해, 다양한 그래프를 실어 봅시다.
그 밖에도 다음과 같은 메트릭을 사용할 수 있습니다.
다음 명령을 치기만 하면 됩니다.
# docker run --publish=8080:8080 --detach=true --name=cadvisor google/cadvisor:latest
Unable to find image 'google/cadvisor:latest' locally
latest: Pulling from google/cadvisor
ff3a5c916c92: Pull complete
44a45bb65cdf: Pull complete
0bbe1a2fe2a6: Pull complete
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image for google/cadvisor:latest
2bce8b923942a90d8114649d9067abd3daf476b0cec6e6bf4eb6512ade014ca7
확인해 보자.
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2bce8b923942 google/cadvisor:latest "/usr/bin/cadvisor -…" 11 seconds ago Up 6 seconds 0.0.0.0:8080->8080/tcp
cAdvisor에 로그인
http://[ip]:8080/containers/에 연결합니다.
이 GUI만으로도 충분할지도 모르는 정도, 제대로 되어 있습니다.

다음은 CPU에 관한 것입니다.

그 외에도 Memory나 Network의 사용률 등을 확인할 수 있습니다.


Prometheus와 협력
설정 파일 편집
job_name: cadvisor
의 부분으로부터를 추가해 주세요.
[cAdvisor IP]는 cAdvisor가 있는 서버의 IP입니다.
port 포워딩을 변경하고 있는 경우는, port 쪽도 변경을 합니다.
prometheus.yml# vi /etc/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets: ['<cAdvisor IP>:8080']
그럼 prometheus를 다시 시작하고 보러 가자.
# systemctl restart prometheus
# systemctl status prometheus
Prometheus GUI
cadvisor_version_info
에서 execute를 선택하여 cAdvisor의 Version 정보가 출력되는지 확인

이것만으로는, 지금 핀과 오지 않으므로, 이하에서도 확인합니다.container_memory_usage_bytes

왠지, 그렇게 되어 왔네요.
Grafana
이제 마지막으로 Grafana에서 dashboard를 만들어 보겠습니다.
왼쪽의 +
버튼에서 Dashboard
를 선택합니다.

그렇다면 Add Query
를 선택하십시오.
방금 사용한 container_memory_usage_bytes
를 사용해보십시오.

title을 붙여 봅시다.

이것을 반복해, 다양한 그래프를 실어 봅시다.
그 밖에도 다음과 같은 메트릭을 사용할 수 있습니다.
설정 파일 편집
job_name: cadvisor
의 부분으로부터를 추가해 주세요.[cAdvisor IP]는 cAdvisor가 있는 서버의 IP입니다.
port 포워딩을 변경하고 있는 경우는, port 쪽도 변경을 합니다.
prometheus.yml
# vi /etc/prometheus/prometheus.yml
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: cadvisor
scrape_interval: 5s
static_configs:
- targets: ['<cAdvisor IP>:8080']
그럼 prometheus를 다시 시작하고 보러 가자.
# systemctl restart prometheus
# systemctl status prometheus
Prometheus GUI
cadvisor_version_info
에서 execute를 선택하여 cAdvisor의 Version 정보가 출력되는지 확인
이것만으로는, 지금 핀과 오지 않으므로, 이하에서도 확인합니다.
container_memory_usage_bytes

왠지, 그렇게 되어 왔네요.
Grafana
이제 마지막으로 Grafana에서 dashboard를 만들어 보겠습니다.
왼쪽의 +
버튼에서 Dashboard
를 선택합니다.

그렇다면 Add Query
를 선택하십시오.
방금 사용한 container_memory_usage_bytes
를 사용해보십시오.

title을 붙여 봅시다.

이것을 반복해, 다양한 그래프를 실어 봅시다.
그 밖에도 다음과 같은 메트릭을 사용할 수 있습니다.
아직도 많이 있기 때문에, 자신이 원하는 것을 취해 이것이 되는 메트릭을 찾아 보세요.
Reference
이 문제에 관하여(cAdvisor 메트릭을 Prometheus에 저장하고 Grafana에서 확인), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ryojsb/items/ac790241b45c3fbcdd16텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)