Multiple objects returned by a single node

Hi Bart,

I was trying to use a node created by you named as "node-red-contrib-cpu" and it returns multiple objects at a time. What I was trying to do is to fetch payload value from each object and merge it into a single JS object or display each msg object individually. But I didn't succeed and I am not able to find any example related to that on google, so can you please help me on that.

Here's the link for the flow: https://drive.google.com/open?id=1tAygTMr-lDNczhOjv8t80Sh3h8pRQDqM

@BartButenaers

Hi,

I have just found a solution to my problem by using a switch node and comparing the msg.topic value to a particular string (core_1, core_2 and so on).
I am attaching the link to my flow code in case someone wants to try this or looking for a solution for this node. Here you go:
https://drive.google.com/open?id=19oXR_3k__TYlTsTJKTDAdliHXoQuZef2
Sorry for the drive links, I will soon upload all my flow codes to github for easy access to all.

@BartButenaers , if you know any other better solution to this then please do share for people like me.
I would like to suggest you to please include few examples for your node on any platform like github, nodered.org or any other where you would like to. It will be a much help to better understand this node.

Hello Harshit,

I have no access to Node-RED at the moment, so I cannot try your example at the moment.
You can choose whether you want 1 message containing the info of all cores, OR 1 message for each core separately. So I assume you have selected 'Output message for each core' and then you want to merge all those messages together into a single message. Isn't it easier that you let the node output a single message?

Bart

Hi Bart,

Thanks for sharing the documentation link but I have gone through it already and as you can see I got the desired output.

Yes, it is but what if you want to see performance for each individual cores for a system with multiple cores. I am assuming that you are referring to this method.

I have also posted my example/ use-case to the github. Here is the link for that.

Hc

Evening Harshit,

It is some time ago that I wrote that cpu-node, and it indeed seems that you cannot have a single output message containing the information of all cpu's. I had completely forgotten that I haver added such an option... I'm getting old :weary:

Currently for each core you will get a message like this (with payload containing the usage percentage):
image

I could add a new option to the config screen:
image

But how should the corresponding output message need to look like?
Perhaps a msg.topic = "all_cores" and msg.payload containing an array like this:

[
    {
        "name": "core_1",
        "usage": 7,
        "model": "ARMv7 Processor rev 4 (v71)",
        "speed": 600
    },
    {
        "name": "core_2",
        "usage": 43,
        "model": "ARMv7 Processor rev 4 (v71)",
        "speed": 600
    },
   ...
]

Does anybody have a better idea ?

Bart

2 Likes

I would reverse the order of the three options :-)... and make the new one mention the word array... "Create a single array of..."

Dave, that is weird.
Asked my wife an hour ago for feedback, and she had the same kind of response (about order, color, text ...).
But she didn't mentioned a word about the wonderfull developments behind the checkbox.
The both of you must have something in common :joy:.
So it would become something like this:

image

Just to wordsmith it a bit more... Personally I found it confusing if they all start “Create a message”

My suggestion would be ...

Create a message for overall usage

Create a separate message for each core usage

Create a single message containing an array of core usages

1 Like

I would also suggest that nodes 'send messages' rather than 'create messages'

And are they really tick boxes ? Can they all be selected ? Should it not be a select box ?

Deal ...

Yes, on NPM there are already tick boxes. So a bit tricky if I change it to a dropdown now, to break existing flows ...

You could indeed select them all at once, which perhaps makes no sense in most cases. But that is not really a problem since each tickbox provides its own dedicated topics to the corresponding messages. For example:

image

Though being an amateur in this area what all I can say is, this looks good and will serve the purpose very well.
And thanks for making the efforts to create this node :slight_smile:

Hc

2 Likes

Hello Harshit,

I have a added a new (0.0.3) version on Github, that contains the new checkbox.
If it looks like what you had in mind, please let me know so I can publish it on NPM !!
Meanwhile you can install this test version directly from Github via command line:

npm install bartbutenaers/node-red-contrib-cpu

All changes in a nutshell:

  • A section about new option has been added to the readme page. And for all 3 available options, message examples have been added.

  • The node's config screen has been updated. And the help in the info panel has also been extended:

  • The new checkbox will generate an array of information for all cpu's. In the next screenshot you will see the comparison to the existing 'send a separate message for each core usage' option:
    image

Thanks guys for all the feedback !!
Bart

1 Like

Hi Bart,

I have gone through the new option and tested it on localhost as well as on an AWS instance and it indeed served the purpose. I would like to say thank you for putting all the efforts for creating this option.

Hc

Hi Harshit,

You are welcome! Thank you for testing the change!
I have published it on NPM, and the new 0.0.3 version is now available in the Node-RED palette:

image

Kind regards,
Bart