Devops's Blog

haproxy_expoter в k8s

В продолжении Prometeus

192.168.100.64 - haproxy

monitoring:12345678 - basic auth haproxy


---
apiVersion: v1
kind: Service
metadata:
  name: haproxy-exporter-svc
  namespace: monitoring
spec:
  ports:
    - name: tcp
      port: 9101
      protocol: TCP
  clusterIP: None
  selector:
    app: haproxy-exporter
  sessionAffinity: None
  type: ClusterIP

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: haproxy-exporter
  namespace: monitoring
  labels:
    app: haproxy-exporter
spec:
  selector:
    matchLabels:
        app: haproxy-exporter
  replicas: 1
  template:
    metadata:
      labels:
        app: haproxy-exporter
    spec:
      containers:
      - name: haproxy-exporter
        image: "prom/haproxy-exporter:v0.10.0"
        imagePullPolicy: IfNotPresent
        args:
          - >-
            --haproxy.scrape-uri=http://monitoring:12345678@192.168.100.64:1313/stats;csv
        resources:
          limits:
            cpu: 256m
            memory: 256Mi
          requests:
            cpu: 50m
            memory: 64Mi
        ports:
        - containerPort: 9101

Подключимся на под prometeus и проверим получения метрик


I have no name!@prometheus-server-865cc64c6c-mp57n:/opt/bitnami/prometheus$ curl -s haproxy-exporter-svc:9101/metrics | grep "haproxy_backend"
# HELP haproxy_backend_bytes_in_total Current total of incoming bytes.
# TYPE haproxy_backend_bytes_in_total gauge
haproxy_backend_bytes_in_total{backend="backend-certbot"} 0
haproxy_backend_bytes_in_total{backend="bknd_hdr_1"} 0
haproxy_backend_bytes_in_total{backend="bknd_hdr_10"} 19699
haproxy_backend_bytes_in_total{backend="bknd_hdr_2"} 1.621525e+06
haproxy_backend_bytes_in_total{backend="bknd_hdr_3"} 3349
haproxy_backend_bytes_in_total{backend="bknd_hdr_4"} 0
haproxy_backend_bytes_in_total{backend="bknd_hdr_5"} 0
haproxy_backend_bytes_in_total{backend="bknd_hdr_8"} 0
haproxy_backend_bytes_in_total{backend="stats"} 411773
haproxy_backend_bytes_in_total{backend="stats_local"} 124092
# HELP haproxy_backend_bytes_out_total Current total of outgoing bytes.
# TYPE haproxy_backend_bytes_out_total gauge
haproxy_backend_bytes_out_total{backend="backend-certbot"} 0
haproxy_backend_bytes_out_total{backend="bknd_hdr_1"} 0
haproxy_backend_bytes_out_total{backend="bknd_hdr_10"} 4.180374e+06
haproxy_backend_bytes_out_total{backend="bknd_hdr_2"} 311301
haproxy_backend_bytes_out_total{backend="bknd_hdr_3"} 26283
haproxy_backend_bytes_out_total{backend="bknd_hdr_4"} 0
haproxy_backend_bytes_out_total{backend="bknd_hdr_5"} 0
haproxy_backend_bytes_out_total{backend="bknd_hdr_8"} 0
haproxy_backend_bytes_out_total{backend="stats"} 2.177435e+07
haproxy_backend_bytes_out_total{backend="stats_local"} 5.337767e+06
# HELP haproxy_backend_connection_errors_total Total of connection errors.
# TYPE haproxy_backend_connection_errors_total gauge
haproxy_backend_connection_errors_total{backend="backend-certbot"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_1"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_10"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_2"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_3"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_4"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_5"} 0
haproxy_backend_connection_errors_total{backend="bknd_hdr_8"} 0
haproxy_backend_connection_errors_total{backend="stats"} 0
haproxy_backend_connection_errors_total{backend="stats_local"} 0

Приведем конфиг prometeus к таком виду и перезапусим под


global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]
  - job_name: "haproxy"
    static_configs:
      - targets: ["haproxy-exporter-svc:9101"]
        labels:
          alias: "haproxy"

Проверим отображения метрик

image

PS Дальше делаем отображение в grafana, шаблон можно найти в интернете