본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Prometheus 텍스트 파일 (Prometheus text file)

원문 보기 위키 갱신

로컬 파일시스템에 있는 Prometheus 텍스트 포맷 파일(.prom 파일)에서 메트릭을 읽어오는 입력 플러그인이에요. 외부 앱이나 스크립트가 파일에 써둔 커스텀 메트릭을 모을 때 씁니다.

출처: 문서

본문

{% hint style="info" %} 지원 이벤트 타입: metrics {% endhint %}

Prometheus text file 입력 플러그인은 Fluent Bit가 로컬 파일시스템의 Prometheus 텍스트 포맷 파일(.prom 파일)에서 메트릭을 읽을 수 있게 해줘요. 이 플러그인은 Prometheus Node Exporter 텍스트 파일 콜렉터처럼, 외부 애플리케이션이나 스크립트가 파일에 써둔 커스텀 메트릭을 수집하는 데 사용해요.

구성 파라미터

Key Description Default
alias 별칭을 설정해요. 같은 입력 플러그인의 여러 인스턴스를 위해 사용해요. 별칭을 지정하지 않으면 플러그인 이름 뒤에 점과 일련번호를 붙인 기본 이름이 할당돼요. 없음
log_level 입력 플러그인의 로그 레벨을 지정해요. 여기서 설정하지 않으면 service 섹션의 전역 로그 레벨을 사용해요. info
log_suppress_interval 지정된 시간 간격 안에 비슷하게 나타나는 입력 플러그인의 로그 메시지를 억제해요. 0은 억제 없음. 0
mem_buf_limit 입력 플러그인의 메모리 버퍼 한도를 설정해요. 한도에 도달하면 버퍼가 비워질 때까지 플러그인이 일시정지해요. 값은 바이트 단위예요. 0으로 설정하면 버퍼 한도가 비활성화돼요. 0
path 읽을 파일 또는 글로브 패턴의 쉼표로 구분된 목록. * 와일드카드를 지원해요 (예: /var/lib/prometheus/*.prom). 없음
routable true로 설정하면 플러그인이 생성한 데이터가 라우팅 가능해져 다른 플러그인이나 출력으로 전달될 수 있어요. false로 설정하면 데이터가 버려져요. true
scrape_interval 파일 스캔 사이의 간격. 10s
storage.pause_on_chunks_overlimit 입력이 자신의 청크 한도에 도달하면 일시정지하도록 켭니다. 없음
storage.type 이 입력의 저장 타입을 설정해요. filesystem, memory, memrb 중 하나. memory
tag 이 입력 플러그인이 생성한 이벤트의 태그를 설정해요. 없음
thread.ring_buffer.capacity 입력이 스레드 모드로 실행될 때 커스텀 링 버퍼 용량을 설정해요. 1024
thread.ring_buffer.window 스레드 입력의 커스텀 링 버퍼 윈도우 백분율을 설정해요. 5
threaded 입력에서 스레딩을 켭니다. false

시작하기

기본 구성

다음 구성은 /var/lib/prometheus/textfile 디렉토리에서 .prom 파일을 15초마다 모니터링해요:

pipeline:
  inputs:
    - name: prometheus_textfile
      tag: custom_metrics
      path: '/var/lib/prometheus/textfile/*.prom'
      scrape_interval: 15s
  outputs:
    - name: prometheus_exporter
      match: custom_metrics
      host: 192.168.100.61
      port: 2021

Prometheus 텍스트 포맷

플러그인은 파일이 표준 Prometheus 텍스트 노출 포맷이길 기대해요. 다음은 유효한 .prom 파일의 예시예요:

# HELP custom_counter_total A custom counter metric
# TYPE custom_counter_total counter
custom_counter_total{instance="server1",job="myapp"} 42

# HELP custom_gauge A custom gauge metric
# TYPE custom_gauge gauge
custom_gauge{environment="production"} 1.23

# HELP custom_histogram_bucket A custom histogram
# TYPE custom_histogram_bucket histogram
custom_histogram_bucket{le="0.1"} 10
custom_histogram_bucket{le="0.5"} 25
custom_histogram_bucket{le="1.0"} 40
custom_histogram_bucket{le="+Inf"} 50
custom_histogram_sum 125.5
custom_histogram_count 50

사용 사례

커스텀 애플리케이션 메트릭

애플리케이션은 .prom 파일에 커스텀 메트릭을 쓸 수 있고, 이 플러그인이 그것을 수집해요:

# Script writes metrics to file
echo "# HELP app_requests_total Total HTTP requests" > /var/lib/prometheus/textfile/app.prom
echo "# TYPE app_requests_total counter" >> /var/lib/prometheus/textfile/app.prom
echo "app_requests_total{status=\"200\"} 1500" >> /var/lib/prometheus/textfile/app.prom
echo "app_requests_total{status=\"404\"} 23" >> /var/lib/prometheus/textfile/app.prom

배치 작업 메트릭

Cron 작업이나 배치 프로세스는 완료 메트릭을 쓸 수 있어요:

#!/bin/bash
# Backup script writes completion metrics
BACKUP_START=$(date +%s)
# ... perform backup ...
BACKUP_END=$(date +%s)
DURATION=$((BACKUP_END - BACKUP_START))

cat > /var/lib/prometheus/textfile/backup.prom << EOF
# HELP backup_duration_seconds Time taken to complete backup
# TYPE backup_duration_seconds gauge
backup_duration_seconds ${DURATION}

# HELP backup_last_success_timestamp_seconds Last successful backup timestamp
# TYPE backup_last_success_timestamp_seconds gauge
backup_last_success_timestamp_seconds ${BACKUP_END}
EOF

시스템 통합

외부 모니터링 도구는 Fluent Bit가 수집해서 전달할 메트릭을 쓸 수 있어요.

다른 플러그인과의 통합

OpenTelemetry 목적지

pipeline:
  inputs:
    - name: prometheus_textfile
      tag: textfile_metrics
      path: /var/lib/prometheus/textfile
    - name: node_exporter_metrics
      tag: system_metrics
      scrape_interval: 15s
  outputs:
    - name: opentelemetry
      match: '*'
      host: 192.168.56.4
      port: 2021

더 알아보기 (Learn more)