2. Nginx exporter 설정
1. nginx exporter 설치
- nginx exporter GitHub URL : https://github.com/nginxinc/nginx-prometheus-exporter/releases
- 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