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

@lvxiaowu/monitor

v1.0.1

Published

前端异常监控、vue异常监控、js异常监控、页面性能监控、设备信息采集

Downloads

1

Readme

1、简介

@lvxiaowu/monitor 是一款前端监控工具,主要包含下面几个方面信息监控:

  • 1)前端异常监控;
  • 2)页面性能监控;
  • 3)设备信息采集;

2、异常捕获详情

  • 1)js错误信息监控;
  • 2)支持vue错误信息监控(需要将vue传入,并设置vueError:true);
  • 3)支持promise中未捕获异常信息的抓取;
  • 4)支持ajax库(xhr)异常信息捕获;
  • 5)支持console.error错误信息捕获;
  • 6)支持资源错误信息捕获。

3、页面性能监控

  • 1)重定向的时间;
  • 2)DNS 查询时间;
  • 3)DNS 缓存时间;
  • 4)卸载页面的时间;
  • 5)tcp连接耗时;
  • 6)内容加载完成的时间;
  • 7)解析dom树耗时;
  • 8)白屏时间;
  • 9)页面加载完成的时间;
  • ...

4、设备信息采集

  • 1)设备类型;
  • 2)操作系统;
  • 3)操作系统版本;
  • 4)屏幕高、屏幕宽;
  • 5)当前使用的语言-国家;
  • 6)联网类型;
  • 7)横竖屏;
  • 8)浏览器信息;
  • 9)浏览器指纹;
  • 10)userAgent;
  • ...

5、引入方式

1、支持es6方式引入
import { MonitorJS } from "@lvxiaowu/monitor";

2、支持commonjs方式引入
const MonitorJS = require("@lvxiaowu/monitor");

6、异常监控Usage

1)异常监控初始化代码:
new MonitorJS().init({
    jsError: true,
    promiseError : true,
    resourceError : true,
    ajaxError : true,
    consoleError : false, //console.error默认不处理
    vueError : false,
    url:"", //错误上报地址
    extendsInfo:{ //自定义扩展信息,一般用于数据持久化区分
        a:"", //自定义信息a(名称可自定义)
        getDynamic:()=>{  //获取动态传参  
        }
    }
})

2)参数说明:
{
    url :错误上报地址
    jsError :配置是否需要监控js错误 (默认true)
    promiseError :配置是否需要监控promise错误 (默认true)
    resourceError :配置是否需要监控资源错误 (默认true)
    ajaxError :配置是否需要监控ajax错误 (默认true)
    consoleError :配置是否需要监控console.error错误 (默认false)
    vueError :配置是否需要记录vue错误信息 (默认false)
    vue : 如需监控vue错误信息,则需要传入vue
    extendsInfo : { //自定义扩展信息,一般用于数据持久化区分
        a:"", //自定义信息a(名称可自定义)
        getDynamic:()=>{  //获取动态传参  
            
        }
    }
}

3)响应(持久化数据)说明:
{
    category:"", //错误类型(枚举):js_error 、resource_error、vue_error、promise_error、ajax_error、console_info、console_warn、console_error、unknow_error
    logType: "Info", //日志类型(枚举) Error、Warning、Info
    logInfo: "", //记录的信息
    deviceInfo:"", //设备信息(JSON字符串)
    ...extendsInfo //自定义扩展信息,一般用于数据持久化区分【如:1、项目区分(Project);2、错误大类区分(前端错误、后端错误 等等)】
}

7、上报页面性能Usage

1)页面性能信息采集代码:
new MonitorJS().monitorPerformance({
    pageId:"page_0001",  //页面唯一标示
    url:"",  //信息采集上报地址
    extendsInfo:{   //扩展信息,一般用于数据数据持久化区分
        module:"项目",
        filterOne: "page_0001",
        getDynamic:()=>{
            return {
                filterTow:()=>{},
            };
        }
    }
});

2)参数说明:
{
    pageId :页面唯一标示
    url :信息采集上报地址
}

3)响应(持久化数据)说明:
{
    time: 1565161213722, //上报时间
    deviceInfo: "", //设备信息
    markUser: "",  //用户标示
    markUv: "",  //uv采集
    pageId: "", //页面唯一标示
    performance: {
        analysisTime: 1825, //解析dom树耗时
        appcacheTime: 0,  //DNS 缓存时间
        blankTime: 8, //白屏时间
        dnsTime: 0, //DNS 查询时间
        domReadyTime: 53, //domReadyTime
        loadPage: 1878, //页面加载完成的时间
        redirectTime: 0, //重定向时间
        reqTime: 8, //请求时间
        tcpTime: 0, //tcp连接耗时
        ttfbTime: 1, //读取页面第一个字节的时间
        unloadTime: 0, //卸载页面的时间
    },
    resourceList: [
        {
            dnsTime: 1562.2399999992922, //dns查询耗时
            initiatorType: "img", //发起资源类型
            name: "https://static-venus.shandiantech.com/skio/20210528/1622170352180_chromePerformance1.png", //请求资源路径
            nextHopProtocol: "http/1.1", //http协议版本
            redirectTime: 0, //重定向时间
            reqTime: 1.1899999808520079, //请求时间
            tcpTime: 33.76000002026558, //tcp链接耗时
        }
    ],
}

8、使用时机

  1. 普通项目,页面初始化时候,就可以完成初始化监控工具(最好在业务代码的前面,避免监控有漏);
  2. vue项目,需要在new Vue之前初始化监控工具,避免监控有漏;