简单的程序或脚本来检查网页的加载时间

我正在寻找一个简单的程序或脚本,你给它一个URL,它会做到以下几点:

我的目的是将这个function作为外部程序集成到Zabbix中。 我做了谷歌search,但无法find一个。

你可以用timewget命令的组合来做你想做的事 – 例如:
time wget -q http://www.google.com/

time将打印完成wget命令所需的时间(以秒/小数秒为单位),并且整个混乱的返回代码将是wget的返回代码将会是的(0 =成功,非零指示各种故障)。

这可以进一步包装在一个适当的脚本,以确定是否成功检索页面,并产生适合Zabbix拾取和使用的输出。

我使用下面的脚本,可能是从其他地方借用的基本想法。 它使用curl统计:

 estadistica () { local site=$1 echo $site echo ${site} | sed -n 's/./-/gp' curl -w ' Lookup time:\t%{time_namelookup} s Connect time:\t%{time_connect} s Pretransfer time:\t%{time_pretransfer} s Starttransfer time:\t%{time_starttransfer} s Size download:\t%{size_download} bytes Speed download:\t%{speed_download} bytes/s Total time:\t%{time_total} s ' -o /dev/null -s $site echo } for i in ${@}; do estadistica $i done 

可以说它被命名为webstats; 这是如何工作的:

 ~/src$ bash webstats http://serverfault.com/questions/295194/simple-program-or-script-to-check-load-time-of-web-page http://www.google.com http://serverfault.com/questions/295194/simple-program-or-script-to-check-load-time-of-web-page ----------------------------------------------------------------------------------------------- Lookup time: 0,009 s Connect time: 0,139 s Pretransfer time: 0,139 s Starttransfer time: 0,284 s Size download: 37298 bytes Speed download: 57153,000 bytes/s Total time: 0,653 s http://www.google.com --------------------- Lookup time: 0,084 s Connect time: 0,147 s Pretransfer time: 0,147 s Starttransfer time: 0,218 s Size download: 218 bytes Speed download: 1000,000 bytes/s Total time: 0,218 s 

如果出现问题,你可以知道它(因此告诉zabbix),因为结果数据是不合逻辑的:

 ~/src$ bash webstats http://thisdoesntexist http://thisdoesntexist ---------------------- Lookup time: 0,000 s Connect time: 0,000 s Pretransfer time: 0,000 s Starttransfer time: 0,000 s Size download: 0 bytes Speed download: 0,000 bytes/s Total time: 0,000 s 

编辑:curl的超时选项:

只是回答你的评论,curl有一个超时选项; 从它的手册页:

  --connect-timeout <seconds> Maximum time in seconds that you allow the connection to the server to take. This only limits the connection phase, once curl has connected this option is of no more use. See also the -m/--max-time option. 

我使用curl而不是wget,因为wget会生成太多的文件。 例:

 $ curl -o /dev/null -s -w %{time_total}\\n http://google.com 0.084 

接下来你应该做的 – 把它放到你的${datadir}/zabbix/externalscripts外部脚本中,并用项目types'external checks'

这个: http : //tools.pingdom.com/

另外,编写一个简单的脚本来自己完成这个任务,并以特定的格式输出会非常容易。

我认为firefox的萤火虫networking选项和pagespeed是一个不错的select

萤火虫网络