NGINX exporter 메트릭
NGINX exporter metrics 입력 플러그인은 NGINX stub status 핸들러에서 메트릭을 수집해요. NGINX 서버의 요청/연결 상태를 지표로 보고 싶은 분께 알맞은 기능이에요.
출처: 문서
본문
{% hint style="info" %}
지원 이벤트 타입: metrics
{% endhint %}
NGINX exporter metrics 입력 플러그인은 NGINX stub status 핸들러에서 메트릭을 수집해요.
{% hint style="info" %} NGINX Exporter Metrics로 수집된 메트릭은 로그와는 별도의 파이프라인으로 흘러가며, 현재 필터는 메트릭 위에서 동작하지 않아요. {% endhint %}
구성 파라미터
플러그인은 다음 구성 파라미터를 지원해요:
| 키 | 설명 | 기본값 |
|---|---|---|
host |
대상 호스트 이름 또는 IP 주소예요. | localhost |
nginx_plus |
NGINX Plus 모드를 켜요. | true |
port |
연결할 대상 NGINX 서비스의 포트예요. | 80 |
scrape_interval |
NGINX 서비스에서 메트릭을 수집하는 간격이에요. | 5s |
status_url |
stub status 핸들러의 URL이에요. | /status |
threaded |
이 입력을 자체 스레드 로 실행할지 여부를 나타내요. | false |
TLS / SSL
NGINX exporter metrics 입력 플러그인은 TLS/SSL을 지원해요. 사용 가능한 속성과 일반 구성에 대한 자세한 내용은 Transport Security 를 참고해요.
시작하기 (Get started)
NGINX는 stub status 핸들러를 호출하는 location으로 구성되어야 해요. 다음은 그러한 location이 있는 예시 구성이에요:
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# Configure the stub status handler.
location /status {
stub_status;
}
}
NGINX Plus REST API 사용 구성
NGINX Plus에서는 또 다른 메트릭 API를 사용할 수 있어요. 먼저 NGINX Plus에서 경로를 구성해야 해요.
server {
listen 80;
listen [::]:80;
server_name localhost;
# Enable /api/ location with appropriate access control in order
# to make use of NGINX Plus API.
location /api/ {
api write=on;
# Configure to allow requests from the server running Fluent Bit.
allow 192.168.1.*;
deny all;
}
}
커맨드 라인
커맨드 라인에서 다음 옵션들로 Fluent Bit가 체크를 생성하게 할 수 있어요:
fluent-bit -i nginx_metrics -p host=127.0.0.1 -p port=80 -p status_url=/status -p nginx_plus=off -o stdout
NGINX Plus REST API로 커맨드 라인에서 메트릭을 수집하려면 nginx_plus 속성을 켜요:
fluent-bit -i nginx_metrics -p host=127.0.0.1 -p port=80 -p nginx_plus=on -p status_url=/api -o stdout
구성 파일
메인 구성 파일에 다음을 추가해요:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: nginx_metrics
host: 127.0.0.1
port: 80
status_url: /status
nginx_plus: off
scrape_interval: 5s
outputs:
- name: stdout
match: '*'
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name nginx_metrics
Host 127.0.0.1
Port 80
Status_URL /status
Nginx_Plus off
Scrape_Interval 5s
[OUTPUT]
Name stdout
Match *
{% endtab %} {% endtabs %}
그리고 NGINX Plus API의 경우:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: nginx_metrics
host: 127.0.0.1
port: 80
status_url: /api
nginx_plus: on
scrape_interval: 5s
outputs:
- name: stdout
match: '*'
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name nginx_metrics
Host 127.0.0.1
Port 80
Status_URL /api
Nginx_Plus on
Scrape_Interval 5s
[OUTPUT]
Name stdout
Match *
{% endtab %} {% endtabs %}
설정 테스트
커맨드 라인에서 직접 호출해 localhost에서 실행 중인 NGINX 서버를 테스트할 수 있어요:
fluent-bit -i nginx_metrics -p host=127.0.0.1 -p nginx_plus=off -o stdout -p match=* -f 1
이 명령은 다음과 유사한 출력을 반환해요:
...
2021-10-14T19:37:37.228691854Z nginx_connections_accepted = 788253884
2021-10-14T19:37:37.228691854Z nginx_connections_handled = 788253884
2021-10-14T19:37:37.228691854Z nginx_http_requests_total = 42045501
2021-10-14T19:37:37.228691854Z nginx_connections_active = 2009
2021-10-14T19:37:37.228691854Z nginx_connections_reading = 0
2021-10-14T19:37:37.228691854Z nginx_connections_writing = 1
2021-10-14T19:37:37.228691854Z nginx_connections_waiting = 2008
2021-10-14T19:37:35.229919621Z nginx_up = 1
...
내보내는 메트릭
사용 가능한 메트릭 목록은 GitHub의 NGINX Prometheus Exporter 메트릭 문서 를 참고해요.