1.0.0-rc.2 • Published 4 years ago

fe-monitor-perf v1.0.0-rc.2

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 years ago

fe-monitor-perf

前端性能监控采集sdk

安装

npm安装

$ npm install fe-monitor-perf

CDN

<script src="https://cdn.jsdelivr.net/npm/fe-monitor-perf@(version)/lib/perf.js"></script>
<!-- 例如 -->
<script src="https://cdn.jsdelivr.net/npm/fe-monitor-perf@1.0.0-rc.1/lib/perf.js"></script>

使用方式

import Perf from 'perf';

Perf.install({
    url: 'http://some.com/api',
    delay: 1000,
    ignoreUrls: ['/api/...'],
    random: 1 
});

配置参数

参数名描述类型
url上报地址string
delay上报延迟时间int
ignoreUrls不想监控的静态资源或者请求array
random抽样上报(0-1)float

上报数据格式

    {
        id: ***,
        type: 1,
        time: 1566527694723,
        isFirstPage: false,
        currentPage: "http://0.0.0.0:8889/#/process/list",
        prePage: "http://localhost.bcetest.baidu.com:8889/demo",
        firstPagePerf: {
            appcache: 0,
            connect: 0,
            userReady: 166,
            domReady: 548,
            initDomTree: 154,
            loadEvent: 0,
            loadPage: 714,
            lookupDomain: 0,
            readyStart: 4,
            redirect: 0,
            request: 5,
            ttfb: 9,
            unloadEvent: 0,
            whitePage: 109
        },
        hashPagePerf: {
            domTime: 225.9900000062771
        },
        resourceList: [
            {
                decodedBodySize: 6376,
                duration: "14.87",
                method: "GET",
                name: "https://bce.bdstatic.com/console/dist/img/process.svg",
                nextHopProtocol: "h2",
                type: "css"
            },
            {
                decodedBodySize: 4402,
                duration: "5.06",
                method: "GET",
                name: "http://0.0.0.0:8889/api/process/list?pageNo=1&pageSize=10",
                nextHopProtocol: "http/1.1",
                type: "xmlhttprequest"
            }
        ]
    }

上报参数说明

参数名描述类型
id上报idstring
type上报类型,1为页面级上报,2为ajax上报int
time时间戳string
isFirstPage是否为首页bool
currentPage当前页面string
prePage前一个页面string
firstPagePerf首页性能object
--appcacheDNS缓存时间int
--connectTCP建立连接完成握手的时间int
--userReady用户可操作的时间节点int
--domReady页面解析dom耗时int
--initDomTree请求完毕至DOM加载int
--loadEvent执行 onload 回调函数的时间int
--loadPage页面加载完成的时间int
--lookupDomainDNS查询时间int
--readyStart准备新页面时间耗时int
--redirect重定向的时间int
--requestrequest请求耗时int
--ttfb读取页面第一个字节的时间int
--unloadEvent卸载页面的时间int
--whitePage白屏时间int
hashPagePerf路由页的性能object
--domTimedom解析时间string
resourceList资源以及ajax请求性能array
--decodedBodySize响应数据长度int
--duration耗时int
--method请求方法GET/POSTstring
--name资源链接string
--nextHopProtocol网络协议string
--type资源类型(img/css/xmlhttprequest...)string