Files
K3S/addons/pushgateway/README.md
Sergey Antropoff 38aaadbfb1 docs: sync addon docs with explicit external/internal service modes
Обновлена документация под новые аддоны (gitlab, redis, mongodb, kafka, kafka-ui, rabbitmq) и новую модель явного выбора зависимостей. Добавлены и унифицированы описания переключателей *_database_mode и *_redis_mode, обновлена таблица зависимостей аддонов, примеры конфигурации и список vault-секретов.
2026-04-29 23:21:04 +03:00

105 lines
3.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Prometheus Pushgateway
Промежуточное хранилище метрик для batch-задач, CI/CD, cron-скриптов — всего что не может быть scraped напрямую Prometheus. Устанавливается в namespace `monitoring` (рядом с Prometheus).
## Быстрый старт
```yaml
# group_vars/all/addons.yml
addon_pushgateway: true
addon_prometheus_stack: true # Prometheus scrapes Pushgateway автоматически
```
```bash
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)
```bash
# Одна метрика
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
```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)
```bash
#!/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 на пропавшие метрики
```yaml
# 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"
```
## Удалить метрику
```bash
curl -X DELETE \
http://prometheus-pushgateway.monitoring.svc.cluster.local:9091/metrics/job/my-batch-job
```
## Официальные ресурсы
- Официальный сайт: [https://github.com/prometheus/pushgateway](https://github.com/prometheus/pushgateway)
- Официальная документация: [https://github.com/prometheus/pushgateway](https://github.com/prometheus/pushgateway)
- Версии Helm chart / ПО: [https://artifacthub.io/packages/helm/prometheus-community/prometheus-pushgateway](https://artifacthub.io/packages/helm/prometheus-community/prometheus-pushgateway)