안녕하세요. 이번에는 Nginx의 현재 상태를 모니터링! 할 수 있는 모듈은 없을까 찾아봤습니다.

 

1. 기본 제공 모듈. HttpStubStatusModule

   : 기본이라고 적었지만 default 로 컴파일 할 때는 설치되지 않습니다. 설치 시 아래와 같은 옵션이 필요합니다.

--with-http_stub_status_module

사용할 때는 nginx.conf에 아래와 같이 설정해 주면 됩니다.

location /nginx_status {
  stub_status on;
  access_log off;
  allow 127.0.0.1;
  deny all;
}

호출해 보니 아래와 같이 정보가 나옵니다.

Active connections : 1
server accepts handled requests
1 1 4
Reading: 0 Writing: 1 Waiting: 0

참고로 각 필드의 의미는 아래와 같습니다.

- active connections -- number of all open connections

- 1 1 4 : 첫번째 숫자가 현재 accept된 connection 수, 두번째 1은 처리 중인 connection 수, 세번째 4는 request 수입니다.

- reading : 읽고있는 request head 수

- writing : nginx reads request body, processes request, or writes response to a client

- waiting : keep-alive connection 수라네요.

대충 간단한 정보가 있긴 하지만 꽤 빈곤합니다. 그래서 다른 모듈은 없는지 살펴봤습니다.

 

 

2. ngx_http_status_module

  : nginx plus에서 제공되는 모듈입니다. 따라서 테스트는 못해봤습니다. trial license를 신청하면 30일 사용가능하긴 한데 여러가지 개인정보를 줘야해서 다음번에 사용해볼 모듈을 모아서 테스트해보도록 하겠습니다.

설정은 아래와 같이 간단합니다.

server {
    location = /status {
        status;
    }

    status_zone example_server;
}

 

위와 같이 설정해서 볼 수 있는 정보는 다양한데요. (http://nginx.org/en/docs/http/ngx_http_status_module.html)

아래 외에도 다양한 정보를 제공하고 있습니다. 역시 돈 받는 서비스는 다르긴 한가봅니다.

 

-load_timestamp : 최종으로 configuration reload 하고 지난 시간.

-connections : 위 모듈과는 달리 dropped라는 항목이 있어 정상저으로 처리되지 않은 connection 개수 정보를 제공합니다.

-1xx, 2xx, 3xx, 4xx, 5xx return code 별 response 개수를 확인할 수 있습니다.

-upstreams 아래의 항목을 통해 load balancing되고 있는 상황도 확인할 수 있습니다.