Все три Go-сервиса (ingest, device-control, rule-engine) отдают /metrics в формате Prometheus: счётчики MQTT/RabbitMQ/ClickHouse операций, гистограммы длительности батч-флашей и диспатча правил, переходы устройств online/offline. Добавлены сервисы prometheus и grafana в docker-compose с провижининг конфигом (datasource + два готовых дашборда: "Ingest & Telemetry" и "Automation & Devices").
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
// 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"})
|
|
)
|