diff --git a/Readme.md b/Readme.md index 1c88805..259d396 100644 --- a/Readme.md +++ b/Readme.md @@ -186,7 +186,7 @@ metrics: - prom_name: humidity # The name of the metric in a MQTT JSON message mqtt_name: humidity - # The scale of the metric in a MQTT JSON message (mqtt_value : scale = prom_value : 1) + # The scale of the metric in a MQTT JSON message (prom_value = mqtt_value * scale) mqtt_value_scale: 100 # The prometheus help text for this metric help: DHT22 humidity reading diff --git a/pkg/metrics/parser.go b/pkg/metrics/parser.go index 2a59eb0..c08da3b 100644 --- a/pkg/metrics/parser.go +++ b/pkg/metrics/parser.go @@ -96,7 +96,7 @@ func (p *Parser) parseMetric(metricPath string, deviceID string, value interface } if cfg.MQTTValueScale != 0 { - metricValue = metricValue / cfg.MQTTValueScale + metricValue = metricValue * cfg.MQTTValueScale } return Metric{ diff --git a/pkg/metrics/parser_test.go b/pkg/metrics/parser_test.go index 64f5429..8d6a680 100644 --- a/pkg/metrics/parser_test.go +++ b/pkg/metrics/parser_test.go @@ -59,7 +59,7 @@ func TestParser_parseMetric(t *testing.T) { { PrometheusName: "temperature", ValueType: "gauge", - MQTTValueScale: 100, + MQTTValueScale: 0.01, }, }, }, @@ -129,7 +129,7 @@ func TestParser_parseMetric(t *testing.T) { { PrometheusName: "humidity", ValueType: "gauge", - MQTTValueScale: 100, + MQTTValueScale: 0.01, }, }, }, @@ -155,7 +155,7 @@ func TestParser_parseMetric(t *testing.T) { { PrometheusName: "humidity", ValueType: "gauge", - MQTTValueScale: -0.5, + MQTTValueScale: -2, }, }, }, @@ -206,7 +206,7 @@ func TestParser_parseMetric(t *testing.T) { { PrometheusName: "enabled", ValueType: "gauge", - MQTTValueScale: 2, + MQTTValueScale: 0.5, }, }, },