V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hardog
V2EX  ›  Node.js

监控你的 Nodejs 应用(NPM 包)

  •  1
     
  •   hardog · Oct 8, 2016 · 2515 views
    This topic created in 3498 days ago, the information mentioned may be changed or developed.

    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

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3330 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 51ms · UTC 13:29 · PVG 21:29 · LAX 06:29 · JFK 09:29
    ♥ Do have faith in what you're doing.