npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kigo-cat-client

v2.0.0

Published

cat nodejs 客户端

Downloads

3

Readme

kigo-cat-client

node cat 客户端 v2.0

升级须知

  • 所有埋点不需要显示的传入父 transaction
  • 需要配合 kigo-context 模块使用

EXAMPLE

var Cat = require('kigo-cat-client');

// Cat 的服务器地址,一个 server 数组,客户端会随机选取一个地址进行连接
var servers = [
  {
    host: 'cat server host',
    port: 'cat server port'
  },
  ...
]

var offset = 1;
var step = 3;

Cat.initialize({
  domain: 'your domain', 
  ip: 'your ip', // 支持模糊匹配,比如 192.168.*.*
  servers: servers,
  offset: offset, // 生成 messageId 递增数字的初始值,可选,默认为 0
  step: step, // 生成 messageId 递增数字的步数,可选,默认为 1
  maxMessageSize: 500, // 缓存的消息到达多少阀值开始丢弃,可选,默认为 1000
});

// 初始化之后可调用 Cat API 进行埋点

API

Transaction

  • Transaction 适合记录跨越系统边界的程序访问行为,比如远程调用,数据库调用,也适合执行时间较长的业务逻辑监控

  • 某些运行期单元要花费一定时间完成工作, 内部需要其他处理逻辑协助, 我们定义为 Transaction

  • Transaction 可以嵌套(如 http 请求过程中嵌套了 sql 处理)

  • 大部分的Transaction可能会失败, 因此需要一个结果状态码

代码示例

var t = Cat.newTransaction("your transaction type", "your transaction name");
Cat.logEvent("your event type", "your event name");
try {
  yourBusinessOperation();
  t.setStatus(Cat.SUCCESS);
} catch (e) {
  Cat.logError('Error' e);
  t.setStatus(Cat.ERROR);
}
t.complete();

API

Event

  • Event用来记录次数,表名单位时间内消息发生次数,比如记录系统异常,它和 Transaction 相比缺少了时间的统计,开销比 Transaction 要小

Metric

  • Metric一共有三个API,分别用来记录次数、平均、总和,统一粒度为一分钟
  1. logMetricForCount 用于记录一个指标值出现的次数

  2. logMetricForDuration 用于记录一个指标出现的平均值

  3. logMetricForSum 用于记录一个指标出现的总和

一份埋点的样例


var context = require('kigo-cat-client'); // v2.0 需要配合该模块使用

var pageName = '';
var serverIp = '';
var amount = 0;

function doTransaction() {
  var t = Cat.newTransaction('URL', pageName); // 创建一个 Transaction

  try {
    Cat.logEvent("URL.Server", serverIp, Cat.SUCCESS, 'ip=' + serverIp + '&...');
    // 记录一个业务指标,记录支付次数
    Cat.logMetricForCount('PayCount');
    // 记录一个业务指标,记录支付金额
    Cat.logMetricForSum('PayAmount', amount);

    // 业务逻辑
    yourBusinessOperation();

    t.setStatus(Cat.SUCCESS); // 设置成功状态
  } catch(e) {
    t.setStatus(Cat.ERROR); // 设置失败状态
  }

  t.complete(); // 结束 Transaction
}

context.bindContext(doTransaction)();

远程调用示例

  • client 端
var t = Cat.newTransaction('Call', 'bangactorservice_1.0.6_getRoomInfoById');
Cat.logEvent('Call.app', 'bangactorservice_1.0.6');

var attachments = Cat.logRemoteCallClient();

// 远程调用需要将 attachments 传递到服务端
doRpcClient(attachments);

t.setStatus(Cat.SUCCESS);
t.complete();
  • server 端
var t = Cat.newTransaction('Service', 'bangactorservice_1.0.6_getRoomInfoById');
// 服务端拿到客户端传过来的 attachments 调用 logRemoteCallServer 方法就可以把 transaction 关联起来
Cat.logRemoteCallServer(attachments);
Cat.logEvent('Service.app', 'bangactorservice_1.0.6');

doRpcServer();

t.setStatus(Cat.SUCCESS);
t.complete();