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

bot-monitor-sdk

v1.2.4

Published

used for statistics and analysis

Readme

FAQ

这是什么?

这是BotMonitor SDK,它可以帮助您收集和分析您开发的bot运行中产生的数据,帮助您实时查看应用运行状态,及时发现应用中存在的问题,提升用户体验。目前,BotMonitor提供应用性能分析、用户行为统计。使用BotMonitor,您可以方便的在自己的DBP平台查看Bot的用户量、会话量、请求量、QPS以及Session的相关统计数据指标。

我该怎么使用?

准备工作

公钥上传

为了保证Bot的数据安全,我们后端会验证Bot的身份。所以在使用BotMonitor提供的数据统计功能之前,你需要在本地使用openssl生成RSA公钥和私钥对,然后把公钥上传到DBP平台上和你的Bot关联起来。步骤如下:

  1. 打开终端,执行openssl genrsa -out rsa_private_key.pem 1024命令生成私钥
  2. 执行openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem生成和私钥匹配的公钥。
  3. 使用编辑器打开公钥文件,将内容上传到DBP平台对应的Bot空间。
  4. 保存私钥文件,我们下面会用到。

注意,如果不进行公钥上传或者公钥版本配置的操作,你仍可以正常的开发和使用Bot,但是无法使用Bot的数据统计和Bot回调DuerOS的功能。

在DuerOS Bot SDK里使用BotMonitor

DuerOS Bot SDK是一个帮助开发Bot的SDK,SDK里封装DuerOS协议,自动集成了BotMonitor对Bot运行中的数据统计功能。我们强烈建议你使用DuerOS Bot SDK开发度秘的Bot。使用DuerOS Bot SDK开发Bot有以下好处:

  1. DuerOS Bot SDK会和DuerOS的协议一起升级,避免DuerOS对Bot的协议升级对你开发的Bot造成影响。
  2. DuerOS Bot SDK自动集成了BotMonitor,你无需在手动引入BotMonitor就能使用基础的数据统计功能。

关于如何使用DuerOS Bot SDK,请查看DBP SDK安装及技能创建

如果你使用DuerOS Bot SDK开发的bot,你需要在你的Bot里配置环境信息,这里我们假设你把上面生成的rsa_private_key.pem文件内容赋值给privateKey变量,假设你有一个在测试环境的Bot叫jokebot:

//do something
//privateKey为私钥内容,0代表你的Bot在DBP平台debug环境,1或者其他整数代表online环境
jokebot.botMonitor.setEnvironmentInfo(privateKey, 0);

环境信息配置完成后,你需要打开BotMonitor数据采集上报开关(默认是开启的,你可以根据自己需求打开或者关闭),true代表打开,false代表关闭:

jokebot.botMonitor.setMonitorEnabled(true);

基础的数据统计功能已在DuerOS Bot SDK里帮你做好,你只需要关心以下两个函数,在自己关心的操作前后打点:

//自定义操作的打点统计,参数名是这个操作的唯一标识字符串,为了方便在平台上展示查看,请尽量使用有意义的名字。假如你的Bot里有个获取天气的函数weatherInfo(city='');,你想了解这个操作的性能,你可以把这个操作命名为get_weatherinfo_task:
//在获取天气的操作之前设置开始计时
jokebot.botMonitor.setOprationTic('get_weatherinfo_task')
jokebot.weatherInfo('beijing');
//在获取天气的操作结束之后结束计时
jokebot.botMonitor.setOprationToc('get_weatherinfo_task');

这样你就能方便的看到基础的数据统计和你打点的事件性能统计。

直接使用BotMonitor

如果你没有使用DuerOS Bot SDK开发bot,你需要在bot中手动引入BotMonitor, BotMonitor通过npm管理。执行如下命令进行安装:

npm install bot-monitor-sdk

安装完成后,你需要在你的Bot里引入BotMonitor:

const BotMonitor = require('bot-monitor-sdk');

然后使用BotMonitor提供的接口在Bot里打点,打点的方法如下:

1. 初始化BotMonitor。使用request初始化一个BotMonitor,request是Object类型,是bot协议里请求对象。

```
jokebot.botMonitor = new BotMonitor(request);
```
2. 初始化环境信息,打开数据采集上报开关。这里我们假设你把上面生成的rsa_private_key.pem文件内容赋值给privateKey变量,假设你有一个在测试环境的Bot叫jokebot:
```
//privateKey为私钥内容,0代表你的Bot在DBP平台debug环境,1或者其他整数代表online环境
jokebot.botMonitor.setEnvironmentInfo(privateKey, 0);
//true打开数据采集上报开(默认打开,你也可以手动关闭)
jokebot.botMonitor.setMonitorEnabled(true);
```

3. 对bot中的系统事件进行打点统计
	下面不同事件的打点调用了不同的函数,方便你在开发者平台上区分自己打点的不同事件。

```
//intent是bot协议里的意图,你需要在处理intent的回调函数前后打点
//intent回调函数处理开始前调用
jokebot.botMonitor.setEventStart();
//do something
//intent回调函数处理结束调用,注意:如果你的回调函数里有多个return的地方,需要在每一个return操作之前调用事件结束函数,保证在每个请求结束都能调到setEventEnd函数
jokebot.botMonitor.setEventEnd();

//如果你订阅了端上触发的事件,比如端上设置闹铃成功、端上音乐播放,对端上事件打点统计,你就可以在自己的端上事件处理的回调里前后打点
//端上事件callback处理开始调用
jokebot.botMonitor.setDeviceEventStart();
//do something
//端上事件callback处理结束调用
jokebot.botMonitor.setDeviceEventStart();
```


4. 对自定义操作打点统计

```
//自定义操作的打点统计,参数名是这个操作的唯一标识字符串,为了方便在平台上展示查看,请尽量使用有意义的名字。假如你的Bot里有个获取天气的函数weatherInfo(city='');你想了解这个操作的性能,你可以把这个操作命名为get_weatherinfo_task:
//在获取天气的操作之前设置开始计时
jokebot.botMonitor.setOprationTic('get_weatherinfo_task')
jokebot.weatherInfo('beijing');
//在获取天气的操作结束之后结束计时
jokebot.botMonitor.setOprationToc('get_weatherinfo_task');
```

5. 设置Bot返回数据并上报相关统计数据

```
//在请求返回时,您需要设置返回的数据responseData,responseData是一个Object,是返回给dueros的应答,假如定义这个请求返回的变量为responseData,我们可以通过下面代码设置返回数据:
jokebot.botMonitor.setResponseData(responseData);
```
6. 把数据上报到后端

```
jokebot.botMonitor.uploadData();
```

预留的功能

这部分的统计是预留功能,目前在DBP平台暂时还不能看到相关数据。如果你对相关的统计结果比较感兴趣。建议你在Bot里手动加入相关的打点: 如果你的Bot使用了打开APP的指令,你可以对打开的APP打点记录:

```
//设置打开的ApplicationName、packagename、deeplink
jokebot.botMonitor.setAppName("手机百度");
jokebot.botMonitor.setPackageName("com.baidu.test");
jokebot.botMonitor.setDeepLink("http://www.baidu.com/");
```

如果你的Bot使用了打开音频的指令,你可以对打开的音频进行记录:

```
//设置打开的音频链接
jokebot.botMonitor.setAudioUrl("https://www.baidu.com/link?url=UuDVofVvZ78dcyLAB7wi47bp9OCXYXAblirMkd3wAKZZZSonnVOfAKu6OlqzDUVNcHkL2uNAbRI0IQjldD-3R_&wd=&eqid=bdb97034000031ca0000000259f17f91");	
```

我们后续会根据大家打点统计的情况来决定是否在平台上增加展示对应的统计数据。