作者:zhanhailiang 日期:2014-11-14

1. 简单介绍

ShowSlow是开源的前端性能监控系统,提供了下面功能:

  • 前端性能指标数据收集功能:ShowSlow原生提供了数据收集工具DOM Monster!,但也支持通过YSlow,PageSpeed等第三方工具将性能数据上报给服务端完毕收集(其server端提供了针对多达8种不同工具上报的数据收集器dommonster,dynatrace,events,har,metric,pagespeed,webpagetest,yslow);
  • 前端性能指标数据展示系统;

2. 安装与配置

1). 安装与配置

安装ShowSlow:

[root@~/software]# wget http://www.showslow.org/downloads/showslow_1.2.2.tar.bz2
[root@~/software]# tar jxf showslow_1.2.2.tar.bz2
[root@~/software]# mv showslow_1.2.2 /usr/local/wwwroot/
[root@/usr/local/wwwroot]# ln -s showslow_1.2.2 showslow
[root@/usr/local/wwwroot]# ln -s /usr/local/php/bin/php /usr/local/bin/php
[root@/usr/local/wwwroot/showslow]# make
# generating crc32 hashes of all assets that should be versioned
find ./ -type f | grep -v -E '^./(timeline|timeplot|ajax|users|svn-assets|flot\/examples)/' | grep -E '\.(png|jpg|js|gif|ico)$' | sort | xargs -n10 php crc32.php | sed -e 's/\t\.\//\t/' > asset_versions.tsv
php dbupgrade.php
Nothing to upgrade from v.34 to v.34.
cd users && make
make[1]: Entering directory `/usr/local/wwwroot/showslow_1.2.2/users'
php depcheck.php
Using PHP version 5.3.29 ... OK
PHP mysqli extension is loaded ... OK
PHP mcrypt extension is loaded ... OK
PHP curl extension is loaded ... OK
PHP mbstring extension is loaded ... OK
Found configuration file ../users_config.php
php dbupgrade.php
Nothing to upgrade from v.31 to v.31.
php aggregatepoints.php
[*** SUCCESS ***] Installation and upgrade of Startup API completed successfully
make[1]: Leaving directory `/usr/local/wwwroot/showslow_1.2.2/users'

改动ShowSlow DB配置:

[root@/usr/local/wwwroot/showslow]# cp config.sample.php config.php

配置Nginx:

server {
listen 80;
server_name showslow;
root /usr/local/wwwroot/showslow; location / {
root /usr/local/wwwroot/showslow;
index index.php index.html index.htm;
} if (!-e $request_filename) {
rewrite ^(.*)$ /index.php$1 last;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root html;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
root /usr/local/wwwroot/showslow;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

配置beacon:

1). 使用DOM Monster!

訪问http://showslow/beacon/dommonster/,将DOM
Monster!收藏为书签。然后訪问http://m.vip.com,点击书签“DOM Monster!”。例如以下:

点击“Send to Show Slow“将性能监控数据上报到server端存储;

2). 配置YSlow上报数据:

改动about:config

extensions.yslow.beaconUrl = http://showslow/beacon/yslow/
extensions.yslow.beaconInfo = grade
extensions.yslow.optinBeacon = true

然后配置“Autorun YSlow each time a web page is loaded”:

刷新页面后。抓包就能够看到性能监控数据上报HTTP请求:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmlsbGZlbGxlcg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

假设看到响应“HTTP/1.1 204 Data accepted”,就表示数据存储成功。

说明:

  /usr/local/wwwroot/showslow/beacon/yslow/index.php
/usr/local/wwwroot/showslow/global.php

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmlsbGZlbGxlcg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

3). 其他工具配置方法类似,略。

3. 数据展示系统

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmlsbGZlbGxlcg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

4. 应用场景及缺陷分析

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当作展示系统使用。

5. 參考

前端性能监控系统ShowSlow的更多相关文章

  1. 前端性能监控系统 & 前端数据分析系统

    前端监控系统 目前已经上线,欢迎使用! 背景:应工作要求,需要整理出前端项目的报错信息,尝试过很多统计工具,如: 腾讯bugly.听云.OneApm.还有一个忘记名字的工具. 因为各种原因,如: 统计 ...

  2. 前端性能监控方案window.performance 调研(转)

    1. 业界案例 目前前端性能监控系统大致为分两类:以GA为代表的代码监控和以webpagetest为代表的工具监控. 代码监控依托于js代码并部署到需监控的页面,手动计算时间差或者使用浏览器的的API ...

  3. Performance — 前端性能监控利器

    Performance是一个做前端性能监控离不开的API,最好在页面完全加载完成之后再使用,因为很多值必须在页面完全加载之后才能得到.最简单的办法是在window.onload事件中读取各种数据. 大 ...

  4. Performance --- 前端性能监控

    阅读目录 一:什么是Performance? 二:使用 performance.timing 来计算值 三:前端性能如何优化? 四:Performance中方法 五:使用performane编写小工具 ...

  5. 多语言应用性能监控系统:Elastic APM

    ▶ 概述 Elastic APM 是基于 Elastic Stack 构建的应用性能监控系统.通过 Elastic APM 可以监控应用程序,收集有关请求的响应时间.数据库查询.高速缓存调用.外部 H ...

  6. 从无到有<前端异常监控系统>落地

    导火索 有一天一个测试同事的一个移动端页面白屏了,看样子是页面哪里报错了.  我自己打开页面并没有报错,最后发现报错只存在于他的手机,移动端项目又是在微信环境下,调试起来会比较麻烦,最后用他手机调试才 ...

  7. 性能监控系统 | 从0到1 搭建Web性能监控系统

    工具介绍 1. Statsd 是一个使用Node开发网络守护进程,它的特点是通过UDP(性能好,及时挂了也不影响主服务)或者TCP来监听各种数据信息,然后发送聚合数据到后端服务进行处理.常见支持的「G ...

  8. 实用|从0到1 搭建Web性能监控系统

    工具介绍 1. Statsd 是一个使用Node开发网络守护进程,它的特点是通过UDP(性能好,及时挂了也不影响主服务)或者TCP来监听各种数据信息,然后发送聚合数据到后端服务进行处理. 常见支持的「 ...

  9. CentOS7安装性能监控系统

    目录 系统描述. 开发环境. 开始之前. 安装influxdb数据库. 安装collectd 安装Grafana FAQ       influxdb的web界面没反应.   系统描述 想打造 New ...

随机推荐

  1. BZOJ 3207: 花神的嘲讽计划Ⅰ( hash + 可持久化线段树 )

    O(NK)暴力搞出所有子串的哈希值, 然后就对哈希值离散化建权值线段树, 就是主席树的经典做法了.总时间复杂度O(NK+(N+Q)logN) ----------------------------- ...

  2. Linux学习之挂载操作

    一.挂载U盘 1.使用命令:fdisk -l,查看系统硬盘和分区情况 2.插入优盘,再次用fdisk -l命令查看     大家可以发现多了一个硬盘/dev/sdb和它的一个分区/dev/sdb1 3 ...

  3. XSS【跨站脚本攻击】

    从客户端(txt="<script><a href="www...")中检测到有潜在危险的 Request.Form 值. 如果你使用的是.NET 3. ...

  4. (总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解

    PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使用经验,总结一下. 一般对负载均衡的使用是随着网站规模的提升根据不 ...

  5. [LeetCode]题解(python):139-Word Break

    题目来源: https://leetcode.com/problems/word-break/ 题意分析: 给定一个字符串s和一个字典dict,判断s是不是由字典dict里面的元素组成的. 题目思路: ...

  6. NET Core MVC 在linux上的创建及发布

    NET Core MVC 在linux上的创建及发布 前言 ASP.NET core转眼都发布半月多了,社区最近也是非常活跃,虽然最近从事python工作,但也一直对.NET念念不忘,看过了园区大神们 ...

  7. mysql 主从实现

    主库:192.168.1.19 从库:192.168.1.20 开启db_test单库复制 常见问题 参考文档 主配置  以mysql root用户登录,用下面sql创建专门用于主从复制的mysql用 ...

  8. linux shell编程总结

    linux shell编程总结 本周学习了unix/linux shell编程,参考的是<LINUX与UNIX Shell 编程指南>,David Tansley著:徐焱,张春萌等译,由机 ...

  9. ubuntu12.04&15.04 安装lamp(12.04为主)

    ubuntu 12.04&15.04下安装lamp环境 注意:如果是ubuntu15.04下,apache2.4.10的话,直接在/etc/apache2/apache2.conf文件的后边直 ...

  10. HTML5地理定位,百度地图API,知识点熟悉

    推断浏览器的兼容问题: IE9+支持地理定位,FF Chrome新版支持地理定位  if (navigator.geolocation) {        alert('支持地理定位');   } e ...