콘텐츠로 이동

ebpf_exporter - Prometheus를 위한 사용자 정의 커널 메트릭 치트시트

ebpf_exporter - Prometheus를 위한 사용자 정의 커널 메트릭 치트시트

ebpf_exporter (Cloudflare)는 eBPF와 Prometheus를 연결합니다. 표준 내보내기는 커널이 이미 게시하는 카운터를 표시합니다; ebpf_exporter를 사용하면 커널 프로브에 사용자 정의 eBPF 프로그램을 연결하고 측정하는 모든 것을 Prometheus 메트릭으로 내보낼 수 있습니다. 디스크 I/O 지연 히스토그램, TCP 재전송 원인, 스케줄러 실행 큐 지연, 페이지 캐시 동작입니다. 깊고 임시적인 커널 질문을 지속적으로 스크래핑되는 시계열로 변환합니다.

요구사항

  • BPF + BTF가 있는 Linux 커널 (5.x 권장)
  • 루트 / CAP_BPF 권한
  • 엔드포인트를 스크래핑할 Prometheus

설치

방법명령
바이너리GitHub Releases에서 다운로드
Dockerdocker run --privileged -p 9435:9435 cloudflare/ebpf_exporter
소스에서git clone https://github.com/cloudflare/ebpf_exporter && make
실행sudo ebpf_exporter --config.dir=examples --config.names=biolatency
메트릭http://localhost:9435/metrics

번들 예시로 실행

# 블록 I/O 지연 히스토그램 내보내기
sudo ./ebpf_exporter --config.dir=examples --config.names=biolatency

# 여러 프로그램을 한 번에
sudo ./ebpf_exporter --config.dir=examples \
  --config.names=biolatency,tcp-syn-backlog,run-queue-latency
플래그목적
--config.dir프로그램 구성 디렉토리
--config.names로드할 프로그램 (쉼표로 구분)
--web.listen-address바인드 주소 (기본값 :9435)
--debug상세 로딩/진단

번들 프로그램 (예시)

프로그램측정
biolatency블록 I/O 지연 히스토그램
bio-tracepoints장치/작업별 디스크 I/O
run-queue-latency작업이 실행되기 전 스케줄러 지연
tcp-syn-backlogSYN 백로그 깊이
tcp-window-clampsTCP 윈도우 클램핑 이벤트
timers타이머/softirq 동작
cachestat페이지 캐시 히트/미스
oomkillOOM 킬 이벤트

구성 구조

프로그램은 컴파일된 eBPF 객체를 메트릭 정의와 쌍으로 합니다.

metrics:
  histograms:
    - name: bio_latency_seconds
      help: Block IO latency histogram
      bucket_type: exp2
      bucket_multiplier: 0.000001   # 마이크로초 → 초
      bucket_min: 0
      bucket_max: 26
      labels:
        - name: device
          size: 32
          decoders:
            - name: string
        - name: bucket
          size: 8
          decoders:
            - name: uint
필드목적
counters / histograms내보낼 메트릭 유형
bucket_typeexp2 / linear 히스토그램 버킷팅
bucket_multiplier원본 커널 단위를 초로 스케일
labelsBPF 맵 키를 Prometheus 레이블에 매핑
decoders원본 바이트를 변환 (string, uint, ksym, cgroup…)

유용한 디코더

디코더변환
string바이트 배열 → 레이블 문자열
uint원본 정수
ksym커널 주소 → 기호 이름
majorminor장치 번호 → sda, nvme0n1
cgroupcgroup ID → 경로
static_map수치 열거 → 읽을 수 있는 레이블

Prometheus에서 쿼리

# 장치별 p99 블록 I/O 지연
histogram_quantile(0.99,
  sum(rate(bio_latency_seconds_bucket[5m])) by (le, device))

# 스케줄러 실행 큐 지연 p95 (CPU 포화 신호)
histogram_quantile(0.95,
  sum(rate(run_queue_latency_seconds_bucket[5m])) by (le))

도달할 때

질문표준 내보내기ebpf_exporter
”디스크가 바쁜가?”예 (node_exporter)
“I/O 지연의 분포는 무엇인가?”아니오
”작업이 스케줄되기를 기다리는 데 얼마나 오래 걸리는가?”아니오
”TCP 재전송이 왜 일어나는가?”부분적으로
”어느 cgroup이 이것을 야기했는가?”아니오예 (cgroup 디코더)

ebpf_exporter vs 관련 도구

도구모델
ebpf_exporter지속적 eBPF 메트릭 → Prometheus
bpftrace임시, 대화형 eBPF 한 줄짜리
bcc-tools사전 구축 eBPF 진단 도구
node_exporter표준 커널 게시 메트릭
bpftopeBPF 프로그램 오버헤드

질문을 대화형으로 탐색하기 위해 bpftrace를 사용한 후 답변을 영구 ebpf_exporter 메트릭으로 인코드합니다.

리소스