Node-RED Process Details (Debugging, Linux)

This example flow will let you monitor the Operating System process details for your Node-RED instance.

To make this work, you need to know the PID (Process Identifier) of your Node-RED instance. The easiest way to do that is to grab it on startup and add it to the global variables from settings.js. Add the following to your settings.js file & restart NR:

...
functionGlobalContext: {
    'pid': process.pid
},
...

The data is taken from the /proc part of the Linux filing system for which you can find the specification in the Kernel docs. Specifically, it will tell you the details of the memory used by Node-RED. We are using /proc/<pid>/status here. However, there are plenty of other things you could also look up in a similar way as illustrated by this console command output:

$ ls /proc/28692/
autogroup   cmdline          cwd@     fdinfo/     maps       mountstats  oom_score      root@      stack   syscall
auxv        comm             environ  io          mem        net/        oom_score_adj  sched      stat    task/
cgroup      coredump_filter  exe@     limits      mountinfo  ns/         pagemap        schedstat  statm   wchan
clear_refs  cpuset           fd/      map_files/  mounts     oom_adj     personality    smaps      status

$ cat /proc/28692/net/sockstat
sockets: used 172
TCP: inuse 18 orphan 0 tw 30 alloc 29 mem 3
UDP: inuse 9 mem 5
UDPLITE: inuse 0
RAW: inuse 0
FRAG: inuse 0 memory 0

$ cat /proc/28692/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             7336                 7336                 processes
Max open files            4096                 4096                 files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       7336                 7336                 signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us
[{"id":"726d8e6c.963a3","type":"comment","z":"106a5b82.ef95a4","name":"Get details of NR process","info":"See:\n\nhttps://www.kernel.org/doc/Documentation/filesystems/proc.txt\n\nFor this to work, you need to set the PID\n(Process ID) for Node-Red. The easiest way\nto do this is to define it in your settings.js\n\nAdd the following to settings.js:\n```\n...\nfunctionGlobalContext: {\n\t\t'pid'\t\t\t: process.pid\n    },\n...\n```","x":229,"y":1363,"wires":[]},{"id":"9f6b4d5c.531da","type":"inject","z":"106a5b82.ef95a4","name":"","topic":"process/status","payload":"pid","payloadType":"global","repeat":"","crontab":"","once":false,"x":160,"y":1400,"wires":[["3609f028.21a15"]]},{"id":"a1f4d4dd.9ca9c8","type":"exec","z":"106a5b82.ef95a4","command":"cat","addpay":true,"append":"","useSpawn":"","timer":"","name":"cat /proc/<pid>/status","x":460,"y":1400,"wires":[["3fda85a9.fddfba"],[],[]]},{"id":"3fda85a9.fddfba","type":"debug","z":"106a5b82.ef95a4","name":"","active":false,"console":"false","complete":"false","x":670,"y":1400,"wires":[]},{"id":"3609f028.21a15","type":"function","z":"106a5b82.ef95a4","name":"","func":"msg.payload = '/proc/' + msg.payload + '/status';\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":1400,"wires":[["a1f4d4dd.9ca9c8"]]}]

Flow Info

Created 8 years, 3 months ago
Updated 5 years ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • exec (x1)
  • function (x1)
  • inject (x1)

Tags

  • debug
  • os
  • linux
  • memory
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option