반응형
Notice
Recent Posts
Recent Comments

05-07 13:04
관리 메뉴

SaevOps

[Docker] Prometheus + (Node Exporter) + Grafana 본문

클라우드/Docker

[Docker] Prometheus + (Node Exporter) + Grafana

세브웁스 2022. 6. 22. 16:00
반응형
Prometheus + (Node Exporter)  + Grafana + Docker

 

본 과정은 CentOS7 / Docker 환경에서 컨테이너로 프로메테우스와 그라파나를 연동하는 방식

Docker는 설치되어 있다는 가정하에 글 작성

클라우드 환경의 경우 포스팅되어있는 방화벽 해제 방법뿐만 아니라 정책 수정까지 해줘야함

 

  • 9090 포트 : Prometheus
  • 9100 포트 : Node Exporter
  • 3000 포트 : Grafana

1. Docker에 Promethus 설치

 1-1. Promethus 폴더 생성 및 yml파일 작성

# Selinux 해제
setenforce 0

mkdir /etc/prometheus
cd /etc/prometheus
vi prometheus.yml

# prometheus.yml 내용

global:
  scrape_interval:     15s # By default, scrape targets every 15 seconds.

  # Attach these labels to any time series or alerts when communicating with
  # external systems (federation, remote storage, Alertmanager).
  external_labels:
    monitor: 'codelab-monitor'

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # Override the global default and scrape targets from this job every 5 seconds.
    scrape_interval: 5s

    static_configs:
      - targets: ['사용자IP:9090']

  - job_name: 'node'
    static_configs:
      - targets: ['사용자IP:9100']

# 가끔 connection refuse라고 에러가 뜰 경우가 있는데 이건 사용자 IP를 localhost라고 했을 때 뜨는 오류

localhost 대신 아이피(Public IP)를 넣어주면 문제없이 넘어가진다. 


1-2. 접속하여 상태 확인

# 도커에 프로메테우스 설치
docker run -d --name prometheus -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

# 방화벽 해제 및 적용
firewall-cmd --permanent --zone=public --add-port=9090/tcp
firewall-cmd --reload

# 홈페이지 열어서 확인
http://사용자IP:9090/targets?search=

1-3. Status - Targets

※ 처음 시도한다면 아직까지 exporter를 설치하지 않은 상태이기 때문에 node의 Endpoint는 Down상태 일 수 있음


2. Docker에 Node Expoter 설치

2-1. Node Exporter 설치 및 방화벽 해제

# 도커에 노드익스포터 설치
docker run -itd -p 9100:9100 --name exporter prom/node-exporter

# 방화벽 해제
firewall-cmd --permanent --zone=public --add-port=9100/tcp
firewall-cmd --reload

2-2. 사용자의 아이피로 접속 후 상태 확인

http://사용자IP:9100/metrics


3. Docker에 Grafana 설치

# 도커에 그라파나 설치
docker run -d -p 3000:3000 grafana/grafana

# 방화벽 해제
firewall-cmd --permanent --zone=public --add-port=3000/tcp
firewall-cmd --reload

4. 그라파나 접속

3-1. 로그인 ( 아이디/비밀번호 : admin / admin )


5. Prometheus - Grafana 연동

 

  • 홈 - Add your first data source 클릭
  • Prometheus 클릭
  • Url 칸에 사용자 아이피 : 9090 입력
  • Save & Test 클릭
  • 대시보드에 마우스 올리고 Import 클릭
  • Url에 https://grafana.com/dashboards/22 입력 후 Load 클릭
  • DataSource에 방금 만든 data source 선택

5-1. 성공적인 모니터링 결과 확인

 


도커로 컨테이너환경에서 그라파나와 프로메테우스를 설치하고 연동하는 것까지 성공했다.

중간에 접근 제한 걸렸을 때 네트워크 쪽에서 Localhost로 사용하지 않으면 해결될 것 같다는 생각을 하고 바로 테스트해봤는데 해결이 잘돼서 뿌듯했다.

사실 도커만 단독적으로 사용하는 게 아닌 쿠버네티스까지 활용해서 구현해보고 싶었는데

아직 쿠버네티스는 초보단계이기 때문에 좀 더 공부하고 다음 포스팅 때 해야겠다.

 

반응형

'클라우드 > Docker' 카테고리의 다른 글

[ Docker ] Grafana Nginx_exporter를 이용한 모니터링  (0) 2022.07.08
[Docker] Nginx  (0) 2022.06.02
[Docker] 기본 명령어  (2) 2022.03.31
Comments