from prometheus_client import Gauge, Info, start_http_server
class MetricsAgent:
def __init__(self):
start_http_server(args.pc_port) # 1041
logging.info("starting pcsvr")
파이썬 패키지 prometheus_client를 이용하여 프로메테우스가 메트릭을 폴링해가도록 구현
프로메테우스 클라이언트가 동작하는 서버를 웹 브라우저로 접속하면 현재 쌓인 메트릭들을 볼 수 있음
global:
scrape_interval: 15s # 메트릭 폴링 주기
scrape_configs:
- job_name: "jobmgr" # 메트릭 컬렉션 이름
static_configs:
- targets: ["jobmgr:1041"] # 폴링 대상
./configs/prometheus/prometheus.yml: 프로메테우스 설정 파일
apiVersion: 1
providers:
- name: Prometheus # provider 이름
folder: Monitor # 대시보드가 위치할 폴더 이름
type: file # 대시보드 정보가 json 파일이기 때문에 고정
updateIntervalSeconds: 30 # 대시보드 새로고침 빈도
options:
# 대시보드 파일(json) 위치한 폴더 경로 (type이 file인 경우 필수)
path: /etc/grafana/provisioning/dashboards
./configs/grafana/dashboards/dashboard.yml: 그라파나 설정 파일 (대시보드 자동 생성)
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
access: proxy
url: http://prometheus:9090
./configs/grafana/datasources/datasource.yml: 그라파나 설정 파일 (데이터 소스 자동 생성)
[auth.anonymous]
enabled = true
./configs/grafana/ini/grafana.ini: 그라파나 설정 파일 (계정이 없어도 그라파나 접근 가능)
version: '3'
services:
jobmgr:
...
ports:
- "1041:1041"
prometheus:
image: prom/prometheus:v2.42.0
volumes:
- ./configs/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
grafana:
image: grafana/grafana:9.3.6
volumes:
- ./configs/grafana/datasources:/etc/grafana/provisioning/datasources/
- ./configs/grafana/dashboards:/etc/grafana/provisioning/dashboards/
- ./configs/grafana/ini/grafana.ini:/etc/grafana/grafana.ini
ports:
- "3000:3000"
docker-compose.yml
참고: https://grafana.com/docs/grafana/latest/administration/provisioning/
Provision Grafana | Grafana documentation
Enterprise Open source Provision Grafana In previous versions of Grafana, you could only use the API for provisioning data sources and dashboards. But that required the service to be running before you started creating dashboards and you also needed to set
grafana.com
'도커' 카테고리의 다른 글
[도커] 컨테이너 SSH 포트 변경 및 확인 (0) | 2023.07.29 |
---|---|
[도커] 컨테이너 타임존 설정 (0) | 2022.11.17 |
[도커] 컴포즈 로그 출력 타임 아웃 (0) | 2022.06.23 |
[도커] docker stats 이름순으로 정렬 및 모니터링 (0) | 2022.05.24 |
[도커] 로그 관리 툴 fluentd 설정 (0) | 2022.05.20 |