Добавлены метрики Prometheus и дашборды Grafana (этап 2.5)

Все три Go-сервиса (ingest, device-control, rule-engine) отдают
/metrics в формате Prometheus: счётчики MQTT/RabbitMQ/ClickHouse
операций, гистограммы длительности батч-флашей и диспатча правил,
переходы устройств online/offline. Добавлены сервисы prometheus и
grafana в docker-compose с провижининг конфигом (datasource +
два готовых дашборда: "Ingest & Telemetry" и "Automation & Devices").
This commit is contained in:
2026-08-11 21:58:59 +05:00
parent 3ade5c2512
commit 81040eec62
31 changed files with 712 additions and 53 deletions
@@ -24,6 +24,8 @@ type Config struct {
BatchMaxSize int
BatchFlushInterval time.Duration
BatchFlushTimeout time.Duration
MetricsPort int
}
func Load() (Config, error) {
@@ -55,6 +57,9 @@ func Load() (Config, error) {
if cfg.BatchFlushTimeout, err = getEnvDuration("INGEST_BATCH_FLUSH_TIMEOUT", 10*time.Second); err != nil {
return Config{}, err
}
if cfg.MetricsPort, err = getEnvInt("INGEST_METRICS_PORT", 9101); err != nil {
return Config{}, err
}
return cfg, nil
}
@@ -0,0 +1,48 @@
// Package metrics defines ingest-service's Prometheus metrics. Registered
// automatically (via promauto) into the default registry on import; served
// by main.go's dedicated metrics HTTP server.
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
MQTTMessagesReceived = promauto.NewCounter(prometheus.CounterOpts{
Name: "ingest_mqtt_messages_received_total",
Help: "Total number of telemetry messages received from MQTT.",
})
MQTTMessagesInvalid = promauto.NewCounter(prometheus.CounterOpts{
Name: "ingest_mqtt_messages_invalid_total",
Help: "Total number of telemetry messages dropped for failing validation.",
})
MQTTMessagesDropped = promauto.NewCounter(prometheus.CounterOpts{
Name: "ingest_mqtt_messages_dropped_total",
Help: "Total number of readings dropped because the worker backlog was full.",
})
BatchFlushes = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ingest_batch_flush_total",
Help: "Total number of batch flushes to ClickHouse, by outcome.",
}, []string{"outcome"})
BatchFlushDuration = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "ingest_batch_flush_duration_seconds",
Help: "Duration of ClickHouse batch insert calls.",
Buckets: prometheus.DefBuckets,
})
BatchSize = promauto.NewHistogram(prometheus.HistogramOpts{
Name: "ingest_batch_size",
Help: "Number of readings per flushed batch.",
Buckets: []float64{1, 5, 10, 25, 50, 100, 250, 500, 1000},
})
RabbitMQPublishes = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ingest_rabbitmq_publish_total",
Help: "Total number of new-reading events published to RabbitMQ, by outcome.",
}, []string{"outcome"})
)