Files
mqtt2prometheus/pkg/metrics/instrumentation.go
Christoph Petrausch be4af9ff5e Refactor metric extraction from MQTT
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
2020-11-08 22:01:36 +01:00

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()
}