1. 若使用DOM Monster做为前端数据收集器,通过修改showslow/beacon/dommonster/dom-monster/src/dommonster.js和showslow/beacon/dommonster/index.php,可以实现自动化上报,代码修改请见:
修改DOM Monster支持自动上报监控数据
=======
1. 修改beacon/dommonster/index.php;去掉confirm二次确认弹出框;
https://github.com/billfeller/showslow/blob/master/beacon/dommonster/index.php
2. 修改beacon/dommonster/dom-monster/src/dommonster.js;支持自动上报数据;
https://github.com/billfeller/dom-monster/blob/master/src/dommonster.js
但其本身所得的监控粒度非常粗放,其统计表结构如下:
--
-- Table structure for table `dommonster`
--
CREATE TABLE IF NOT EXISTS `dommonster` (
`id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Measurement ID',
`version` VARCHAR(255) DEFAULT NULL COMMENT 'Version of DOM Monster bookmarklet',
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Measurement time',
`url_id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'URL ID',
`elements` BIGINT(20) UNSIGNED NOT NULL COMMENT 'number of elements [number]',
`nodecount` BIGINT(20) UNSIGNED NOT NULL COMMENT 'number of DOM nodes [number]',
`textnodes` BIGINT(20) UNSIGNED NOT NULL COMMENT 'number of Text nodes [number]',
`textnodessize` BIGINT(20) UNSIGNED NOT NULL COMMENT 'size of Text nodes [bytes]',
`contentpercent` DECIMAL(5,2) UNSIGNED NOT NULL COMMENT 'content percentage [percentage]',
`average` DECIMAL(10,1) UNSIGNED NOT NULL COMMENT 'average nesting depth [number]',
`domsize` BIGINT(20) UNSIGNED NOT NULL COMMENT 'serialized DOM size [bytes]',
`bodycount` BIGINT(20) UNSIGNED DEFAULT NULL COMMENT 'DOM tree serialization time [ms]'
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
2. 若使用YSlow等第三方工具确实实现收集细粒度的监控数据,以YSlow为例,其统计表结构如下:
--
-- Table structure for table `yslow2`
--
CREATE TABLE IF NOT EXISTS `yslow2` (
`id` BIGINT(20) UNSIGNED NOT NULL COMMENT 'Entry id',
`timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Measurement timestamp',
`ip` INT(4) UNSIGNED DEFAULT '0' COMMENT 'IP address of the agent',
`user_agent` text NOT NULL COMMENT 'User agent string',
`url_id` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0',
`w` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'size of the page in bytes',
`o` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'overall YSlow grade calculated for this profile',
`r` SMALLINT(6) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'total amount of requests with empty cache',
`i` text NOT NULL COMMENT 'testing profile used',
`lt` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'page load time',
`ynumreq` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Make fewer HTTP requests',
`ycdn` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Using CDN',
`yexpires` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Expires Headers',
`yemptysrc` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Avoid Empty Image src',
`ycompress` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Gzip components',
`ycsstop` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'CSS at the top',
`yjsbottom` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'JS at the bottom',
`yexpressions` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'CSS expressions',
`yexternal` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Make Javascript and CSS external',
`ydns` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Reduce DNS lookups',
`yminify` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Minify Javascript and CSS',
`yredirects` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Avoid URL redirects',
`ydupes` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Remove duplicate Javascript and CSS',
`yetags` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Configure entity tags (ETags)',
`yxhr` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Make AJAX cacheable',
`yxhrmethod` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Use GET for AJAX requests',
`ymindom` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Reduce the number of DOM elements',
`yno404` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Avoid HTTP 404 (Not Found) error',
`yminCOOKIE` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Reduce COOKIE size',
`yCOOKIEfree` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Use COOKIE-free domains',
`ynofilter` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Avoid AlphaImageLoader filter',
`yimgnoscale` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Do not scale images in HTML',
`yfavicon` SMALLINT(3) UNSIGNED DEFAULT NULL COMMENT 'Make favicon small and cacheable',
`details` text COMMENT 'Beacon details'
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8;
但是由于对工具的依赖,其本身无法实现自动化监控用户真实的应用场景。
针对移动端的性能监控,目前由于其本身依赖的大多数高级工具绝大多数只有PC端的版本,在移动端缺乏相应的工具支持,所以如果想使用ShowSlow作为前端性能监控平台,需要单独实现数据收集系统,而只是将ShowSlow当作展示系统使用。