1. Blackbox Exporter 설치 및 실행
다음 명령어를 사용해 릴리스 파일을 다운로드하고 설치합니다.
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.25.0/blackbox_exporter-0.25.0.linux-amd64.tar.gz
tar xf blackbox_exporter-0.25.0.linux-amd64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv blackbox_exporter-0.25.0.linux-amd64/ blackbox_exporter
시스템 서비스로 등록하기 위해 아래 내용을 /etc/systemd/system/blackbox-exporter.service에 저장합니다.
[Unit]
Description=Prometheus Blackbox Exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \
--config.file=/usr/local/blackbox_exporter/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
서비스를 로드하고 시작하며, 부팅 시 자동 실행되도록 설정합니다.
systemctl daemon-reload
systemctl restart blackbox-exporter.service
systemctl enable blackbox-exporter.service
netstat -tnlp | grep 9115
2. 기본 탐지 기능 및 사용 방법
HTTP 상태 코드 확인은 다음 형식으로 요청합니다.
http://192.168.100.133:9115/probe?target=https://baidu.com&module=http_2xx&debug=true
- target: 검사 대상 주소 (예: 도메인 또는 IP)
- module: 사용할 탐지 방식 (예:
http_2xx,icmp) - debug: 디버그 정보 출력 여부
지원되는 탐지 모듈 목록
http_2xx: HTTP GET 요청 후 200대 응답 코드 확인http_post_2xx: POST 요청 결과 2xx 상태 확인icmp: ICMP 펄스(핑) 통신 상태 검사irc_banner: IRC 서버의 환영 메시지 확인pop3s_banner: POP3S 프로토콜 연결 시 응답 확인ssh_banner: SSH 접속 시 서버 배너 확인tcp_connect: 특정 포트에 대한 연결 가능 여부 테스트
3. Prometheus에서 Blackbox Exporter 연동 설정
Blackbox Exporter는 자체적으로 모니터링할 항목을 제공하지 않으며, Prometheus가 타겟을 전달해야 합니다.
예제 1: URL 상태 모니터링 (HTTP 상태 코드 검사)
- job_name: 'http_status'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://www.xiaomi.com', 'http://www.jd.com/']
labels:
group: web
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.100.134:9115
예제 2: ICMP 기반 네트워크 상태 감시
- job_name: 'icmp_status'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['192.168.100.131', '192.168.100.132']
labels:
group: icmp
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.100.134:9115
예제 3: 원격 포트 연결 상태 점검
- job_name: 'port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.100.131:9100', '192.168.100.132:8080']
labels:
group: port
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 192.168.100.134:9115
설정 파일 검증 및 Prometheus 재로드:
/usr/local/prometheus/promtool check config prometheus.yml
curl -X POST http://127.0.0.1:9090/-/reload
4. Grafana에서 시각화 구성
추천 템플릿: ID 9965
이름 표시 오류 발생 시, instance 레이블을 적절히 조정하거나 쿼리에서 직접 참조하세요.
주요 쿼리 예시
probe_success == 0: 탐색 실패 항목 필터링 (1 = 성공)probe_duration_seconds > 5: 탐색 시간이 5초 이상 소요된 경우probe_dns_lookup_time_seconds > 5: DNS 조회 시간 초과probe_http_status_code >= 400: HTTP 4xx 또는 5xx 오류 발생(probe_ssl_earliest_cert_expiry - time()) / 3600 / 24 < 7: SSL 인증서 유효기간 7일 이내probe_http_duration_seconds{phase="connect"} > 5: HTTP 연결 지연 시간 초과
공식 지원 리스트: https://prometheus.io/docs/instrumenting/exporters/