모니터링/prometheus

[ prometheus ] Nginx exporter

김붕어87 2023. 3. 16. 14:57
반응형
개요
nginx exporter는
nginx metrics 정보를 수집해주는 역할을 합니다.

 

Nginx 설정

1. 모듈 확인

  • nginx 관련 metrics를 수집하기 위해서는 “ngx_http_stub_status_module” Enable 설정이 필요합니다.
  • ngx_http_stub_status_module Enable 설정 확인
nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http-_stub_status_module

 

2. nginx 설정

  • metrics 접근 가능한 경로 설정
  • http dirctive내에 server dirctive 설정
sudo vi /etc/nginx/nginx.conf

server {
    listen  80 default_server;
    listen  [::]:80 default_server;


---- 내용 추가 ----
    location /metrics {
        stub_status;
        allow all;
    }
---- 내용 추가 ----    
}

service nginx restart

 

  • metrics 설정 확인
curl localhost/metrics

Active connections: 2
server accepts handled requests
 122 122 910
Reading: 0 Writing: 1 Waiting: 1

 

 

 

 

 

2. Nginx exporter 설정

1. nginx exporter 설치

wget https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/v0.11.0/nginx-prometheus-exporter_0.11.0_linux_amd64.tar.gz
tar xvfz nginx-prometheus-exporter_0.10.0_linux_arm64.tar.gz

 

  • nginx exporter 실행
nohup ./nginx-prometheus-exporter -nginx.scrape-uri=http://localhost/metrics --web.listen-address=:8080 &

 

 

  • nginx expoter 확인
curl localhost:8080/metrics

# TYPE nginx_connections_accepted counter
nginx_connections_accepted 124
# HELP nginx_connections_active Active client connections
# TYPE nginx_connections_active gauge
nginx_connections_active 1
# HELP nginx_connections_handled Handled client connections
# TYPE nginx_connections_handled counter
nginx_connections_handled 124
# HELP nginx_connections_reading Connections where NGINX is reading the request header
# TYPE nginx_connections_reading gauge
nginx_connections_reading 0
# HELP nginx_connections_waiting Idle client connections
# TYPE nginx_connections_waiting gauge
nginx_connections_waiting 0

 

 

3. Nginx rule 설정

 

1. rule 생성

  • 폴더 위치 : prometheus/templates/prometheus/rules-1.14
  • 파일 : test-rule.yaml
  • nginx_up 상태가 0이면 Alert 알람 보내기
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: test-rule
  namespace: {{ template "kube-prometheus-stack.namespace" . }}
  labels:
    app: kube-prometheus-stack
    app.kubernetes.io/instance: prometheus
    app.kubernetes.io/part-of: kube-prometheus-stack
    app.kubernetes.io/version: 43.3.0
    release: prometheus
  annotations:
    meta.helm.sh/release-name: prometheus
    meta.helm.sh/release-namespace: monitor
spec:
  groups:
  - name: test-instance
    rules:
    - alert: nginxDown
      expr: nginx_up == 0
      labels:
        severity: critical
      annotations:
        description: '{{`{{`}} $labels.instance {{`}}`}} of job {{`{{`}} $labels.job {{`}}`}} has been down for more than 1 minutes.'
        summary: 'Instance : {{`{{`}} $labels.instance {{`}}`}}'
        title: 'nginx service down'

 

2. prometheus 재배포

helm upgrade --install prometheus . -f values-dev.yaml -n monitor

 

 

반응형

'모니터링 > prometheus' 카테고리의 다른 글

[ Prometheus ] exporter 종류  (0) 2023.03.16
[ Prometheus ] Nginx Log exporter  (0) 2023.03.16
[ Grafana ] Alert - Slack  (0) 2023.02.27
[ Grafana ] 설정  (0) 2023.02.27
[ prometheus ] node exporter  (0) 2023.02.23