mirror of
https://github.com/hikhvar/mqtt2prometheus.git
synced 2026-08-23 21:16:15 +00:00
This commit allows to extract the metric name from the topic path. Now it can be configured if all metrics are in a object in a certain topic or if every topic contains exactly one metric. However, currently these modes can not be mixed. This should solve !26 TODO: * Update documentation * Add unit tests
34 lines
768 B
Go
34 lines
768 B
Go
package metrics
|
|
|
|
import "github.com/prometheus/client_golang/prometheus"
|
|
|
|
const (
|
|
storeError = "storeError"
|
|
success = "success"
|
|
)
|
|
|
|
var defaultInstrumentation = instrumentation{
|
|
messageMetric: prometheus.NewCounterVec(
|
|
prometheus.CounterOpts{
|
|
Name: "received_messages",
|
|
Help: "received messages per topic and status",
|
|
}, []string{"status", "topic"},
|
|
),
|
|
}
|
|
|
|
type instrumentation struct {
|
|
messageMetric *prometheus.CounterVec
|
|
}
|
|
|
|
func (i *instrumentation) MessageMetric() *prometheus.CounterVec {
|
|
return i.messageMetric
|
|
}
|
|
|
|
func (i *instrumentation) CountSuccess(topic string) {
|
|
i.messageMetric.WithLabelValues(success, topic).Inc()
|
|
}
|
|
|
|
func (i *instrumentation) CountStoreError(topic string) {
|
|
i.messageMetric.WithLabelValues(storeError, topic).Inc()
|
|
}
|