Get total number of messages for logging purpose

hi evreyone,

for log purpose i need to count all the messages that arrive in a node. i need one value in a varible

At the moment i set up topic + counter + join with a timeout. but is not the proper soluutin sin time can take 2 ms 2 second or one minutes depending on the amount of message(variable).

i think msg.complete can be the solution but i cant find a set up to wait the precedent node as completed is job.

best solution wolud be a javascript code so i can integrate it in the log fuction node

[
    {
        "id": "eb56325d12849757",
        "type": "change",
        "z": "97d240c946ec6b33",
        "g": "8db8781fc043d9a0",
        "name": "topic ",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "num-query",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1290,
        "y": 220,
        "wires": [
            [
                "01b05955132bd655"
            ]
        ]
    },
    {
        "id": "01b05955132bd655",
        "type": "counter",
        "z": "97d240c946ec6b33",
        "g": "8db8781fc043d9a0",
        "name": "",
        "init": "0",
        "step": "1",
        "lower": null,
        "upper": null,
        "mode": "increment",
        "outputs": "1",
        "x": 1300,
        "y": 260,
        "wires": [
            [
                "77b3d0a01dee7270"
            ]
        ]
    },
    {
        "id": "77b3d0a01dee7270",
        "type": "join",
        "z": "97d240c946ec6b33",
        "g": "8db8781fc043d9a0",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "3",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1290,
        "y": 300,
        "wires": [
            [
                "f8cbb1dc34bcc942"
            ]
        ]
    }
]
node-red-contrib-message-counter

From the Docs...

Message Counter Node

Counts messages within given interval.

The node has two outputs. Output 1 will generate summary message on every interval. Output 2 will repeat incoming (non-control) messages. It can be used to continue your flow.

Messages are counted on regular intervals when a measuring message arrives. You can choose between two types of measuring message generators:

  • INTERNAL: uses built-in generator. You can specify interval and units (seconds / minutes / hours). Intervals can be aligned to the system clock
  • EXTERNAL: in this case you are responsible of generating measuring messages. The topic should be "mc-control" and the payload should be "measure".

In case you want information about current message count without resetting the counter, then send message with topic "mc-control" and payload "report". To distinguish between measure and report messages you can use msg.isReset property. This can be useful for displaying message count to a graph.

1 Like

already tested not working

What is not working? Do you mean the node does not count the incoming messages correctly?

The debug node can also count messages and show them as status - which can be caught by the status node - so you could wire it in parallel to the node you ar looking at

Show what you have done, I am sure there is a simple solution for what you are looking for.

the problem is that i want the total amount of messages and store it variable when the previsus node is completed. The counter node send a message for each incominig messege with count properties progressive.

when and/or how do you know the previous node is 'completed' ?

node-red-contrib-message-counter might not be the best option since it hasn't been updated in 7 years and an issued opened in 2018 has never been replied to. This would lead me to believe it has been abandoned.

You could try using node-red-contrib-counter and here is a sample flow you could use to see if it will it your need:

[{"id":"a8b622d1dd9458c8","type":"counter","z":"0c1d250328ecb536","name":"","init":"0","step":"1","lower":null,"upper":null,"mode":"increment","outputs":"1","x":300,"y":160,"wires":[["67347f199c9d6f56"]]},{"id":"48c99464b0cc4d30","type":"inject","z":"0c1d250328ecb536","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":180,"wires":[["a8b622d1dd9458c8"]]},{"id":"67347f199c9d6f56","type":"debug","z":"0c1d250328ecb536","name":"debug 634","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"count","targetType":"msg","statusVal":"","statusType":"auto","x":510,"y":160,"wires":[]},{"id":"06db22f594e5eeba","type":"inject","z":"0c1d250328ecb536","name":"reset","props":[{"p":"reset","v":"0","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":110,"y":120,"wires":[["a8b622d1dd9458c8"]]}]
1 Like