Skip to content

console 平台是完整的 node 监控平台,由 agent + connection + cron + web 组成。agent 是其中的 「采集/上报」模块。其余部分暂未开源

License

kaola-fed/console-agent

Repository files navigation

console-agent

架构图

agent 与 connection 交互

特性

  • 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

egg 用户推荐使用 egg-console-agent

使用

模块引入

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

About

console 平台是完整的 node 监控平台,由 agent + connection + cron + web 组成。agent 是其中的 「采集/上报」模块。其余部分暂未开源

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published