nodejs流程監視模塊
此軟件包僅使用Node.js LTS版本測試。
注意:此模塊當前僅在Linux操作系統上工作。
該模塊在nodejs運行時啟動了一個單獨的線程,該線程監視並收集有關運行nodejs進程的統計信息。然後,這些統計信息通過局部域套接字通過UDP數據報作為JSON消息發送。
這是模塊報告定期報告的數據列表:
{ status:
{ pid: <pid of the node process>,
ts: <current time stamp>,
cluster: <process group id>,
reqstotal: <total requests processed by this node process server>,
utcstart: <when the process was started>,
events: <number of new reports being processed since last stats reporting>,,
cpu: <cpu usage>,
mem: <memory usage>,
cpuperreq: <cpu usage per request>,
oreqs: <current open requests count>,
sys_cpu: <system cpu load>,
oconns: <current open connections count>,
user_cpu: <user cpu load>,
rps: <requests per second>,
kbs_out: <kbs of data transferred since last stats reporting>,
elapsed: <time elapsed since last event>,
kb_trans: <total kbs of data transferred>,
jiffyperreq: <cpu usage in terms of ticks per request>,
gc: {
scavenge: { count: <number>, elapsed_ms: <number>, max_ms: <number> },
marksweep: { count: <number>, elapsed_ms: <number>, max_ms: <number> }
}
}
}
它通過在process.monitor.gc上創建僅閱讀的屬性來提供運行的nodejs應用程序,以便能夠進行內省垃圾收集活動:
count :發生GC停止世界事件的次數elapsed :累積時間(以毫秒為單位)與NPM一起做:
npm install monitr
var monitor = require ( 'monitr' ) ; monitor . start ( ) ;產生線程並監視過程。每秒寫入套接字路徑。
monitor . stop ( ) ;終止線程並關閉插座。
monitor . setIpcMonitorPath ( '/tmp/my-process-stats.mon' ) ;設置數據報套接字名稱以編寫統計數據。默認為 /tmp/nodejs.s.mon
Monitr支持自定義健康功能,該應用程序可以報告自己的健康。將以下方法添加到Process.Monitor設置並獲取健康信息。
setHealthStatus ( isDown , statusCode )
isDown ( )
getStatusCode ( )
getStatusTimestamp ( ) - Return seconds when setHealthStatus was last called
getStatusDate ( ) - Return Date object一旦調用了Sethealthstatus,上述狀態JSON將有其他字段。
health_status_timestamp : < timestamp when the setHealthStatus was invoked , in sec > ,
health_is_down : < app is down or up , boolean > ,
health_status_code: < health status code >Monitr安裝了一個自定義的SIGHUP處理程序,該處理程序將可選地打印出當前正在執行的JavaScript的NodeJS堆棧返回。這對於調試NodeJS進程可能卡住可能很有用。
它在系統上查找 /proc /*文件以報告CPU使用情況。它在系統上查找/proc/pid/*文件以報告自己的統計數據。 process.monitor.*方法由lib/monitor.js設置。
它調用process.monitor。 *自監視啟動以來的總請求的方法( reqstotal ),飛行中的當前請求( oreqs ),當前的開放連接( oconns )(OCONNS)和自監視啟動以來返回的總數據( kb_trans )。注意:當啟用KeepAlive時, oreqs可能大於oconns 。
它將每個報告間隔的以下統計數據連接到V8垃圾收集鉤(對於每種GC類型)上。
count :調用GC類型的次數elapsed_ms :總計時間nodejs線程被阻止max_ms :最大時間被任何一個GC事件阻止請參閱示例/readme.md,以顯示這些功能使用的示例。