V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hardog
V2EX  ›  Node.js

监控你的 Nodejs 应用(NPM 包)

  •  1
     
  •   hardog · 2016-10-08 20:51:08 +08:00 · 2064 次点击
    这是一个创建于 2754 天前的主题,其中的信息可能已经有所发展或是发生改变。

    tinymonit(Go Site)

    Build Status Coverage Status License npm Version

    可以搜集系统的 CPU 、内存、负载等信息,以及系统进程的 CPU 、内存等相关信息可自由组合,当然也支持集群模式,即如果你有多台机器多个进程仍然可以使用该包收集简单的监控信息来监控你的应用。

    使用示例

    做了一个简单的微信小程序 Demo 来显示如何在界面中查看监控信息:

    tm-wechat

    wechat-tinymonit 代码详见: 点击查看 wechat ui 代码

    特性列表

    • promisify 风格的函数
    • 可以收集系统 CPU 、内存、负载等信息
    • 可以收集系统中进程的 CPU 、内存等信息
    • 可以设置阀值告警
    • 支持集群模式

    安装

    $ 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));
    });
    
    

    License

    MIT

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5160 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 05:43 · PVG 13:43 · LAX 22:43 · JFK 01:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.