1.简介
1.1 SpeedTest是干嘛的?
- 测试上性和下行带宽(即当前网络的能力)
- 测试网络延时 (即网络的稳定性)
1.2 SpeedTest的特点
- 无需依赖浏览器:支持web,客户端,命令行三种方式运行
- 支持远程服务器和低功耗设备:通过关闭预分配内存参数降低内存消耗
- 可实现自动化脚本测一段时间网速:在命令行下编写shell脚本结合crontab可以获取一天内不同时间段的网速
- 支持不同操作系统的命令行测速:支持windows,linux,macos以及Android和Ios。
- 通过CSV,JSONL或 JSON查看测速结果:支持多次输出格式
1.3 相关测试场景
- 打开web页面,加载部分资源失效
- 打开web页面,websocket接口超时
- 打开web页面,上传图片和下载文件超时失败
- 验证公网限速是否生效
- 检测网络抖动以及延时
2.Speedtest的打开方式
2.1 web方式
2.2 客户端方式
2.3 命令行
命令行是方便和灵活的方式,结合脚本可以灵活地制定出各种SpeedTest-Cli的使用场景。
2.3.1 安装
首先需要注意的是,只有用pip安装才会安装到最新版的SpeedTest-cli,无论是brew,yum还是apt,最后安装的版本都有可能是老版本。
2.3.1.1 Mac(brew安装)
brew install speedtest-cli
2.3.1.2 Centos(yum安装)
1) 查找speedcli-test2.3.1.3 Ubuntu(apt安装)
2.3.1.4 pip安装方式(推荐)
#此方法需要预装python2和pip pip install git+https://github.com/sivel/speedtest-cli.git
2.3.2 命令行执行
2.3.2.1 帮助
speedtest-cli -h optional arguments: -h, --help show this help message and exit //指定该参数将不测试下载速度,默认是要测试下载速度的,建议不要指定。 --no-download Do not perform download test //指定该参数将不测试上传速度,默认是要测试上传速度的,建议不要指定。 --no-upload Do not perform upload test //使用单信道,默认使用多信道,测试单文件上传下载可以开启此项。 --single Only use a single connection instead of multiple. This simulates a typical file transfer. // 默认单位使用位(bit),开启此项会使用单位为字节(bytes),一个字节相当于8个位。此参数无法影响csv和json,图像输出中的单位(仍旧是bit)。 --bytes Display values in bytes instead of bits. Does not affect the image generated by --share, nor output from --json or --csv //生成一个报告的url,用于分享给别人查看 --share Generate and provide a URL to the speedtest.net share results image, not displayed with --csv //输出概要结果,而不是详细结果 --simple Suppress verbose output, only show basic information //输出为csv格式,速度单位限定为bit/s --csv Suppress verbose output, only show basic information in CSV format. Speeds listed in bit/s and not affected by --bytes //设定csv的分隔符,默认为逗号 --csv-delimiter CSV_DELIMITER Single character delimiter to use in CSV output. Default "," //输出csv的header,就是表头 --csv-header Print CSV headers //输出为json格式,速度单位限定为bit/s --json Suppress verbose output, only show basic information in JSON format. Speeds listed in bit/s and not affected by --bytes //查看当前speedtest用于测速的目的服务器 --list Display a list of speedtest.net servers sorted by distance //指定目的服务器ID进行测试,这里的ID为--list查询到的服务器ID --server SERVER Specify a server ID to test against. Can be supplied multiple times //排除目的服务器ID进行测试,这里的ID为--list查询到的服务器ID --exclude EXCLUDE Exclude a server from selection. Can be supplied multiple times //这里试了下,貌似目的服务器不存在,超时了 -mini MINI URL of the Speedtest Mini server //指定源ip,其实就是本机ip,可以用ifconifg查看本机ip --source SOURCE Source IP address to bind to //设置http超时时间,默认为10s --timeout TIMEOUT HTTP timeout in seconds. Default 10 //指定--secure后,会使用https协议进行通信 --secure Use HTTPS instead of HTTP when communicating with speedtest.net operated servers //这里是speedcli-test的内存使用策略,默认开启就好,指定此参数会占用过多内存 --no-pre-allocate Do not pre allocate upload data. Pre allocation is enabled by default to improve upload performance. To support systems with insufficient memory, use this option to avoid a MemoryError //查看对应版本 --version Show the version number and exit
2.3.2.2 实例
博主:测试生财(一个不为996而996的测开码农)
座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。
内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。
csdn:https://blog.csdn.net/ccgshigao
博客园:https://www.cnblogs.com/qa-freeroad/
51cto:https://blog.51cto.com/14900374
微信公众号:测试生财(定期分享独家内容和资源)
