Ubuntu application monitoring

I am trying to create a couple of flows in Node Red 3.1.0 running on Ubuntu that will send a HTTP JSON or MQTT message when an application, such as Chrome or other application for example, opens or closes on that local system. Is this possible and if so how do I do that?

Welcome to the forum @dweb32.

Perhaps the pgrep command will work.
Here node-red is running (output 1), chrome is not (output 0).

[{"id":"d2a7bbe4acf004f3","type":"exec","z":"3b562c3873fb06e7","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","winHide":false,"oldrc":false,"name":"","x":530,"y":160,"wires":[["0785a033b75dc140"],[],[]]},{"id":"0e22cf2822cdbdf7","type":"inject","z":"3b562c3873fb06e7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"node-red","payloadType":"str","x":520,"y":60,"wires":[["d1e21593fec9c7bf"]]},{"id":"d1e21593fec9c7bf","type":"change","z":"3b562c3873fb06e7","name":"Command","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"'/usr/bin/pgrep --count ' & payload & \" || true\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":80,"wires":[["d2a7bbe4acf004f3"]]},{"id":"012a51f5642ef264","type":"inject","z":"3b562c3873fb06e7","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"chrome","payloadType":"str","x":510,"y":100,"wires":[["d1e21593fec9c7bf"]]},{"id":"0785a033b75dc140","type":"change","z":"3b562c3873fb06e7","name":"As number","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number($substringBefore(payload, '\\n'))","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":160,"wires":[["77ac297536dc32f8"]]},{"id":"77ac297536dc32f8","type":"debug","z":"3b562c3873fb06e7","name":"Result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":160,"wires":[]}]

Note if the process named is not running, the pgrep exit code is 1, so exec also indicates an error "command failed".

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