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

@mpxjs/mp-api-monitor

v0.0.12

Published

mini program api invoking monitor

Downloads

16

Readme

@mpxjs/mp-api-monitor

在小程序中对于全局API及实例API的调用同运行时性能有很大关联,首先,大部分的全局API调用都比较耗时(超过10ms),过度调用会拖慢js本身的执行,其次,很多API调用本身就与运行时性能存在直接关系,例如实例API中的this.setData和全局API中的wx.getLocation等,不当的调用方式会在很大程度上影响到小程序的运行时性能,而这些问题往往在小程序业务开发时会被忽略掉。

为了发现解决业务代码小程序API不当调用的问题,我们设计开发了@mpxjs/mp-api-monitor SDK,通过该SDK我们能够监听到小程序全局API及实例API的调用,记录调用信息,生成统计摘要,便于开发者发现并定位小程序中存在的不当API调用;同时该SDK支持自定义报警配置,能够便于用户对小程序的API调用情况进行长期监控;最后SDK也在许多层面提供了自定义拓展机制,便于用户进行高度定制的API调用情况监控。

本SDK会对API进行代理,在调用和返回时执行统计逻辑,在一定程度上产生运行时开销,我们强烈建议仅在开发环境下作为问题排查的手段使用本SDK,而不要在生产环境下使用,可以使用Mpx提供的env条件编译或者process.env.NODE_ENV进行环境定义与判断。

安装

npm install --save-dev @mpxjs/mp-api-monitor

使用实例

import { 
  APIMonitor, 
  getParallelismRule,
  getSizeRule
} from '@mpxjs/mp-api-monitor'

const monitor = new APIMonitor()

const error = (msg) => {
  console.error(msg)
}
// 添加报警规则:request并发数不应该超过10
monitor.addWarningRule('request', getParallelismRule({
  parallelism: 10,
  onWarning: error
}))
// 添加报警规则:setData单次发送数据不应该超过10K
monitor.addWarningRule('setData', getSizeRule({
  size: 10000,
  count: 1,
  onWarning: error
}))

monitor.startRecord()
setTimeout(()=>{
  // 也可在任意时机调用相关方法查看API调用情况
  console.log(monitor.getSummary())
}, 10000)

API参考

https://github.com/mpx-ecology/mp-api-monitor/blob/master/docs/index.md

License

Apache-2.0