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

@ch0918/monitor

v1.0.2

Published

A lightweight front-end monitor library

Downloads

10

Readme

前端监控 sdk

监控前端报错,将报错信息上报到阿里云日志系统,方便快速排查问题;收集前端性能相关的数据,针对性优化。目前只是快速把功能实现了,还有很大的优化空间。

  1. 支持监控以下类型异常
  • 一般的 js 错误
  • 资源加载错误
  • 调用接口错误
  • 页面白屏
  1. 支持监控性能相关指标
  • 页面加载时间
  • 页面 FP、FCP、FMP、LCP、FID 等时间
  • 长任务
  1. 支持自定义埋点数据上报

安装

npm install @ch0918/monitor

vue3 中使用

import { createApp } from 'vue';
import { ChMonitor } from '@ch0918/monitor';

const app = createApp();
const monitor = new ChMonitor({
  config: {
    // 阿里云日志系统域名
    host: '',
    // 阿里云日志系统项目名
    project: '',
    // 阿里云日志系统仓库名
    logstore: '',
  },
});
app.use(monitor);

vue2 中使用

import Vue from 'vue';
import { ChMonitor } from '@ch0918/monitor';

const monitor = new ChMonitor({
  config: {
    // 阿里云日志系统域名
    host: '',
    // 阿里云日志系统项目名
    project: '',
    // 阿里云日志系统仓库名
    logstore: '',
  },
});
Vue.use();

通过 cdn 使用

阿里云日志系统

由于本 SDK 主要是将采集到的数据上传到阿里云日志系统中,所以需要先开通阿里云日志服务,方法如下:

  1. 登录阿里云平台选择日志服务 阿里云日志服务 选择日志服务
  2. 创建项目,调用 sdk 配置需要的 project 字段 创建项目
  3. 创建 logstore,调用 sdk 配置需要的 logstore 字段 创建logstore
  4. 创建成功 仓库
  5. 调用 sdk 诶之需要的 host 字段 host

配置项

| 名称 | 字段类型 | 默认 | 描述 | | :-------------------------- | :------------------------- | :----------- | :-------------------------------------------------------------------------- | | config.host | string | undefined | 阿里云日志服务域名,详见上面说明 | | config.project | string | undefined | 阿里云日志服务项目名,详见上面说明 | | config.logstore | string | undefined | 阿里云日志服务仓库名,详见上面说明 | | monitorJsErr | boolean | true | 是否监控普通的 js 错误 | | monitorResourceErr | boolean | true | 是否监控资源加载类型错误 | | monitorPromiseErr | boolean | true | 是否监控 promise 类型错误 | | monitorBlankScreenErr | boolean | true | 是否监控白屏 | | monitorXHRErr | boolean | true | 是否监控接口报错 | | monitorLongTask | boolean | true | 是否监控长任务 | | longTaskTime | number | 100 毫秒 | 定义长任务的时间 | | monitorPermanceFirstInput | boolean | true | 是否监控首次可交互时间指标 | | monitorPermancePain | boolean | true | 是否监控绘制时间指标 | | monitorLoadTime | boolean | true | 是否监控加载时间指标 | | send | function(data, callback) | - | 手动上传数据,data.config 的 project,host,logstore 三个参数必传 | | monitorBlankScreen | function(data) | - | 在需要的地方手动监控白屏,data.config 的 project,host,logstore 三个参数必传 |

// 举个例子
import { send, monitorBlankScreen, ChMonitor } from '@ch0918/monitor';

const config = { host: 'xxx', project: 'xxx', logstore: 'xxx' };
const monitor = new ChMonitor({
  config,
});
// 手动调方法上传日志
send(
  {
    config,
    uid: 1,
    token: 'abc',
  },
  () => {
    console.log('send success');
  }
);
// 在需要的地方开启白屏监控
monitorBlankScreen({ config });

TODO

  • [x] 基本的数据采集功能
  • [ ] 改成 TypeScript 重写
  • [ ] 添加单元测试
  • [ ] 新增 server 服务,将采集到的数据上传到数据库中
  • [ ] 新增后台看板功能