@resolveio/server-lib 20.5.15 → 20.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,i){return new(r=r||Promise)(function(o,t){function fulfilled(e){try{step(i.next(e))}catch(e){t(e)}}function rejected(e){try{step(i.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?o(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(fulfilled,rejected)}step((i=i.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,r){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},l={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function verb(o){return function(e){var t=[o,e];if(i)throw new TypeError("Generator is already executing.");for(;c=l&&t[l=0]?0:c;)try{if(i=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))c.label=t[1];else if(6===t[0]&&c.label<s[1])c.label=s[1],s=t;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(t)}}t=r.call(n,c)}catch(e){t=[6,e],a=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},axios_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitorFunction=exports.MonitorManagerFunction=exports.MonitorMongo=exports.MonitorManager=void 0,require("axios")),monitor_cpu_collection_1=require("../collections/monitor-cpu.collection"),monitor_memory_collection_1=require("../collections/monitor-memory.collection"),monitor_mongo_collection_1=require("../collections/monitor-mongo.collection"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common"),monitor_function_collection_1=require("../collections/monitor-function.collection"),os=require("os"),MAX_BATCH_SIZE=8388608,MonitorManager=function(){function MonitorManager(){this._instanceHostname="",this._monitorData=[],this._instanceHostname=os.hostname().replace(/\./g,"-"),this.setupIntervals(),this.setupEventLoop()}return MonitorManager.prototype.cpuAverage=function(){for(var e=0,t=0,o=os.cpus(),n=0,r=o.length;n<r;n++){var i,a=o[n];for(i in a.times)t+=a.times[i];e+=a.times.idle}return{idle:e/o.length,total:t/o.length}},MonitorManager.prototype.setupIntervals=function(){return __awaiter(this,void 0,void 0,function(){var t,n,r=this;return __generator(this,function(e){switch(e.label){case 0:if("https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,axios_1.default.get("http://169.254.169.254/latest/meta-data/instance-id")];case 2:return t=e.sent(),setInterval(function(){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,axios_1.default.post("https://backend.resolveio.com/api/health",{type:"application",id_aws_instance:t.data,version:"number"==typeof process.env.APP_VERSION?process.env.APP_VERSION.toString():process.env.APP_VERSION,version_key:process.env.APP_VERSION_KEY})];case 1:return e.sent(),[3,3];case 2:return e.sent(),[3,3];case 3:return[2]}})})},1e4),[3,4];case 3:return e.sent(),[3,4];case 4:return n=this.cpuAverage(),setInterval(function(){var e=new Date,t=r.cpuAverage(),o=1-(t.idle-n.idle)/(t.total-n.total),o=("https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_cpu_collection_1.MonitorCPUs.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,app:o,system:os.loadavg()[0]}):r.pushMonitorData({type:"monitor-cpu",data:{metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,app:o,system:os.loadavg()[0]}}),n=t,process.memoryUsage());"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_memory_collection_1.MonitorMemorys.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,physical_total:o.heapTotal,physical_used:o.heapUsed,physical_free:os.freemem(),virtual:o.rss,private:o.external,physical:os.totalmem()}):r.pushMonitorData({type:"monitor-memory",data:{metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,physical_total:o.heapTotal,physical_used:o.heapUsed,physical_free:os.freemem(),virtual:o.rss,private:o.external,physical:os.totalmem(),type:"memory"}})},3e3),[2]}})})},MonitorManager.prototype.addMongoTracker=function(e){"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?e.collection.startsWith("monitor-")||monitor_mongo_collection_1.MonitorMongos.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.date),method:e.method,doc_collection:e.collection,duration:e.duration,query:Buffer.byteLength(e.query,"utf8")<158e5?e.query:"Too Big"}):this._instanceHostname&&this.pushMonitorData({type:"monitor-mongo",data:{metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.date),method:e.method,doc_collection:e.collection,duration:e.duration,query:Buffer.byteLength(e.query,"utf8")<158e5?e.query:"Too Big"}})},MonitorManager.prototype.addFunctionTracker=function(e){"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_function_collection_1.MonitorFunctions.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.startTime),type:e.functionType,name:e.functionName,user:e.user,duration:e.duration,data:Buffer.byteLength(e.data,"utf8")<158e5?e.data:"Too Big"}):this._instanceHostname&&this.pushMonitorData({type:"monitor-function",data:{metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.startTime),type:e.functionType,name:e.functionName,user:e.user,duration:e.duration,data:Buffer.byteLength(e.data,"utf8")<158e5?e.data:"Too Big"}})},MonitorManager.prototype.pushMonitorData=function(e){this._monitorData.push(e),this.estimateBatchSize()>=MAX_BATCH_SIZE&&this.flushMonitorData()},MonitorManager.prototype.estimateBatchSize=function(){return this._monitorData.reduce(function(e,t){return e+Buffer.byteLength(JSON.stringify(t))},0)},MonitorManager.prototype.setupEventLoop=function(){var e=this;setInterval(function(){0<e._monitorData.length&&e.flushMonitorData()},2500)},MonitorManager.prototype.flushMonitorData=function(){for(var e=[],t=0;0<this._monitorData.length&&t<MAX_BATCH_SIZE;){var o=this._monitorData.shift(),n=Buffer.byteLength(JSON.stringify(o));if(MAX_BATCH_SIZE<t+n&&0<e.length){this._monitorData.unshift(o);break}e.push(o),t+=n}try{resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLogs(e)}catch(e){console.error(new Date,"MonitorManager","Failed to flush monitor data to file:",e)}},MonitorManager}(),MonitorMongo=(exports.MonitorManager=MonitorManager,function(){function MonitorMongo(e,t,o){this._startTime=0,this._method="",this._collection="",this._query="",this._startTime=Date.now(),this._method=e,this._collection=t,this._query=o}return MonitorMongo.prototype.finish=function(){var e=Date.now(),e={date:new Date(e),method:this._method,collection:this._collection,query:this._query,duration:e-this._startTime};resolveio_server_app_1.ResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(e)},MonitorMongo}()),MonitorManagerFunction=(exports.MonitorMongo=MonitorMongo,function(){function MonitorManagerFunction(){this._functionCnt=0,this._functions=[],this._functionLastCompletedWS={}}return MonitorManagerFunction.prototype.startMonitorFunction=function(e,t,o,n,r){e=new MonitorFunction(this._functionCnt++,e,t,o,n,r);return this._functions.push(e),e.id},MonitorManagerFunction.prototype.finishMonitorFunction=function(t){var e=this._functions.find(function(e){return e.id===t});e&&(e.finish(),this._functionLastCompleted=e,this._functionLastCompletedWS[e.id_socket]=e,this._functions.splice(this._functions.map(function(e){return e.id}).indexOf(t),1))},MonitorManagerFunction.prototype.getActiveMonitorFunctions=function(){return this._functions},MonitorManagerFunction.prototype.getLastCompletedMonitorFunction=function(){return this._functionLastCompleted},MonitorManagerFunction.prototype.getLastCompletedMonitorFunctionWS=function(){return this._functionLastCompletedWS},MonitorManagerFunction}()),MonitorFunction=(exports.MonitorManagerFunction=MonitorManagerFunction,function(){function MonitorFunction(e,t,o,n,r,i){var a=this;this._timer=null,this.duration=0,this.startTime=null,this.endTime=null,this.lastTime=null,this.id_socket="",this.id=0,this.id=e,this.startTime=new Date,this.functionType=t,this.functionName=o,this.user=n,this.id_socket=r,this.data=i,this.lastTime=new Date,this._timer=setInterval(function(){var e=Date.now()-a.lastTime.getTime();e>a.duration&&(a.duration=e),a.lastTime=new Date},1e3)}return MonitorFunction.prototype.finish=function(){this._timer&&(clearInterval(this._timer),this._timer=null),this.endTime=new Date,this.duration,resolveio_server_app_1.ResolveIOServer.getMainServer().getMonitorManager().addFunctionTracker(this)},MonitorFunction}());exports.MonitorFunction=MonitorFunction;
1
+ "use strict";var __awaiter=this&&this.__awaiter||function(e,n,r,i){return new(r=r||Promise)(function(o,t){function fulfilled(e){try{step(i.next(e))}catch(e){t(e)}}function rejected(e){try{step(i.throw(e))}catch(e){t(e)}}function step(e){var t;e.done?o(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(fulfilled,rejected)}step((i=i.apply(e,n||[])).next())})},__generator=this&&this.__generator||function(n,r){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},l={next:verb(0),throw:verb(1),return:verb(2)};return"function"==typeof Symbol&&(l[Symbol.iterator]=function(){return this}),l;function verb(o){return function(e){var t=[o,e];if(i)throw new TypeError("Generator is already executing.");for(;c=l&&t[l=0]?0:c;)try{if(i=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!(s=0<(s=c.trys).length&&s[s.length-1])&&(6===t[0]||2===t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))c.label=t[1];else if(6===t[0]&&c.label<s[1])c.label=s[1],s=t;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(t)}}t=r.call(n,c)}catch(e){t=[6,e],a=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}},axios_1=(Object.defineProperty(exports,"__esModule",{value:!0}),exports.MonitorFunction=exports.MonitorManagerFunction=exports.MonitorMongo=exports.MonitorManager=void 0,require("axios")),monitor_cpu_collection_1=require("../collections/monitor-cpu.collection"),monitor_memory_collection_1=require("../collections/monitor-memory.collection"),monitor_mongo_collection_1=require("../collections/monitor-mongo.collection"),resolveio_server_app_1=require("../resolveio-server-app"),common_1=require("../util/common"),monitor_function_collection_1=require("../collections/monitor-function.collection"),os=require("os"),MAX_BATCH_SIZE=8388608,MonitorManager=function(){function MonitorManager(){this._instanceHostname="",this._monitorData=[],this._instanceHostname=os.hostname().replace(/\./g,"-"),this.setupIntervals(),this.setupEventLoop()}return MonitorManager.prototype.cpuAverage=function(){for(var e=0,t=0,o=os.cpus(),n=0,r=o.length;n<r;n++){var i,a=o[n];for(i in a.times)t+=a.times[i];e+=a.times.idle}return{idle:e/o.length,total:t/o.length}},MonitorManager.prototype.setupIntervals=function(){return __awaiter(this,void 0,void 0,function(){var t,n,r=this;return __generator(this,function(e){switch(e.label){case 0:if("https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL)return[3,4];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,axios_1.default.get("http://169.254.169.254/latest/meta-data/instance-id")];case 2:return t=e.sent(),setInterval(function(){return __awaiter(r,void 0,void 0,function(){return __generator(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,axios_1.default.post("https://backend.resolveio.com/api/health",{type:"application",id_aws_instance:t.data,version:"number"==typeof process.env.APP_VERSION?process.env.APP_VERSION.toString():process.env.APP_VERSION,version_key:process.env.APP_VERSION_KEY})];case 1:return e.sent(),[3,3];case 2:return e.sent(),[3,3];case 3:return[2]}})})},1e4),[3,4];case 3:return e.sent(),[3,4];case 4:return n=this.cpuAverage(),setInterval(function(){var e=new Date,t=r.cpuAverage(),o=1-(t.idle-n.idle)/(t.total-n.total),o=("https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_cpu_collection_1.MonitorCPUs.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,app:o,system:os.loadavg()[0]}):r.pushMonitorData({type:"monitor-cpu",data:{metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,app:o,system:os.loadavg()[0]}}),n=t,process.memoryUsage());"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_memory_collection_1.MonitorMemorys.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,physical_total:o.heapTotal,physical_used:o.heapUsed,physical_free:os.freemem(),virtual:o.rss,private:o.external,physical:os.totalmem()}):r.pushMonitorData({type:"monitor-memory",data:{metadata:{instance:r._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:e,physical_total:o.heapTotal,physical_used:o.heapUsed,physical_free:os.freemem(),virtual:o.rss,private:o.external,physical:os.totalmem(),type:"memory"}})},3e3),[2]}})})},MonitorManager.prototype.addMongoTracker=function(e){"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?e.collection.startsWith("monitor-")||monitor_mongo_collection_1.MonitorMongos.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.date),method:e.method,doc_collection:e.collection,duration:e.duration,query:Buffer.byteLength(e.query,"utf8")<158e5?e.query:"Too Big"}):this._instanceHostname&&this.pushMonitorData({type:"monitor-mongo",data:{metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.date),method:e.method,doc_collection:e.collection,duration:e.duration,query:Buffer.byteLength(e.query,"utf8")<158e5?e.query:"Too Big"}})},MonitorManager.prototype.addFunctionTracker=function(e){"string"!=typeof e.data&&(e.data=JSON.stringify(e.data)),"https://resolveio.com"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL||"http://localhost:4200"===resolveio_server_app_1.ResolveIOServer.getServerConfig().ROOT_URL?monitor_function_collection_1.MonitorFunctions.create({_id:(0,common_1.objectIdHexString)(),metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.startTime),type:e.functionType,name:e.functionName,user:e.user,duration:e.duration,data:Buffer.byteLength(e.data,"utf8")<158e5?e.data:"Too Big"}):this._instanceHostname&&this.pushMonitorData({type:"monitor-function",data:{metadata:{instance:this._instanceHostname,client:resolveio_server_app_1.ResolveIOServer.getServerConfig().CLIENT_NAME},date:new Date(e.startTime),type:e.functionType,name:e.functionName,user:e.user,duration:e.duration,data:Buffer.byteLength(e.data,"utf8")<158e5?e.data:"Too Big"}})},MonitorManager.prototype.pushMonitorData=function(e){this._monitorData.push(e),this.estimateBatchSize()>=MAX_BATCH_SIZE&&this.flushMonitorData()},MonitorManager.prototype.estimateBatchSize=function(){return this._monitorData.reduce(function(e,t){return e+Buffer.byteLength(JSON.stringify(t))},0)},MonitorManager.prototype.setupEventLoop=function(){var e=this;setInterval(function(){0<e._monitorData.length&&e.flushMonitorData()},2500)},MonitorManager.prototype.flushMonitorData=function(){for(var e=[],t=0;0<this._monitorData.length&&t<MAX_BATCH_SIZE;){var o=this._monitorData.shift(),n=Buffer.byteLength(JSON.stringify(o));if(MAX_BATCH_SIZE<t+n&&0<e.length){this._monitorData.unshift(o);break}e.push(o),t+=n}try{resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLogs(e)}catch(e){console.error(new Date,"MonitorManager","Failed to flush monitor data to file:",e)}},MonitorManager}(),MonitorMongo=(exports.MonitorManager=MonitorManager,function(){function MonitorMongo(e,t,o){this._startTime=0,this._method="",this._collection="",this._query="",this._startTime=Date.now(),this._method=e,this._collection=t,this._query=o}return MonitorMongo.prototype.finish=function(){var e=Date.now(),e={date:new Date(e),method:this._method,collection:this._collection,query:this._query,duration:e-this._startTime};resolveio_server_app_1.ResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(e)},MonitorMongo}()),MonitorManagerFunction=(exports.MonitorMongo=MonitorMongo,function(){function MonitorManagerFunction(){this._functionCnt=0,this._functions=[],this._functionLastCompletedWS={}}return MonitorManagerFunction.prototype.startMonitorFunction=function(e,t,o,n,r){e=new MonitorFunction(this._functionCnt++,e,t,o,n,r);return this._functions.push(e),e.id},MonitorManagerFunction.prototype.finishMonitorFunction=function(t){var e=this._functions.find(function(e){return e.id===t});e&&(e.finish(),this._functionLastCompleted=e,this._functionLastCompletedWS[e.id_socket]=e,this._functions.splice(this._functions.map(function(e){return e.id}).indexOf(t),1))},MonitorManagerFunction.prototype.getActiveMonitorFunctions=function(){return this._functions},MonitorManagerFunction.prototype.getLastCompletedMonitorFunction=function(){return this._functionLastCompleted},MonitorManagerFunction.prototype.getLastCompletedMonitorFunctionWS=function(){return this._functionLastCompletedWS},MonitorManagerFunction}()),MonitorFunction=(exports.MonitorManagerFunction=MonitorManagerFunction,function(){function MonitorFunction(e,t,o,n,r,i){var a=this;this._timer=null,this.duration=0,this.startTime=null,this.endTime=null,this.lastTime=null,this.id_socket="",this.id=0,this.id=e,this.startTime=new Date,this.functionType=t,this.functionName=o,this.user=n,this.id_socket=r,this.data=i,this.lastTime=new Date,this._timer=setInterval(function(){var e=Date.now()-a.lastTime.getTime();e>a.duration&&(a.duration=e),a.lastTime=new Date},1e3)}return MonitorFunction.prototype.finish=function(){this._timer&&(clearInterval(this._timer),this._timer=null),this.endTime=new Date,this.duration,resolveio_server_app_1.ResolveIOServer.getMainServer().getMonitorManager().addFunctionTracker(this)},MonitorFunction}());exports.MonitorFunction=MonitorFunction;
2
2
  //# sourceMappingURL=monitor.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/monitor.manager.ts"],"names":["axios_1","require","monitor_cpu_collection_1","monitor_memory_collection_1","monitor_mongo_collection_1","resolveio_server_app_1","common_1","monitor_function_collection_1","os","MAX_BATCH_SIZE","MonitorManager","this","_instanceHostname","_monitorData","hostname","replace","setupIntervals","setupEventLoop","prototype","cpuAverage","totalIdle","totalTick","cpus","i","len","length","type","cpu","times","idle","total","ResolveIOServer","getServerConfig","default","get","instanceId_1","_a","sent","setInterval","__awaiter","_this","post","id_aws_instance","data","version","process","env","APP_VERSION","toString","version_key","APP_VERSION_KEY","lastCPU","now","Date","endMeasure","percentageCPU","memUsage","MonitorCPUs","create","_id","objectIdHexString","metadata","instance","client","date","app","system","loadavg","pushMonitorData","memoryUsage","MonitorMemorys","physical_total","heapTotal","physical_used","heapUsed","physical_free","freemem","virtual","rss","private","external","physical","totalmem","addMongoTracker","collection","startsWith","MonitorMongos","method","doc_collection","duration","query","Buffer","byteLength","addFunctionTracker","MonitorFunctions","startTime","functionType","name","functionName","user","push","estimateBatchSize","flushMonitorData","reduce","item","JSON","stringify","batch","batchSize","shift","itemSize","unshift","getLocalLogManager","writeLogs","error","console","MonitorMongo","exports","_startTime","_method","_collection","_query","finish","endTime","mongoMonitor","getMainServer","getMonitorManager","MonitorManagerFunction","_functionCnt","_functions","_functionLastCompletedWS","startMonitorFunction","id_socket","newMonitorFunction","MonitorFunction","id","finishMonitorFunction","monitor","find","a","_functionLastCompleted","splice","map","indexOf","getActiveMonitorFunctions","getLastCompletedMonitorFunction","getLastCompletedMonitorFunctionWS","_timer","lastTime","diff","getTime","clearInterval"],"mappings":"k8CAAAA,S,iKAAAC,QAAA,OAAA,GACAC,yBAAAD,QAAA,uCAAA,EACAE,4BAAAF,QAAA,0CAAA,EACAG,2BAAAH,QAAA,yCAAA,EACAI,uBAAAJ,QAAA,yBAAA,EACAK,SAAAL,QAAA,gBAAA,EAEAM,8BAAAN,QA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AAyI,SAAiB,KACjBzI,KAAAyH,UAAY,GACZzH,KAAA4H,GAAK,EAUX5H,KAAK4H,GAAKA,EACV5H,KAAKoF,UAAY,IAAI1C,KACrB1C,KAAKqF,aAAeA,EACpBrF,KAAKuF,aAAeA,EACpBvF,KAAKwF,KAAOA,EACZxF,KAAKyH,UAAYA,EACjBzH,KAAKgC,KAAOA,EACZhC,KAAKyI,SAAW,IAAI/F,KAEpB1C,KAAKwI,OAAS7G,YAAY,WACzB,IAAI+G,EAAOhG,KAAKD,IAAG,EAAKZ,EAAK4G,SAASE,QAAO,EAEzCD,EAAO7G,EAAKiD,WACfjD,EAAKiD,SAAW4D,GAGjB7G,EAAK4G,SAAW,IAAI/F,IACrB,EAAG,GAAI,CACR,CAgBD,OAdQiF,gBAAApH,UAAAwG,OAAP,WACK/G,KAAKwI,SACRI,cAAc5I,KAAKwI,MAAM,EACzBxI,KAAKwI,OAAS,MAGfxI,KAAKgH,QAAU,IAAItE,KAEf1C,KAAK8E,SAITpF,uBAAA0B,gBAAgB8F,cAAa,EAAGC,kBAAiB,EAAGjC,mBAAmBlF,IAAI,CAC5E,EACD2H,eAAA,EAAC,GAvDYjB,QAAAiB,gBAAAA","file":"monitor.manager.js","sourcesContent":["import axios from 'axios';\nimport { MonitorCPUs } from '../collections/monitor-cpu.collection';\nimport { MonitorMemorys } from '../collections/monitor-memory.collection';\nimport { MonitorMongos } from '../collections/monitor-mongo.collection';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { LocalLogModel } from './local-log.manager';\nimport { MonitorFunctions } from '../collections/monitor-function.collection';\n\nconst os = require('os');\nconst MAX_BATCH_SIZE = 8 * 1024 * 1024; // 8MB max for safety\n\nexport class MonitorManager {\n\tprivate _instanceHostname = '';\n\tprivate _monitorData: LocalLogModel[] = [];\n\n\tconstructor() {\n\t\tthis._instanceHostname = os.hostname().replace(/\\./g, '-');\n\n\t\tthis.setupIntervals();\n\t\tthis.setupEventLoop();\n\t}\n\n\tcpuAverage() {\n\t\tvar totalIdle = 0, totalTick = 0;\n\t\tvar cpus = os.cpus();\n\n\t\tfor (var i = 0, len = cpus.length; i < len; i++) {\n\t\t\tvar cpu = cpus[i];\n\n\t\t\tfor (let type in cpu.times) {\n\t\t\t\ttotalTick += cpu.times[type];\n\t\t\t}\n\t\t\ttotalIdle += cpu.times.idle;\n\t\t}\n\n\t\treturn {\n\t\t\tidle: totalIdle / cpus.length,\n\t\t\ttotal: totalTick / cpus.length\n\t\t};\n\t}\n\n\tasync setupIntervals() {\n\t\t// Example: If not on production or localhost, do a health check\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\ttry {\n\t\t\t\tlet instanceId = await axios.get('http://169.254.169.254/latest/meta-data/instance-id');\n\n\t\t\t\tsetInterval(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/health', {\n\t\t\t\t\t\t\ttype: 'application',\n\t\t\t\t\t\t\tid_aws_instance: instanceId.data,\n\t\t\t\t\t\t\tversion: typeof process.env.APP_VERSION === 'number'\n\t\t\t\t\t\t\t\t? (<any>process.env.APP_VERSION).toString()\n\t\t\t\t\t\t\t\t: process.env.APP_VERSION,\n\t\t\t\t\t\t\tversion_key: process.env.APP_VERSION_KEY\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcatch(e) {}\n\t\t\t\t}, 10000);\n\t\t\t}\n\t\t\tcatch(errHealth) {}\n\t\t}\n\n\t\tlet lastCPU = this.cpuAverage();\n\n\t\tsetInterval(() => {\n\t\t\tlet now = new Date();\n\t\t\tvar endMeasure = this.cpuAverage();\n\t\t\tvar idleDifference = endMeasure.idle - lastCPU.idle;\n\t\t\tvar totalDifference = endMeasure.total - lastCPU.total;\n\t\t\tvar percentageCPU = 1 - idleDifference / totalDifference;\n\n\t\t\t// Original local code\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tMonitorCPUs.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-cpu',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: now,\n\t\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlastCPU = endMeasure;\n\n\t\t\tconst memUsage = process.memoryUsage();\n\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tMonitorMemorys.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem()\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-memory',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: now,\n\t\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\t\tphysical: os.totalmem(),\n\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}, 3000);\n\t}\n\n\taddMongoTracker(data: MongoMonitorModel) {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!data.collection.startsWith('monitor-')) {\n\t\t\t\tMonitorMongos.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: Buffer.byteLength(data.query, 'utf8') < 15800000\n\t\t\t\t\t\t? data.query\n\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-mongo',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\t\tmethod: data.method,\n\t\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\t\tduration: data.duration,\n\t\t\t\t\t\tquery: Buffer.byteLength(data.query, 'utf8') < 15800000\n\t\t\t\t\t\t\t? data.query\n\t\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\taddFunctionTracker(data: MonitorFunction) {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t) {\n\t\t\tMonitorFunctions.create({\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\tmetadata: {\n\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t},\n\t\t\t\tdate: new Date(data.startTime),\n\t\t\t\ttype: data.functionType,\n\t\t\t\tname: data.functionName,\n\t\t\t\tuser: data.user,\n\t\t\t\tduration: data.duration,\n\t\t\t\tdata: Buffer.byteLength(data.data, 'utf8') < 15800000\n\t\t\t\t\t? data.data\n\t\t\t\t\t: 'Too Big'\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-function',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: new Date(data.startTime),\n\t\t\t\t\t\ttype: data.functionType,\n\t\t\t\t\t\tname: data.functionName,\n\t\t\t\t\t\tuser: data.user,\n\t\t\t\t\t\tduration: data.duration,\n\t\t\t\t\t\tdata: Buffer.byteLength(data.data, 'utf8') < 15800000\n\t\t\t\t\t\t\t? data.data\n\t\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushMonitorData(data: LocalLogModel) {\n\t\tthis._monitorData.push(data);\n\n\t\t// If data is huge, flush immediately to file\n\t\tif (this.estimateBatchSize() >= MAX_BATCH_SIZE) {\n\t\t\tthis.flushMonitorData();\n\t\t}\n\t}\n\n\tprivate estimateBatchSize(): number {\n\t\treturn this._monitorData.reduce((total, item) => {\n\t\t\treturn total + Buffer.byteLength(JSON.stringify(item));\n\t\t}, 0);\n\t}\n\n\tsetupEventLoop() {\n\t\t// Flush every 2.5 seconds\n\t\tsetInterval(() => {\n\t\t\tif (this._monitorData.length > 0) {\n\t\t\t\tthis.flushMonitorData();\n\t\t\t}\n\t\t}, 2500);\n\t}\n\n\tprivate flushMonitorData() {\n\t\tconst batch = [];\n\t\tlet batchSize = 0;\n\n\t\twhile (this._monitorData.length > 0 && batchSize < MAX_BATCH_SIZE) {\n\t\t\tconst item = this._monitorData.shift();\n\t\t\tconst itemSize = Buffer.byteLength(JSON.stringify(item));\n\n\t\t\tif ((batchSize + itemSize) > MAX_BATCH_SIZE && batch.length > 0) {\n\t\t\t\t// put the item back for next round\n\t\t\t\tthis._monitorData.unshift(item);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbatch.push(item);\n\t\t\tbatchSize += itemSize;\n\t\t}\n\n\t\ttry {\n\t\t\t// Now, instead of calling an external HTTP endpoint, we write the batch to disk:\n\t\t\tResolveIOServer.getLocalLogManager().writeLogs(batch);\n\t\t}\n\t\tcatch (error) {\n\t\t\tconsole.error(new Date(), 'MonitorManager', 'Failed to flush monitor data to file:', error);\n\t\t}\n\t}\n}\n\nexport interface MongoMonitorModel {\n\tdate: Date;\n\tmethod: string;\n\tcollection: string;\n\tduration: number;\n\tquery: string;\n}\n\nexport class MonitorMongo {\n\tprivate _startTime = 0;\n\tprivate _method = '';\n\tprivate _collection = '';\n\tprivate _query = '';\n\n\tconstructor(method: string, collection: string, query: string) {\n\t\tthis._startTime = Date.now();\n\t\tthis._method = method;\n\t\tthis._collection = collection;\n\t\tthis._query = query;\n\t}\n\n\tpublic finish() {\n\t\tlet endTime = Date.now();\n\n\t\tlet mongoMonitor: MongoMonitorModel = {\n\t\t\tdate: new Date(endTime),\n\t\t\tmethod: this._method,\n\t\t\tcollection: this._collection,\n\t\t\tquery: this._query,\n\t\t\tduration: endTime - this._startTime\n\t\t};\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(mongoMonitor);\n\t}\n}\n\nexport class MonitorManagerFunction {\n\tprivate _functionCnt = 0;\n\tprivate _functions: MonitorFunction[] = [];\n\tprivate _functionLastCompletedWS: { [id_socket: string]: MonitorFunction; } = {};\n\tprivate _functionLastCompleted: MonitorFunction;\n\n\tconstructor() {}\n\n\tstartMonitorFunction(\n\t\tfunctionType: MonitorFunctionType,\n\t\tfunctionName: string,\n\t\tuser: string,\n\t\tid_socket: string,\n\t\tdata: any\n\t) {\n\t\tlet newMonitorFunction = new MonitorFunction(\n\t\t\tthis._functionCnt++,\n\t\t\tfunctionType,\n\t\t\tfunctionName,\n\t\t\tuser,\n\t\t\tid_socket,\n\t\t\tdata\n\t\t);\n\n\t\tthis._functions.push(newMonitorFunction);\n\t\treturn newMonitorFunction.id;\n\t}\n\n\tfinishMonitorFunction(id: number) {\n\t\tlet monitor = this._functions.find(a => a.id === id);\n\n\t\tif (monitor) {\n\t\t\tmonitor.finish();\n\t\t\tthis._functionLastCompleted = monitor;\n\t\t\tthis._functionLastCompletedWS[monitor.id_socket] = monitor;\n\t\t\tthis._functions.splice(\n\t\t\t\tthis._functions.map(a => a.id).indexOf(id),\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t}\n\n\tgetActiveMonitorFunctions() {\n\t\treturn this._functions;\n\t}\n\n\tgetLastCompletedMonitorFunction() {\n\t\treturn this._functionLastCompleted;\n\t}\n\n\tgetLastCompletedMonitorFunctionWS() {\n\t\treturn this._functionLastCompletedWS;\n\t}\n}\n\nexport type MonitorFunctionType =\n\t'Cron Method'\n\t| 'Method'\n\t| 'User Specific Publication'\n\t| 'Publication';\n\nexport class MonitorFunction {\n\tprivate _timer: NodeJS.Timeout = null;\n\tpublic duration = 0;\n\tpublic functionType: MonitorFunctionType;\n\tpublic functionName: string;\n\tpublic user: string;\n\tpublic data: any;\n\tpublic startTime: Date = null;\n\tpublic endTime: Date = null;\n\tpublic lastTime: Date = null;\n\tpublic id_socket = '';\n\tpublic id = 0;\n\n\tconstructor(\n\t\tid: number,\n\t\tfunctionType: MonitorFunctionType,\n\t\tfunctionName: string,\n\t\tuser: string,\n\t\tid_socket: string,\n\t\tdata: any\n\t) {\n\t\tthis.id = id;\n\t\tthis.startTime = new Date();\n\t\tthis.functionType = functionType;\n\t\tthis.functionName = functionName;\n\t\tthis.user = user;\n\t\tthis.id_socket = id_socket;\n\t\tthis.data = data;\n\t\tthis.lastTime = new Date();\n\n\t\tthis._timer = setInterval(() => {\n\t\t\tlet diff = Date.now() - this.lastTime.getTime();\n\n\t\t\tif (diff > this.duration) {\n\t\t\t\tthis.duration = diff;\n\t\t\t}\n\n\t\t\tthis.lastTime = new Date();\n\t\t}, 1000);\n\t}\n\n\tpublic finish() {\n\t\tif (this._timer) {\n\t\t\tclearInterval(this._timer);\n\t\t\tthis._timer = null;\n\t\t}\n\n\t\tthis.endTime = new Date();\n\n\t\tif (this.duration >= 5000) {\n\t\t\t// Optional slow function logging or email\n\t\t}\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addFunctionTracker(this);\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/monitor.manager.ts"],"names":["axios_1","require","monitor_cpu_collection_1","monitor_memory_collection_1","monitor_mongo_collection_1","resolveio_server_app_1","common_1","monitor_function_collection_1","os","MAX_BATCH_SIZE","MonitorManager","this","_instanceHostname","_monitorData","hostname","replace","setupIntervals","setupEventLoop","prototype","cpuAverage","totalIdle","totalTick","cpus","i","len","length","type","cpu","times","idle","total","ResolveIOServer","getServerConfig","default","get","instanceId_1","_a","sent","setInterval","__awaiter","_this","post","id_aws_instance","data","version","process","env","APP_VERSION","toString","version_key","APP_VERSION_KEY","lastCPU","now","Date","endMeasure","percentageCPU","memUsage","MonitorCPUs","create","_id","objectIdHexString","metadata","instance","client","date","app","system","loadavg","pushMonitorData","memoryUsage","MonitorMemorys","physical_total","heapTotal","physical_used","heapUsed","physical_free","freemem","virtual","rss","private","external","physical","totalmem","addMongoTracker","collection","startsWith","MonitorMongos","method","doc_collection","duration","query","Buffer","byteLength","addFunctionTracker","JSON","stringify","MonitorFunctions","startTime","functionType","name","functionName","user","push","estimateBatchSize","flushMonitorData","reduce","item","batch","batchSize","shift","itemSize","unshift","getLocalLogManager","writeLogs","error","console","MonitorMongo","exports","_startTime","_method","_collection","_query","finish","endTime","mongoMonitor","getMainServer","getMonitorManager","MonitorManagerFunction","_functionCnt","_functions","_functionLastCompletedWS","startMonitorFunction","id_socket","newMonitorFunction","MonitorFunction","id","finishMonitorFunction","monitor","find","a","_functionLastCompleted","splice","map","indexOf","getActiveMonitorFunctions","getLastCompletedMonitorFunction","getLastCompletedMonitorFunctionWS","_timer","lastTime","diff","getTime","clearInterval"],"mappings":"k8CAAAA,S,iKAAAC,QAAA,OAAA,GACAC,yBAAAD,QAAA,uCAAA,EACAE,4BAAAF,QAAA,0CAAA,EACAG,2BAAAH,QAAA,yCAAA,EACAI,uBAAAJ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+B,EACAzF,GAND,IAAAH,EAAA7B,KAZQA,KAAAwI,OAAyB,KAC1BxI,KAAA8E,SAAW,EAKX9E,KAAAsF,UAAkB,KAClBtF,KAAAgH,QAAgB,KAChBhH,KAAAyI,SAAiB,KACjBzI,KAAAyH,UAAY,GACZzH,KAAA4H,GAAK,EAUX5H,KAAK4H,GAAKA,EACV5H,KAAKsF,UAAY,IAAI5C,KACrB1C,KAAKuF,aAAeA,EACpBvF,KAAKyF,aAAeA,EACpBzF,KAAK0F,KAAOA,EACZ1F,KAAKyH,UAAYA,EACjBzH,KAAKgC,KAAOA,EACZhC,KAAKyI,SAAW,IAAI/F,KAEpB1C,KAAKwI,OAAS7G,YAAY,WACzB,IAAI+G,EAAOhG,KAAKD,IAAG,EAAKZ,EAAK4G,SAASE,QAAO,EAEzCD,EAAO7G,EAAKiD,WACfjD,EAAKiD,SAAW4D,GAGjB7G,EAAK4G,SAAW,IAAI/F,IACrB,EAAG,GAAI,CACR,CAgBD,OAdQiF,gBAAApH,UAAAwG,OAAP,WACK/G,KAAKwI,SACRI,cAAc5I,KAAKwI,MAAM,EACzBxI,KAAKwI,OAAS,MAGfxI,KAAKgH,QAAU,IAAItE,KAEf1C,KAAK8E,SAITpF,uBAAA0B,gBAAgB8F,cAAa,EAAGC,kBAAiB,EAAGjC,mBAAmBlF,IAAI,CAC5E,EACD2H,eAAA,EAAC,GAvDYjB,QAAAiB,gBAAAA","file":"monitor.manager.js","sourcesContent":["import axios from 'axios';\nimport { MonitorCPUs } from '../collections/monitor-cpu.collection';\nimport { MonitorMemorys } from '../collections/monitor-memory.collection';\nimport { MonitorMongos } from '../collections/monitor-mongo.collection';\nimport { ResolveIOServer } from '../resolveio-server-app';\nimport { objectIdHexString } from '../util/common';\nimport { LocalLogModel } from './local-log.manager';\nimport { MonitorFunctions } from '../collections/monitor-function.collection';\n\nconst os = require('os');\nconst MAX_BATCH_SIZE = 8 * 1024 * 1024; // 8MB max for safety\n\nexport class MonitorManager {\n\tprivate _instanceHostname = '';\n\tprivate _monitorData: LocalLogModel[] = [];\n\n\tconstructor() {\n\t\tthis._instanceHostname = os.hostname().replace(/\\./g, '-');\n\n\t\tthis.setupIntervals();\n\t\tthis.setupEventLoop();\n\t}\n\n\tcpuAverage() {\n\t\tvar totalIdle = 0, totalTick = 0;\n\t\tvar cpus = os.cpus();\n\n\t\tfor (var i = 0, len = cpus.length; i < len; i++) {\n\t\t\tvar cpu = cpus[i];\n\n\t\t\tfor (let type in cpu.times) {\n\t\t\t\ttotalTick += cpu.times[type];\n\t\t\t}\n\t\t\ttotalIdle += cpu.times.idle;\n\t\t}\n\n\t\treturn {\n\t\t\tidle: totalIdle / cpus.length,\n\t\t\ttotal: totalTick / cpus.length\n\t\t};\n\t}\n\n\tasync setupIntervals() {\n\t\t// Example: If not on production or localhost, do a health check\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\ttry {\n\t\t\t\tlet instanceId = await axios.get('http://169.254.169.254/latest/meta-data/instance-id');\n\n\t\t\t\tsetInterval(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/health', {\n\t\t\t\t\t\t\ttype: 'application',\n\t\t\t\t\t\t\tid_aws_instance: instanceId.data,\n\t\t\t\t\t\t\tversion: typeof process.env.APP_VERSION === 'number'\n\t\t\t\t\t\t\t\t? (<any>process.env.APP_VERSION).toString()\n\t\t\t\t\t\t\t\t: process.env.APP_VERSION,\n\t\t\t\t\t\t\tversion_key: process.env.APP_VERSION_KEY\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcatch(e) {}\n\t\t\t\t}, 10000);\n\t\t\t}\n\t\t\tcatch(errHealth) {}\n\t\t}\n\n\t\tlet lastCPU = this.cpuAverage();\n\n\t\tsetInterval(() => {\n\t\t\tlet now = new Date();\n\t\t\tvar endMeasure = this.cpuAverage();\n\t\t\tvar idleDifference = endMeasure.idle - lastCPU.idle;\n\t\t\tvar totalDifference = endMeasure.total - lastCPU.total;\n\t\t\tvar percentageCPU = 1 - idleDifference / totalDifference;\n\n\t\t\t// Original local code\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tMonitorCPUs.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-cpu',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: now,\n\t\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlastCPU = endMeasure;\n\n\t\t\tconst memUsage = process.memoryUsage();\n\n\t\t\tif (\n\t\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t\t) {\n\t\t\t\tMonitorMemorys.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem()\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-memory',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: now,\n\t\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\t\tphysical: os.totalmem(),\n\t\t\t\t\t\ttype: 'memory'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}, 3000);\n\t}\n\n\taddMongoTracker(data: MongoMonitorModel) {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!data.collection.startsWith('monitor-')) {\n\t\t\t\tMonitorMongos.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: Buffer.byteLength(data.query, 'utf8') < 15800000\n\t\t\t\t\t\t? data.query\n\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-mongo',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\t\tmethod: data.method,\n\t\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\t\tduration: data.duration,\n\t\t\t\t\t\tquery: Buffer.byteLength(data.query, 'utf8') < 15800000\n\t\t\t\t\t\t\t? data.query\n\t\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\taddFunctionTracker(data: MonitorFunction) {\n\t\tif (typeof(data.data) !== 'string') {\n\t\t\tdata.data = JSON.stringify(data.data);\n\t\t}\n\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] === 'https://resolveio.com'\n\t\t\t|| ResolveIOServer.getServerConfig()['ROOT_URL'] === 'http://localhost:4200'\n\t\t) {\n\t\t\tMonitorFunctions.create({\n\t\t\t\t_id: objectIdHexString(),\n\t\t\t\tmetadata: {\n\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t},\n\t\t\t\tdate: new Date(data.startTime),\n\t\t\t\ttype: data.functionType,\n\t\t\t\tname: data.functionName,\n\t\t\t\tuser: data.user,\n\t\t\t\tduration: data.duration,\n\t\t\t\tdata: Buffer.byteLength(data.data, 'utf8') < 15800000\n\t\t\t\t\t? data.data\n\t\t\t\t\t: 'Too Big'\n\t\t\t});\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis.pushMonitorData({\n\t\t\t\t\ttype: 'monitor-function',\n\t\t\t\t\tdata: {\n\t\t\t\t\t\tmetadata: {\n\t\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\t\tclient: ResolveIOServer.getServerConfig()['CLIENT_NAME']\n\t\t\t\t\t\t},\n\t\t\t\t\t\tdate: new Date(data.startTime),\n\t\t\t\t\t\ttype: data.functionType,\n\t\t\t\t\t\tname: data.functionName,\n\t\t\t\t\t\tuser: data.user,\n\t\t\t\t\t\tduration: data.duration,\n\t\t\t\t\t\tdata: Buffer.byteLength(data.data, 'utf8') < 15800000\n\t\t\t\t\t\t\t? data.data\n\t\t\t\t\t\t\t: 'Too Big'\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate pushMonitorData(data: LocalLogModel) {\n\t\tthis._monitorData.push(data);\n\n\t\t// If data is huge, flush immediately to file\n\t\tif (this.estimateBatchSize() >= MAX_BATCH_SIZE) {\n\t\t\tthis.flushMonitorData();\n\t\t}\n\t}\n\n\tprivate estimateBatchSize(): number {\n\t\treturn this._monitorData.reduce((total, item) => {\n\t\t\treturn total + Buffer.byteLength(JSON.stringify(item));\n\t\t}, 0);\n\t}\n\n\tsetupEventLoop() {\n\t\t// Flush every 2.5 seconds\n\t\tsetInterval(() => {\n\t\t\tif (this._monitorData.length > 0) {\n\t\t\t\tthis.flushMonitorData();\n\t\t\t}\n\t\t}, 2500);\n\t}\n\n\tprivate flushMonitorData() {\n\t\tconst batch = [];\n\t\tlet batchSize = 0;\n\n\t\twhile (this._monitorData.length > 0 && batchSize < MAX_BATCH_SIZE) {\n\t\t\tconst item = this._monitorData.shift();\n\t\t\tconst itemSize = Buffer.byteLength(JSON.stringify(item));\n\n\t\t\tif ((batchSize + itemSize) > MAX_BATCH_SIZE && batch.length > 0) {\n\t\t\t\t// put the item back for next round\n\t\t\t\tthis._monitorData.unshift(item);\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tbatch.push(item);\n\t\t\tbatchSize += itemSize;\n\t\t}\n\n\t\ttry {\n\t\t\t// Now, instead of calling an external HTTP endpoint, we write the batch to disk:\n\t\t\tResolveIOServer.getLocalLogManager().writeLogs(batch);\n\t\t}\n\t\tcatch (error) {\n\t\t\tconsole.error(new Date(), 'MonitorManager', 'Failed to flush monitor data to file:', error);\n\t\t}\n\t}\n}\n\nexport interface MongoMonitorModel {\n\tdate: Date;\n\tmethod: string;\n\tcollection: string;\n\tduration: number;\n\tquery: string;\n}\n\nexport class MonitorMongo {\n\tprivate _startTime = 0;\n\tprivate _method = '';\n\tprivate _collection = '';\n\tprivate _query = '';\n\n\tconstructor(method: string, collection: string, query: string) {\n\t\tthis._startTime = Date.now();\n\t\tthis._method = method;\n\t\tthis._collection = collection;\n\t\tthis._query = query;\n\t}\n\n\tpublic finish() {\n\t\tlet endTime = Date.now();\n\n\t\tlet mongoMonitor: MongoMonitorModel = {\n\t\t\tdate: new Date(endTime),\n\t\t\tmethod: this._method,\n\t\t\tcollection: this._collection,\n\t\t\tquery: this._query,\n\t\t\tduration: endTime - this._startTime\n\t\t};\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(mongoMonitor);\n\t}\n}\n\nexport class MonitorManagerFunction {\n\tprivate _functionCnt = 0;\n\tprivate _functions: MonitorFunction[] = [];\n\tprivate _functionLastCompletedWS: { [id_socket: string]: MonitorFunction; } = {};\n\tprivate _functionLastCompleted: MonitorFunction;\n\n\tconstructor() {}\n\n\tstartMonitorFunction(\n\t\tfunctionType: MonitorFunctionType,\n\t\tfunctionName: string,\n\t\tuser: string,\n\t\tid_socket: string,\n\t\tdata: any\n\t) {\n\t\tlet newMonitorFunction = new MonitorFunction(\n\t\t\tthis._functionCnt++,\n\t\t\tfunctionType,\n\t\t\tfunctionName,\n\t\t\tuser,\n\t\t\tid_socket,\n\t\t\tdata\n\t\t);\n\n\t\tthis._functions.push(newMonitorFunction);\n\t\treturn newMonitorFunction.id;\n\t}\n\n\tfinishMonitorFunction(id: number) {\n\t\tlet monitor = this._functions.find(a => a.id === id);\n\n\t\tif (monitor) {\n\t\t\tmonitor.finish();\n\t\t\tthis._functionLastCompleted = monitor;\n\t\t\tthis._functionLastCompletedWS[monitor.id_socket] = monitor;\n\t\t\tthis._functions.splice(\n\t\t\t\tthis._functions.map(a => a.id).indexOf(id),\n\t\t\t\t1\n\t\t\t);\n\t\t}\n\t}\n\n\tgetActiveMonitorFunctions() {\n\t\treturn this._functions;\n\t}\n\n\tgetLastCompletedMonitorFunction() {\n\t\treturn this._functionLastCompleted;\n\t}\n\n\tgetLastCompletedMonitorFunctionWS() {\n\t\treturn this._functionLastCompletedWS;\n\t}\n}\n\nexport type MonitorFunctionType =\n\t'Cron Method'\n\t| 'Method'\n\t| 'User Specific Publication'\n\t| 'Publication';\n\nexport class MonitorFunction {\n\tprivate _timer: NodeJS.Timeout = null;\n\tpublic duration = 0;\n\tpublic functionType: MonitorFunctionType;\n\tpublic functionName: string;\n\tpublic user: string;\n\tpublic data: any;\n\tpublic startTime: Date = null;\n\tpublic endTime: Date = null;\n\tpublic lastTime: Date = null;\n\tpublic id_socket = '';\n\tpublic id = 0;\n\n\tconstructor(\n\t\tid: number,\n\t\tfunctionType: MonitorFunctionType,\n\t\tfunctionName: string,\n\t\tuser: string,\n\t\tid_socket: string,\n\t\tdata: any\n\t) {\n\t\tthis.id = id;\n\t\tthis.startTime = new Date();\n\t\tthis.functionType = functionType;\n\t\tthis.functionName = functionName;\n\t\tthis.user = user;\n\t\tthis.id_socket = id_socket;\n\t\tthis.data = data;\n\t\tthis.lastTime = new Date();\n\n\t\tthis._timer = setInterval(() => {\n\t\t\tlet diff = Date.now() - this.lastTime.getTime();\n\n\t\t\tif (diff > this.duration) {\n\t\t\t\tthis.duration = diff;\n\t\t\t}\n\n\t\t\tthis.lastTime = new Date();\n\t\t}, 1000);\n\t}\n\n\tpublic finish() {\n\t\tif (this._timer) {\n\t\t\tclearInterval(this._timer);\n\t\t\tthis._timer = null;\n\t\t}\n\n\t\tthis.endTime = new Date();\n\n\t\tif (this.duration >= 5000) {\n\t\t\t// Optional slow function logging or email\n\t\t}\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addFunctionTracker(this);\n\t}\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@resolveio/server-lib",
3
- "version": "20.5.15",
3
+ "version": "20.6.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "package": "./build_package.sh",