[프로메테우스] Docker로, Prometheus 설치 및 설정

91Savage·2022년 11월 1일
0

Server

목록 보기
4/24

Docker

  • 컨테이너 기반의 가상화 툴
  • 개발 환경이 맞지 않더라도 손쉽게 배포 가능
  • 호스트 시스템의 커널 사용
  • 기타 바이너리와 라이브러리 등은 이미지를 통해 가상화

docker run

새로운 컨테이너에서 해당명령어를 실행

-d, --detach : 백그라운드에서 컨테이너 실행 및 컨테이너 ID 출력
--name : 컨테이너 이름 할당
--network : 컨테이너를 네트워크에 연결
-v, --volume: 컨테이너 볼륨을 호스트 볼륨에 바인딩

docker ps

컨테이너 목록 출력
-a, -all 전부

docker logs

로그 출력
-f, --follow 로그 추적

docker restart

하나 이상의 컨테이너 재시작

docker rm

제거
-f, --force 강제 제거

Prometheus

--config.file

설정 파일 경로

--storage.tsdb.path

메트릭 저장소 경로

--web.enable-lifecycle

HTTP 통신을 통한 Prometheus reload 및 shutdown 활성화

파티션 효율적 관리

--storage.tsdb.retention.time

얼마나 오랫동안 데이터를 유지할지

--storage.tsdb.retention.size

보존 할 수 있는 데이터의 크기를 제한 할 수 있다, 지정된 용량이 초과되면 이전 데이터는 자동으로 삭제됨.

--log.level

지정된 단계 이상으로 로그를 보임 [debug, info, warn, error]

[도커로 프로메테우스 설치]

  • cd /prometheus/config
  • vim prometheus.yml

yml 파일은 들여쓰기 잘못하면 오류나서 안됨;; 꼭 지키기

scrape_configs:
      - job_name: 'prometheus'
        scrape_interval: 3s
        scrape_timeout: 1s
        static_configs:
        - targets:
          - localhost:9090
  • docker run --rm prom/prometheus:v2.29.2

  • docker exec -it zen_wu sh ("zen_wu" 는 tab쳐서 나오 것 )

 - /prometheus $
 - /prometheus $ id
 - UID=65534(nobody) gid=65534(nobody) // 디렉토리 권한설정을 사용자와 맞춰줘야함

Prometheus 컨테이너 내부 접근

docker exec -it prometheus /bin/bash

이전에 어떤 옵션으로 설치되었는지 확인 하고싶으면

docker inspect prometheus

설치 및 환경 설정

docker run \
-d --name=prometheus \
--net=host \
-v /prometheus/config:/etc/prometheus \
-v /prometheus/data:/data \
prom/prometheus:v2.29.2 \
--config.file=/etc/prometheus/prometheus.yml \
--storage.tsdb.path=/data
  • -d 백그라운드 실행
  • --name 이름
  • -v 데이터 유실 피하기 위해

c0e5e113da4ef30c96f4069ff548fc55a48e73e5b756ce1197349f416bf1108c

  • docker logs -f prometheus

prometheus 시작

  • docker start prometheus

-------------에러날떄 도커 stop & delete 후 다시 시작-----------
https://blog.d0ngd0nge.xyz/docker-container/

API 참고

https://prometheus.io/docs/prometheus/latest/management_api/

[Health check]
curl localhost:9090/-/healthy -D /dev/stdout
[Readiness check]
curl localhost:9090/-/ready -D /dev/stdout

[Reload, Quit] 은 403 에러.
--web.enable-lifecycle 추가하고 다시실행

[Reload] restart 하지 않고도 prometheus 설정 변경

docker 제거

  • docker rm -f prometheus

docker 재시작 (--web.enable-lifecycle 추가)

docker run -d --name=prometheus --net=host -v /prometheus/config:/etc/prometheus -v /prometheus/data:/data prom/prometheus:v2.29.2 --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data --web.enable-lifecycle

curl localhost:9090/-/reload -XPOST -D /dev/stdout

HTTP/1.1 200 OK

config 체크

[Public IP]
http://xxx.xxx.xxx.xxx:9090/config

retention // 보관주기

  • docker logs -f prometheus 2>&1 | grep retention
    리텐션은 설정하지 않으면 default로 15일 주기임 -> 20일로 변경 하기
docker run -d --name=prometheus --net=host -v /prometheus/config:/etc/prometheus -v /prometheus/data:/data prom/prometheus:v2.29.2 --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data --web.enable-lifecycle --storage.tsdb.retention.time=20d
  • docker logs -f prometheus 2>&1 | grep retention
  • docker logs -f prometheus 2>&1 | grep info
  • docker logs -f prometheus 2>&1 | grep error

에러가 뜨지 않음.

에러 로그 설정

--log.level=debug 로 변경

docker run -d --name=prometheus --net=host -v /prometheus/config:/etc/prometheus -v /prometheus/data:/data prom/prometheus:v2.29.2 --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/data --web.enable-lifecycle --storage.tsdb.retention.time=20d --log.level=debug

0개의 댓글