Metrics exposed:
- sqs_requests_total{tenant, operation} — request counter
- sqs_request_bytes_total{tenant, operation} — traffic counter
- sqs_request_duration_seconds{operation} — latency histogram
- sqs_errors_total{operation} — error counter
- sqs_queues_count{tenant} — gauge, updated every 15s
- sqs_messages_count{tenant} — gauge, updated every 15s
72 lines
2.7 KiB
Go
72 lines
2.7 KiB
Go
// app/metrics/metrics.go
|
|
// Prometheus-совместимые метрики shared-sqs для Victoria Metrics / Grafana.
|
|
// Отдаёт метрики на /metrics в стандартном формате Prometheus.
|
|
// VMAgent в кластере скрейпит этот endpoint через VMServiceScrape.
|
|
// Created: 2026-04-12
|
|
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
// RequestsTotal — счётчик SQS-запросов по тенанту и операции.
|
|
// Пример: sqs_requests_total{tenant="t-abc123", operation="SendMessage"} = 42
|
|
var RequestsTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "sqs_requests_total",
|
|
Help: "Total number of SQS API requests by tenant and operation",
|
|
},
|
|
[]string{"tenant", "operation"},
|
|
)
|
|
|
|
// RequestBytesTotal — суммарный объём тел запросов (Content-Length) по тенанту и операции.
|
|
// Для биллинга по трафику.
|
|
var RequestBytesTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "sqs_request_bytes_total",
|
|
Help: "Total request body bytes by tenant and operation",
|
|
},
|
|
[]string{"tenant", "operation"},
|
|
)
|
|
|
|
// RequestDuration — гистограмма latency SQS-операций в секундах.
|
|
// Бакеты подобраны для типичного SQS: от 1ms до 30s (long polling).
|
|
var RequestDuration = promauto.NewHistogramVec(
|
|
prometheus.HistogramOpts{
|
|
Name: "sqs_request_duration_seconds",
|
|
Help: "SQS API request duration in seconds",
|
|
Buckets: []float64{0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, 20, 30},
|
|
},
|
|
[]string{"operation"},
|
|
)
|
|
|
|
// ErrorsTotal — счётчик ошибочных SQS-ответов (HTTP >= 400) по операции.
|
|
var ErrorsTotal = promauto.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "sqs_errors_total",
|
|
Help: "Total number of SQS API error responses by operation",
|
|
},
|
|
[]string{"operation"},
|
|
)
|
|
|
|
// QueuesGauge — текущее количество очередей по тенанту.
|
|
// Обновляется периодически, не на каждый запрос.
|
|
var QueuesGauge = promauto.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Name: "sqs_queues_count",
|
|
Help: "Current number of queues per tenant",
|
|
},
|
|
[]string{"tenant"},
|
|
)
|
|
|
|
// MessagesGauge — текущее количество сообщений по тенанту.
|
|
// Обновляется периодически, не на каждый запрос.
|
|
var MessagesGauge = promauto.NewGaugeVec(
|
|
prometheus.GaugeOpts{
|
|
Name: "sqs_messages_count",
|
|
Help: "Current number of messages per tenant",
|
|
},
|
|
[]string{"tenant"},
|
|
)
|