Skip to content

Nmis mqtt observations#142

Merged
markdueck1 merged 2 commits intonmis9_devfrom
nmis-mqtt-observations
Mar 25, 2026
Merged

Nmis mqtt observations#142
markdueck1 merged 2 commits intonmis9_devfrom
nmis-mqtt-observations

Conversation

@kcsinclair
Copy link
Copy Markdown
Collaborator

Sumitting NMIS MQTT Observations for your consideration.

README has details, sends latest data to MQTT as OTEL inspired flat structure, very efficient, many metrics in one message.

…cument.

This could be changed to use full OTLP/JSON if someone required.

Updated README to include information about data being gauges
$NG->log->debug("MqttObservations: Processing concept '$concept' for $node")
if $extra_logging;

my $ids = $S->nmisng_node->get_inventory_ids(
Copy link
Copy Markdown
Contributor

@markdueck1 markdueck1 Mar 19, 2026

Choose a reason for hiding this comment

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

This works. You don't really need full inventory objects because this is just reading.

if you find that this plugin starts causing performance issues it might work better to query the node for all of it's inventory for the concept, using a fields_hash to limit was is returned. ModelData ->next_value() (without calling data() or count()) will use mongo's built in batching to read more efficiently.

eg:
while( my $entry = $md->next_value )
{
my $D = $entry->{data};

my $plugin_config = NMISNG::Util::loadTable(dir => 'conf', name => 'mqttobservations', conf => $C);
if (!$plugin_config || ref($plugin_config) ne 'HASH')
{
$NG->log->error("MqttObservations: Failed to load conf/mqttobservations.nmis");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

$plugin_config will hold the error string for why it failed to load, it might be useful in the log

{
eval {
my $mqtt = Net::MQTT::Simple->new($server);
$mqtt->login($username,$password);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest refactoring the new and login function calls out of the publishMqtt function and into a connectMqtt function which is called at the start of the collect_plugin function so it's not logging in for each message

@markdueck1 markdueck1 merged commit e3067ff into nmis9_dev Mar 25, 2026
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.

2 participants