console-agent

0.1.0 • Public • Published

console-agent

架构图

console-agent

特性

  • Leader/Follower 进程模型,保障监控模块高可用;
  • 内置进程监控探针,采集进程信息;
  • 与 connection 模块维持长连接,上报监控信息与执行远程端命令

快速开始

注册应用

1. 进入系统

2. 创建应用

3. 记录 app_id 与 app_secret

安装依赖

$ npm i -S console-agent

创建 .kagentrc.js

module.exports = {
  "server": "http://127.0.0.1:7009",                // connection 模块暴露的地址
  "appid": "5",                                     // appid
  "secret": "84fe6510-1340-11e9-94fa-d9a76a880c81", // secret
  "cluster": "localjd"                              // 集群名
}

预加载

$ node index.js --require ./node_modules/console-agent/index.js

使用

模块引入

const agent = require('console-agent');

ready

Leader/Follower 模型建立以及与 Connection 的对接是异步过程。本地埋探针的操作应当使用 ready 函数确保流程启动完毕。

const getMysqlConnections = () => {};
 
agent.ready(() => {
    agent.guage('connections', () => {
        return getMysqlConnections()
    })
});

埋入探针 API

agent.guage

const getMysqlConnections = () => {};
agent.guage('connections', () => {
    return getMysqlConnections()
})

agent.counter

该操作用来统计某一时刻的数量,常用于统计连接数

const redisCounter = agent.counter('redis');
 
redisCounter.inc();
redisCounter.dec();

agent.histogram

该操作用来统计某一操作的数据分布,如 MIN/MAX/AVG

const redisRT = agent.histogram('redis-rt');
 
redisRT.update(35);
redisRT.update(34);
redisRT.update(33);

agent.meter

该操作用来统计某一操作的触发频率,如 QPS

const redisQPS = agent.meter('redis-qps');
 
redisRT.mark();
redisRT.mark();
redisRT.mark();

agent.timer

timermeterhistogram 的封装。

const http = require('http');
 
http.createServer((req, res) => {
    const end = res.end;
    const url = URL.parse(req.url)
    const path = url.pathname;
    const timer = kagent.timer('http');
    timer.start();
 
    res.end = function(...args1) {
      timer.close();
      kagent.meter('app/url/' + res.statusCode + '/' + path).mark();
      return Reflect.apply(end, this, args1);
    }
});

LICENSE

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i console-agent

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

7.36 MB

Total Files

1698

Last publish

Collaborators

  • junesmith