Counting messages per main topic

First you would need to split the topic and grab the first part.

Then you could use a function node and an object stored in context to count them...

example...

chrome_ay2VTcASfH

demo flow...

[{"id":"8f7f9a59772e9c54","type":"inject","z":"a4633311d1bf470d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"main1/sub1","payload":"","payloadType":"date","x":1940,"y":800,"wires":[["4b61f945350d10d6"]]},{"id":"4b61f945350d10d6","type":"function","z":"a4633311d1bf470d","name":"topic counter","func":"let topic_counter = flow.get(\"topic_counter\") || {};\n\nif(msg.topic == \"CLEAR-STORE\") {\n    topic_counter = {};\n} else {\n    const main = msg.topic.split(\"/\")[0]\n    if(topic_counter[main] == null) {\n        topic_counter[main] = 0;\n    }\n    topic_counter[main]++;\n}\n\nflow.set(\"topic_counter\", topic_counter);\n\nmsg.payload = topic_counter;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2190,"y":860,"wires":[["159f9dcabd276f59"]]},{"id":"e6ce8b5ac7c69af1","type":"inject","z":"a4633311d1bf470d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"main1/sub2","payload":"","payloadType":"date","x":1940,"y":840,"wires":[["4b61f945350d10d6"]]},{"id":"43647647ced4c82c","type":"inject","z":"a4633311d1bf470d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"main2/sub1","payload":"","payloadType":"date","x":1940,"y":880,"wires":[["4b61f945350d10d6"]]},{"id":"34fb52f7e712aa72","type":"inject","z":"a4633311d1bf470d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"main21/sub2","payload":"","payloadType":"date","x":1940,"y":920,"wires":[["4b61f945350d10d6"]]},{"id":"159f9dcabd276f59","type":"debug","z":"a4633311d1bf470d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2370,"y":860,"wires":[]},{"id":"db507ead0e26e1af","type":"inject","z":"a4633311d1bf470d","name":"","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CLEAR-STORE","x":1960,"y":740,"wires":[["4b61f945350d10d6"]]}]