Grafana와 Prometheus 시작하기
Grafana와 Prometheus 시작하기 (Get started with Grafana and Prometheus)
Prometheus는 Grafana가 기본 지원을 제공하는 오픈소스 모니터링 시스템이에요. 이 문서에서는 Prometheus로 모니터링되는 서버의 시스템 메트릭을 표시하는 대시보드 시리즈를 Grafana에서 만드는 단계를 알려드릴게요.
팁: Prometheus Learning Journeys를 확인하세요. Grafana Cloud에서 Prometheus 데이터 소스 연결, Prometheus remote write로 Grafana Cloud에 메트릭 전송이 있어요.
출처: 문서
본문
Grafana와 Prometheus 과정 개요:
- Prometheus와 Node exporter 다운로드
- Prometheus Node exporter 설치
- Prometheus 설치·구성
- Grafana용 Prometheus 구성
- Grafana Explore 뷰에서 Prometheus 메트릭 확인
- 대시보드 구축 시작
Prometheus와 Node exporter 다운로드
Prometheus와 Node exporter를 다운로드하세요. Grafana와 마찬가지로 여러 OS에 설치할 수 있어요.
Prometheus Node exporter 설치
모니터링할 모든 호스트에 Node exporter를 설치하세요. Node exporter는 시스템 메트릭을 노출하는 널리 쓰이는 도구로, 설치 방법은 Prometheus 문서의 Node exporter 설치·실행을 참고하세요. 로컬에서 실행하면 http://localhost:9100/metrics로 메트릭이 내보내지는지 확인할 수 있어요.
참고: 참조된 문서는 Linux 사용자용입니다. OS에 따라 조정할 수 있어요. 예: Windows라면 windows_exporter를 사용하세요.
Prometheus 설치·구성
- 다운로드 후 압축 풀고 디렉터리로 이동:
tar xvfz prometheus-*.tar.gz
cd prometheus-*
- 디렉터리에서
prometheus.yml파일 찾기 - Node exporter를 설치한 호스트를 모니터링하도록 구성 파일 수정
기본적으로 Prometheus는 작업 디렉터리의 prometheus.yml을 찾아요. --config.file 커맨드라인 플래그로 변경할 수 있습니다. 로컬 실행 시 Node exporter를 대상으로 하는 구성 예시:
# A scrape configuration containing exactly one endpoint to scrape from Node exporter running on a host:
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'node'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9100']
- Prometheus 서비스 시작:
./prometheus --config.file=./prometheus.yml
http://localhost:9090로 접속해 실행 확인
Node exporter 메트릭이 Prometheus로 전달됐어요. 다음으로 메트릭을 Grafana로 보냅니다.
Grafana용 Prometheus 구성
로컬 Prometheus를 호스팅된 Grafana Cloud 인스턴스에서 쓰려면:
- grafana.com에 가입. Grafana가 Prometheus 인스턴스를 기본 제공해요.
- 로컬 Prometheus 인스턴스를 운영 중이므로 메트릭을 Grafana.com Prometheus 인스턴스로
remote_write해야 합니다.prometheus.yml에 다음을 추가하세요.
remote_write:
- url: <https://your-remote-write-endpoint>
basic_auth:
username: <your user name>
password: <Your Grafana.com API Key>
참고: Grafana Cloud 대신 로컬 Grafana로 구성하려면 Grafana 다운로드 후 여기의 구성 단계를 따르세요.
문제 해결
1. Prometheus 실행 중인지 확인
- Linux:
sudo systemctl status prometheus - MacOS:
pgrep prometheus - Windows (PowerShell):
Get-Process -Name prometheus -ErrorAction SilentlyContinue
2. Prometheus가 실행되지 않을 때
- 포트 충돌 확인(기본 9090): Linux/MacOS
lsof -i :9090, Windowsnetstat -ano | findstr :9090 - 바이너리 위치 확인:
ls /usr/local/bin/prometheus /usr/local/bin/promtool - PATH 확인:
which prometheus && which promtool - 구성·데이터 파일 확인:
ls /etc/prometheus /var/lib/prometheus,ls /etc/prometheus/prometheus.yml - 권한 확인:
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus - (선택) 전용 사용자 생성:
sudo useradd --no-create-home --shell /bin/false prometheus
3. 서비스로 실행 중인지 확인
- Linux
systemctl status prometheus.service, Windowssc query prometheus, MacOSpgrep prometheus
4. 서비스로 실행되지 않을 때
- 서비스 unit 파일 확인:
sudo nano /etc/systemd/system/prometheus.service—ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/라인의 바이너리 경로·구성 파일·저장 경로 확인 - 재시작·활성화:
sudo systemctl daemon-reload
sudo systemctl enable prometheus
sudo systemctl start prometheus
sudo systemctl status prometheus
- 헬스 확인:
curl -s http://localhost:9090/-/ready - Windows 서비스 재시작:
net stop prometheus/net start prometheus
5. 메트릭 캡처 확인
curl http://localhost:9090/metrics
메트릭과 그 메타데이터를 반환해야 해요.
Grafana Metrics Drilldown에서 Prometheus 메트릭 확인
Grafana 인스턴스에서 Drilldown 뷰로 이동해 쿼리 없이 Prometheus 호환 메트릭을 탐색해 보세요.
대시보드 구축 시작
선별된 쿼리 목록이 있으면 Prometheus가 모니터링하는 시스템 메트릭을 렌더링할 대시보드를 만드세요. Prometheus와 Node exporter/windows_exporter 설치 시 권장 대시보드를 찾을 수 있어요.
더 알아보기: Prometheus 데이터 소스, What is Prometheus?