Files
K3S/addons/pushgateway
Sergey Antropoff eccc1c2a01 docs: полная документация проекта — docs/ и README.md для каждого аддона
- README.md: перепиcан как компактный обзор (98 строк) с навигацией по docs/
- docs/: 13 файлов — getting-started, architecture, configuration, addons,
  storage, security, cicd, observability, networking, operations,
  make-reference, molecule-testing, troubleshooting
- addons/*/README.md: 31 новый файл — описание, параметры, примеры кода
  для каждого из 34 аддонов (vault и external-secrets уже существовали)
2026-04-26 00:22:06 +03:00
..

Prometheus Pushgateway

Промежуточное хранилище метрик для batch-задач, CI/CD, cron-скриптов — всего что не может быть scraped напрямую Prometheus. Устанавливается в namespace monitoring (рядом с Prometheus).

Быстрый старт

# group_vars/all/addons.yml
addon_pushgateway: true
addon_prometheus_stack: true  # Prometheus scrapes Pushgateway автоматически
make addon-pushgateway

Параметры

Переменная Умолч. Описание
pushgateway_ingress_enabled false Ingress (обычно не нужен)
pushgateway_persistence_enabled false Сохранять метрики при рестарте
pushgateway_persistence_size 2Gi PVC если persistence enabled

Endpoint

http://prometheus-pushgateway.monitoring.svc.cluster.local:9091

Отправить метрику (curl)

# Одна метрика
cat <<EOF | curl --data-binary @- \
  http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/my-batch-job
# HELP my_job_duration_seconds Duration of my batch job
# TYPE my_job_duration_seconds gauge
my_job_duration_seconds 42.5
EOF

# С labels
cat <<EOF | curl --data-binary @- \
  http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/backup/instance/prod
backup_success 1
backup_size_bytes 1073741824
EOF

Из Python

from prometheus_client import CollectorRegistry, Gauge, push_to_gateway

registry = CollectorRegistry()
g = Gauge('job_last_success_unixtime', 'Last time job succeeded',
          registry=registry)
g.set_to_current_time()

push_to_gateway(
    'prometheus-pushgateway.monitoring.svc.cluster.local:9091',
    job='my_job',
    registry=registry
)

Из скрипта (bash в Pod)

#!/bin/bash
START=$(date +%s)
# ... основная работа ...
END=$(date +%s)
DURATION=$((END - START))

cat <<EOF | curl --data-binary @- \
  "${PUSHGATEWAY_URL}/metrics/job/${JOB_NAME}/instance/${HOSTNAME}"
job_duration_seconds ${DURATION}
job_last_success_timestamp $(date +%s)
EOF

Alerting на пропавшие метрики

# PrometheusRule
- alert: BatchJobMissing
  expr: time() - push_time_seconds{job="my-cron-job"} > 3600
  for: 0m
  annotations:
    summary: "Batch job hasn't run in 1 hour"

Удалить метрику

curl -X DELETE \
  http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/my-batch-job