Skip to content

Map JSON properties as MQTT labels#172

Open
SuperCoolAlan wants to merge 8 commits into
hikhvar:masterfrom
SuperCoolAlan:master
Open

Map JSON properties as MQTT labels#172
SuperCoolAlan wants to merge 8 commits into
hikhvar:masterfrom
SuperCoolAlan:master

Conversation

@SuperCoolAlan

Copy link
Copy Markdown

Implements the feature requested here: #74

Comment thread hack/docker-compose.yml
Comment thread pkg/metrics/collector.go Outdated
Comment thread pkg/metrics/parser.go Outdated
Comment thread pkg/metrics/parser.go Outdated
Comment thread pkg/metrics/extractor.go
return func(topic string, payload []byte, deviceID string) (MetricCollection, error) {
var mc MetricCollection
parsed := gojsonq.New(gojsonq.SetSeparator(p.separator)).FromString(string(payload))
rawPayload := gojsonq.New(gojsonq.SetSeparator(p.separator)).FromString(string(payload))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than parse the raw data again, can we avoid cloning altogether or at least clone the object without deserializing again?

@SuperCoolAlan

Copy link
Copy Markdown
Author

I should probably update the README to include this new feature, as well :)

@SuperCoolAlan

Copy link
Copy Markdown
Author

Here's a pre-built package for your use https://github.com/SuperCoolAlan/mqtt2prometheus/pkgs/container/mqtt2prometheus

@SuperCoolAlan

Copy link
Copy Markdown
Author

When sharing the same topic and inheriting labels, no new Prometheus measurement is posted to /metrics for each unique label value. Instead, I see the exporter report the correct values to a single measurement & the inherited label switches back & forth between the unique label values. I'll work on a patch for this - Whenever a new inherited label is found, we must create a new measurement entry rather than override the existing entry & its label value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant