New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

console-agent

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

console-agent

console-agent <img src

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 08 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc