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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pn-cat-client

v1.6.1

Published

Cat client for nodejs.

Downloads

8

Readme

cat-client

Install

$ npm install cat-client --save

请确保你的服务器配置了/data/appdatas/cat/client.xml

Usage


var Cat = require("cat-client");

//应用初始化阶段
Cat.init({
  appName:"your-app-name"
});
//for koa middleware
app.use(Cat.middleware);


//in app

//log event
Cat.logEvent("URL","/index");

//log error
Cat.logError("error userId not found",error);

//transaction
var t = Cat.newTransaction("URL","/index");

//处理业务逻辑, 推荐使用generator同步写法,以确保其他调用setStatus complete 是在业务逻辑处理之后
//例如 yield biz();

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

API

Cat.logEvent(type , name , status, data)

新建event用以监控。

  • type - {string} Event的type,默认值是undefined。

  • name - {string} Event的name,默认值是undefined。

  • status - {string} optional ,Event的status,请使用Cat.STATUS常量, 默认成功

  • data - {string} optional, Event的data,默认值为undefined。

Cat.logError(msg,error)

新建error用以监控。

  • msg - {string} 用户需要记录的信息,默认值是undefined。

  • error - {object} Error对象。

Cat.newTransaction(type,name)

初始化生成一个transaction handler实例,包含一系列Transaction操作接口。

  • type - {string} Transaction的type,默认值为undefined。

  • name - {string} Transaction的name,默认值为undefined。

transactionHandler.setStatus(status)

设置transaction的状态,0表示成功,非零表示失败,默认值是0。

status: {string} , 参见 Cat.STATUS常量

transactionHandler.addData(data)

添加transaction的数据,默认值为undefined。

data: {string}

transactionHandler.complete()

完成transaction。

Cat.STATUS

logEvent ,transaction.setStatus 所使用的状态码

  • SUCCESS 成功
  • FAIL 失败

NOTE

如果你使用了koa以及cat.middleware , 推荐使用 this.cat 获取cat实例, 以确保所有的打点都能汇总到单个请求中

this.cat和require('cat-client') 拿到的Cat实例 API一致

Examples

  • 抓取一个URL请求的数据
//in koa middleware

var t = Cat.newTranscation('URL',this.path);

t.addData(this.url);

t.logEvent('URL','URL.Server',Ca.SUCCESS, 'Refer='+this.header.referer+';Agent='+this.header['user-agent']);

yield next;

t.setStatus(this.status < 400 ? Cat.FAIL : Cat.SUCCESS);
t.complete();

在Cat的Transaction页面就能看到按URL打的所有URL信息