System Information Monitor

Im working on a smart car project and i needed homepage for server to see its status so i made a simple flow that i want to share with you. You will need node-red-contrib-cpu & node-red-contrib-interval & node-red-contrib-os & node-red-dashboard & https://github.com/mstum/TimeSpan.js

I didnt add any graphs because they make dashboard laggy as hell.

It has 3 groups, system information that shows you yours system info, cpu usage and memory usage.

Only 4 cores supported rn, you can add more, just read functions, its not hard.

[{"id":"20d8286f.365ad8","type":"tab","label":"Homepage","disabled":false,"info":""},{"id":"d245b225.57c2e","type":"OS","z":"20d8286f.365ad8","name":"","x":2110,"y":2360,"wires":[["c2f88a04.fb4e78"]]},{"id":"472ff50d.21a54c","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":2,"width":0,"height":0,"name":"","label":"Hostname","format":"{{msg.payload}}","layout":"row-spread","x":2490,"y":2280,"wires":[]},{"id":"e91395d5.65e058","type":"inject","z":"20d8286f.365ad8","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":1890,"y":2540,"wires":[["d245b225.57c2e","31d4bd25.312d22","99d5114b.2f06b","754fb58a.92801c"]]},{"id":"f27ac320.32f1","type":"debug","z":"20d8286f.365ad8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":2170,"y":3340,"wires":[]},{"id":"c2f88a04.fb4e78","type":"function","z":"20d8286f.365ad8","name":"Hostname","func":"hostname = {payload: msg.payload.hostname};\ntype = {payload: msg.payload.type};\nplatform = {payload: msg.payload.platform};\narch = {payload: msg.payload.arch};\nrelease = {payload: msg.payload.release};\nreturn [hostname, type, platform, arch, release];","outputs":5,"noerr":0,"x":2290,"y":2360,"wires":[["472ff50d.21a54c"],["5c226171.0f2b7"],["6a851e16.46759"],["cd441e8c.d1537"],["5370315d.02da5"]]},{"id":"31d4bd25.312d22","type":"Uptime","z":"20d8286f.365ad8","name":"","x":2120,"y":2600,"wires":[["66c17437.85c0bc"]]},{"id":"66c17437.85c0bc","type":"function","z":"20d8286f.365ad8","name":"TimeSpan","func":"function pad(n) {\n    return (n < 10) ? (\"0\" + n) : n;\n}\n\nvar seconds = parseInt(msg.payload.uptime);\nvar timespan = context.global.get('timespan');\nvar ts = timespan.fromSeconds(seconds);\nmsg.payload = ts.days + \":\" + pad(ts.hours) + \":\" + pad(ts.minutes) + \":\" + pad(ts.seconds);\nreturn msg;","outputs":1,"noerr":0,"x":2280,"y":2600,"wires":[["52db1961.3b89a8"]]},{"id":"5c226171.0f2b7","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":3,"width":0,"height":0,"name":"","label":"Type","format":"{{msg.payload}}","layout":"row-spread","x":2470,"y":2320,"wires":[]},{"id":"6a851e16.46759","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":5,"width":0,"height":0,"name":"","label":"Platform","format":"{{msg.payload}}","layout":"row-spread","x":2480,"y":2360,"wires":[]},{"id":"cd441e8c.d1537","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":6,"width":0,"height":0,"name":"","label":"Arch","format":"{{msg.payload}}","layout":"row-spread","x":2470,"y":2400,"wires":[]},{"id":"5370315d.02da5","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":4,"width":0,"height":0,"name":"","label":"Release","format":"{{msg.payload}}","layout":"row-spread","x":2480,"y":2440,"wires":[]},{"id":"52db1961.3b89a8","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":1,"width":0,"height":0,"name":"","label":"Up time","format":"{{msg.payload}}","layout":"row-spread","x":2480,"y":2600,"wires":[]},{"id":"63dc68f7.01f9d8","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":8,"width":0,"height":0,"name":"","label":"CPU 1","format":"{{msg.model + \"\"}}","layout":"col-center","x":2670,"y":2300,"wires":[]},{"id":"30c37f04.fd62c","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":9,"width":0,"height":0,"name":"","label":"CPU 2","format":"{{msg.model + \"\"}}","layout":"col-center","x":2670,"y":2340,"wires":[]},{"id":"79b2f7f3.8e7778","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":10,"width":0,"height":0,"name":"","label":"CPU 3","format":"{{msg.model + \"\"}}","layout":"col-center","x":2670,"y":2380,"wires":[]},{"id":"3ae52e0f.366912","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":11,"width":0,"height":0,"name":"","label":"CPU 4","format":"{{msg.model + \"\"}}","layout":"col-center","x":2670,"y":2420,"wires":[]},{"id":"99d5114b.2f06b","type":"Memory","z":"20d8286f.365ad8","name":"","x":2120,"y":2720,"wires":[["d8c1ad3e.29de2"]]},{"id":"d8c1ad3e.29de2","type":"function","z":"20d8286f.365ad8","name":"Memory","func":"var totalmem = msg.payload.totalmem;\nvar freemem = msg.payload.freemem;\nvar usedmem = totalmem - freemem;\nvar usedmemMB = Math.floor((usedmem / 1048576) * 100) / 100;\nvar totalmemMB = Math.floor((totalmem / 1048576) * 100) / 100;\nvar freememMB = Math.floor((freemem / 1048576) * 100) / 100;\nvar usedmemGB = Math.floor((usedmemMB / 1024) * 100) / 100;\nvar freememGB = Math.floor((freememMB / 1024) * 100) / 100;\nvar totalmemGB = Math.floor((totalmemMB / 1024) * 100) / 100;\ntotalmem = {payload: totalmem, mb: totalmemMB, gb: totalmemGB};\nmemusage = {payload: msg.payload.memusage};\nusedmem = {payload: usedmem, mb: usedmemMB, gb: usedmemGB};\nfreemem = {payload: freemem, mb: freememMB, gb: freememGB};\nreturn [totalmem, memusage, usedmem, freemem];","outputs":4,"noerr":0,"x":2280,"y":2720,"wires":[["c803c55b.02da88","23476256.80109e"],["ec0cff65.7f68d"],["757e614c.795dc"],["7286d476.f8c35c"]]},{"id":"7f5bea18.58d694","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"5248d644.832088","order":1,"width":"8","height":"8","gtype":"gage","title":"CPU","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2670,"y":2460,"wires":[]},{"id":"754fb58a.92801c","type":"cpu","z":"20d8286f.365ad8","name":"","msgCore":true,"msgOverall":true,"x":2130,"y":2520,"wires":[["a9a93204.2cf3"]]},{"id":"a9a93204.2cf3","type":"function","z":"20d8286f.365ad8","name":"CPU","func":"var getContext = function(str) {\n  return context.get(str) || {};\n}\nvar setContext = function(str, obj) {\n  return context.set(str, obj);\n}\nvar topics = [\n    \"core_1\",\n    \"core_2\",\n    \"core_3\",\n    \"core_4\",\n    \"overall\"\n];\n\nvar msgs = [\n    getContext(topics[0]),\n    getContext(topics[1]),\n    getContext(topics[2]),\n    getContext(topics[3]),\n    getContext(topics[4])\n];\n\nswitch(msg.topic)\n{\n    case topics[0]:\n        setContext(topics[0], msg);\n        return [msg, null, null, null, null];\n    case topics[1]:\n        setContext(topics[1], msg);\n        return [null, msg, null, null, null];\n    case topics[2]:\n        setContext(topics[2], msg);\n        return [null, null, msg, null, null];\n    case topics[3]:\n        setContext(topics[3], msg);\n        return [null, null, null, msg, null];\n    case topics[4]:\n        setContext(topics[4], msg);\n        return [null, null, null, null, msg];\n}\n\nreturn msgs;","outputs":5,"noerr":0,"x":2470,"y":2520,"wires":[["63dc68f7.01f9d8","67c0177d.b039a8","d4366758.2cfd08"],["30c37f04.fd62c","f6093cb.b8a74c","6e85d626.748e88"],["79b2f7f3.8e7778","123ac2c3.5da6dd","230dc32.be8403c"],["3ae52e0f.366912","27019838.88d138","ae6cb242.fe155"],["7f5bea18.58d694"]]},{"id":"67c0177d.b039a8","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"5248d644.832088","order":3,"width":"2","height":"2","gtype":"gage","title":"Core 1","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2670,"y":2500,"wires":[]},{"id":"f6093cb.b8a74c","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"5248d644.832088","order":4,"width":"2","height":"2","gtype":"gage","title":"Core 2","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2670,"y":2540,"wires":[]},{"id":"123ac2c3.5da6dd","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"5248d644.832088","order":6,"width":"2","height":"2","gtype":"gage","title":"Core 3","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2670,"y":2580,"wires":[]},{"id":"27019838.88d138","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"5248d644.832088","order":7,"width":"2","height":"2","gtype":"gage","title":"Core 4","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2670,"y":2620,"wires":[]},{"id":"d4366758.2cfd08","type":"ui_text","z":"20d8286f.365ad8","group":"5248d644.832088","order":8,"width":"2","height":"1","name":"","label":"MHz","format":"{{msg.speed}}","layout":"col-center","x":2670,"y":2660,"wires":[]},{"id":"6e85d626.748e88","type":"ui_text","z":"20d8286f.365ad8","group":"5248d644.832088","order":9,"width":"2","height":"1","name":"","label":"MHz","format":"{{msg.speed}}","layout":"col-center","x":2670,"y":2700,"wires":[]},{"id":"230dc32.be8403c","type":"ui_text","z":"20d8286f.365ad8","group":"5248d644.832088","order":11,"width":"2","height":"1","name":"","label":"MHz","format":"{{msg.speed}}","layout":"col-center","x":2670,"y":2740,"wires":[]},{"id":"ae6cb242.fe155","type":"ui_text","z":"20d8286f.365ad8","group":"5248d644.832088","order":12,"width":"2","height":"1","name":"","label":"MHz","format":"{{msg.speed}}","layout":"col-center","x":2670,"y":2780,"wires":[]},{"id":"c803c55b.02da88","type":"ui_text","z":"20d8286f.365ad8","group":"afc31343.2448","order":7,"width":"8","height":"1","name":"Memory","label":"Memory {{msg.gb}} GB","format":"{{msg.mb}} MB","layout":"row-spread","x":2480,"y":2640,"wires":[]},{"id":"ec0cff65.7f68d","type":"ui_gauge","z":"20d8286f.365ad8","name":"","group":"2c9c8674.f7b96a","order":0,"width":"8","height":"8","gtype":"gage","title":"Memory","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"70","seg2":"90","x":2480,"y":2720,"wires":[]},{"id":"23476256.80109e","type":"ui_text","z":"20d8286f.365ad8","group":"2c9c8674.f7b96a","order":0,"width":0,"height":0,"name":"Memory","label":"Memory {{msg.gb}} GB","format":"{{msg.mb}} MB","layout":"row-spread","x":2480,"y":2680,"wires":[]},{"id":"757e614c.795dc","type":"ui_text","z":"20d8286f.365ad8","group":"2c9c8674.f7b96a","order":0,"width":0,"height":0,"name":"Used Memory","label":"Used Memory {{msg.gb}} GB","format":"{{msg.mb}} MB","layout":"row-spread","x":2500,"y":2760,"wires":[]},{"id":"7286d476.f8c35c","type":"ui_text","z":"20d8286f.365ad8","group":"2c9c8674.f7b96a","order":0,"width":0,"height":0,"name":"Free Memory","label":"Free Memory {{msg.gb}} GB","format":"{{msg.mb}} MB","layout":"row-spread","x":2490,"y":2800,"wires":[]},{"id":"afc31343.2448","type":"ui_group","z":"","name":"System Information","tab":"630b9fc3.95e5d","order":1,"disp":true,"width":"8","collapse":true},{"id":"5248d644.832088","type":"ui_group","z":"","name":"CPU Status","tab":"630b9fc3.95e5d","order":2,"disp":true,"width":"8","collapse":true},{"id":"2c9c8674.f7b96a","type":"ui_group","z":"","name":"Memory Status","tab":"630b9fc3.95e5d","order":3,"disp":true,"width":"8","collapse":true},{"id":"630b9fc3.95e5d","type":"ui_tab","z":"","name":"Homepage","icon":"dashboard"}]
DjordjeMandic

Flow Info

created 10 months ago

Node Types

Core
  • debug (x1)
  • function (x4)
  • inject (x1)
Other
  • Memory (x1)
  • OS (x1)
  • Uptime (x1)
  • cpu (x1)
  • tab (x1)
  • ui_gauge (x6)
  • ui_group (x3)
  • ui_tab (x1)
  • ui_text (x18)

Tags

  • System
  • Monitor
  • CPU
  • Memory
  • Usage
  • Dashboard
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option