Prometheus в Go. Метрики и экспорт.

Ответ

Prometheus - метрики в формате ключ-значение, pull-модель. В Go: client_golang (prometheus/prometheus). Регистрируют Counter, Gauge, Histogram, Summary; метрики обновляют в коде. Endpoint /metrics отдает текст в формате Prometheus (promhttp.Handler()). Метки (labels) для разбиения (handler, method, code).

var reqTotal = prometheus.NewCounterVec(
    prometheus.CounterOpts{Name: "http_requests_total"},
    []string{"method", "path", "code"},
)
prometheus.MustRegister(reqTotal)
reqTotal.WithLabelValues("GET", "/", "200").Inc()
http.Handle("/metrics", promhttp.Handler())
🧠Квиз 🏆Лидеры 🎯Собесед. 📖Вопросы 📚База зн.