# Get total number of messages for logging purpose

**URL:** <https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930>\
**Category:** General\
**Created:** [26 February 2024 14:45 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930 "2024-02-26T14:45:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riccaleu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riccaleu/32/83807_2.png) [@Riccaleu](https://discourse.nodered.org/u/Riccaleu)\
**Post date:** [26 February 2024 14:45 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/1 "2024-02-26T14:45:47Z")

</div>

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

```auto
[
    {
        "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"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [26 February 2024 15:17 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/2 "2024-02-26T15:17:36Z")

</div>

```auto
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.

---

<div class="post-metadata">

**Author:** ![Riccaleu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riccaleu/32/83807_2.png) [@Riccaleu](https://discourse.nodered.org/u/Riccaleu)\
**Post date:** [26 February 2024 15:54 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/3 "2024-02-26T15:54:10Z")

</div>

already tested not working

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 February 2024 17:25 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/4 "2024-02-26T17:25:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 February 2024 19:28 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/5 "2024-02-26T19:28:28Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/680b742a75394592aa71cfe7ca36c5c3a65657bd.png)

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [27 February 2024 02:31 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/6 "2024-02-27T02:31:15Z")

</div>

> [@Riccaleu](#):
>
> already tested not working

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

---

<div class="post-metadata">

**Author:** ![Riccaleu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/riccaleu/32/83807_2.png) [@Riccaleu](https://discourse.nodered.org/u/Riccaleu)\
**Post date:** [27 February 2024 08:28 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/7 "2024-02-27T08:28:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [27 February 2024 09:03 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/8 "2024-02-27T09:03:50Z")

</div>

> [@Riccaleu](#):
>
> when the previsus node is completed

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [27 February 2024 09:16 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/9 "2024-02-27T09:16:11Z")

</div>

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:

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 May 2024 09:16 UTC](https://discourse.nodered.org/t/get-total-number-of-messages-for-logging-purpose/85930/10 "2024-05-27T09:16:55Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
