node-red-contrib-device-stats
Version:
Node-RED nodes for Device Statistics
1 lines • 961 B
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=function(n){n.nodes.registerType("DeviceStats",function t(e){var o=this;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),n.nodes.createNode(this,e),this.name=e.name,this.mem=e.mem,this.nw=e.nw,this.load=e.load,this.hostname=e.hostname,this.useString=e.useString,this.collector=new _stats.StatsCollector(this),this.status({}),this.on("input",function(e){clearTimeout(o.timeout),delete o.timeout,o.status({fill:"red",shape:"dot",text:"device-stats.status.heartbeat"});var s=e?e.payload:null;o.collector.collect(s).then(function(t){(o.useString||s&&s.useString)&&(t=JSON.stringify(t)),e.payload=t,o.send(e),o.timeout=setTimeout(function(){o.timeout&&o.status({})},750)}).catch(function(t){n.log.warn(n._("device-stats.errors.unknown",{error:t})),o.status({})})})})};var _stats=require("./stats");module.exports=exports.default;
;