可以搜集系统的 CPU 、内存、负载等信息,以及系统进程的 CPU 、内存等相关信息可自由组合,当然也支持集群模式,即如果你有多台机器多个进程仍然可以使用该包收集简单的监控信息来监控你的应用。
做了一个简单的微信小程序 Demo 来显示如何在界面中查看监控信息:
wechat-tinymonit 代码详见: 点击查看 wechat ui 代码
$ npm install tinymonit -g
运行测试:
$ npm run test
运行测试覆盖率:
$ npm run cover
const tm = require('tinymonit');
const osstat = tm.osstat;
Promise.resolve()
.then(() => osstat([8122]))
.then((stat) => console.log(r));
const Part = require('tinymonit').part;
let part = new Part(3000, {
timeout: 100,
pid: process.pid // this is defalut
});
const Central = require('tinymonit').central;
let ctl = new Central({
timeout: 100,
parts:[
3000,
[3001, 200]
//'[remote ip]:[port]'
]
});
// start collect performance data from 3000, 3001
Promise.resolve()
.then(() => ctl.collect())
.then((allstats) => {
// do sth
});
const tm = require('tinymonit');
const pid = process.pid;
const osstat = tm.osstat;
const alarm = tm.alarm;
Promise.resolve()
.then(() => osstat([pid]))
.then((stat) => {
console.log(alarm.should_cpu_alarm(rstat, 1));
console.log(alarm.should_mem_alarm(stat));
console.log(alarm.should_load_alarm(stat));
console.log(alarm.should_procs_alarm(stat, 2));
});