httpstat:一个检查网站性能的 curl 统计分析工具

运维 系统运维
httpstat 是一个 Python 脚本,它以美妙妥善的方式反映了 curl 统计分析,它是一个单一脚本,兼容 Python 3 ,在用户的系统上不需要安装额外的软件(依赖)。

httpstat 是一个 Python 脚本,它以美妙妥善的方式反映了 curl 统计分析,它是一个单一脚本,兼容 Python 3 ,在用户的系统上不需要安装额外的软件(依赖)。

从本质上来说它是一个 cURL 工具的封装,意味着你可以在 URL 后使用几个有效的 cURL 选项,但是不包括 -w、 -D、 -o、 -s 和 -S 选项,这些已经被 httpstat 使用了。

httpstat Curl 统计分析工具

你可以看到上图的一个 ASCII 表显示了每个过程消耗多长时间,对我来说最重要的一步是“服务器处理server processing” – 如果这个数字很高,那么你需要优化你网站服务器来加速访问速度

网站或服务器优化你可以查看我们的文章:

  1. 5 个优化 Apache Web 服务器性能的技巧
  2. 使 Apache 和 Nginx 性能提升 10 倍
  3. 如何使用 Gzip 模块提高 Nginx 性能
  4. 15 个优化 MySQL/MariaDB 性能的建议

使用下面安装说明和用法来获取 httpstat 检查出你的网站速度。

在 Linux 系统中安装 httpstat

你可以使用两种合理的方法安装 httpstat :

  1. 使用 wget 命令直接从它的 Github 仓库获取如下:
  1. $ wget -c https://raw.githubusercontent.com/reorx/httpstat/master/httpstat.py 
  1. 使用 pip(这个方法允许 httpstat 作为命令安装到你的系统中)像这样:
  1. $ sudo pip install httpstat 

注:确保 pip 包已经在系统上安装了,如果没使用你的发行版包管理器 yum 或 apt安装它。

在 Linux 中如何使用 httpstat

httpstat 可以根据你安装它的方式来使用,如果你直接下载了它,进入下载目录使用下面的语句运行它:

  1. $ python httpstat.py url cURL_options 

如果你使用 pip 来安装它,你可以作为命令来执行它,如下表:

  1. $ httpstat url cURL_options 

查看 httpstat 帮助页,命令如下:

  1. $ python httpstat.py --help 
  2. 或 
  3. $ httpstat --help 

httpstat 帮助:

  1. Usage: httpstat URL [CURL_OPTIONS] 
  2. httpstat -h | --help 
  3. httpstat --version 
  4. Arguments: 
  5. URL     url to request, could be with or without `http(s)://` prefix 
  6. Options: 
  7. CURL_OPTIONS  any curl supported options, except for -w -D -o -S -s, 
  8. which are already used internally. 
  9. -h --help     show this screen. 
  10. --version     show version. 
  11. Environments: 
  12. HTTPSTAT_SHOW_BODY    Set to `trueto show response body in the output
  13. note that body length is limited to 1023 bytes, will be 
  14. truncated if exceeds. Default is `false`. 
  15. HTTPSTAT_SHOW_IP      By default httpstat shows remote and local IP/port address. 
  16. Set to `falseto disable this feature. Default is `true`. 
  17. HTTPSTAT_SHOW_SPEED   Set to `trueto show download and upload speed. 
  18. Default is `false`. 
  19. HTTPSTAT_SAVE_BODY    By default httpstat stores body in a tmp file, 
  20. set to `falseto disable this feature. Default is `true
  21. HTTPSTAT_CURL_BIN     Indicate the curl bin path to use. Default is `curl` 
  22. from current shell $PATH. 
  23. HTTPSTAT_DEBUG        Set to `trueto see debugging logs. Default is `false

从上面帮助命令的输出,你可以看出 httpstat 已经具备了一些可以影响其行为的环境变量。

使用它们,只需输出适当的值的这些变量到 .bashrc 或 .zshrc 文件。

例如:

  1. export  HTTPSTAT_SHOW_IP=false 
  2. export  HTTPSTAT_SHOW_SPEED=true 
  3. export  HTTPSTAT_SAVE_BODY=false 
  4. export  HTTPSTAT_DEBUG=true 

你一旦添加完它们,保存文件然后运行下面的命令使改变生效:

  1. $ source ~/.bashrc 

你可以指定使用 cURL 执行文件的路径,默认使用的是当前 shell 的 $PATH 环境变量

下面是一些展示 httpstat 如何工作的例子。

  1. $ python httpstat.py google.com 
  2. 或 
  3. $ httpstat google.com 

httpstat – 展示网站统计分析

接下来的命令中:

  1. -X 命令标记指定一个客户与 HTTP 服务器连接的请求方法。
  2. --data-urlencode 这个选项将会把数据(这里是 a=b)按 URL 编码的方式编码后再提交。
  3. -v 开启详细模式。
  1. $ python httpstat.py httpbin.org/post -X POST --data-urlencode "a=b" -v 

httpstat – 定制提交请求

你可以查看 cURL 的帮助获取更多有用的高级选项,或者浏览 httpstat 的 Github 仓库: https://github.com/reorx/httpstat

这篇文章中,我们讲述了一个有效的工具,它以简单和整洁方式来查看 cURL 统计分析。如果你知道任何类似的工具,别犹豫,让我们知道,你也可以问问题或评论这篇文章或 httpstat,通过下面反馈。

责任编辑:武晓燕 来源: Linux中国
相关推荐

2019-09-18 09:05:58

技术SQLDevOps

2015-08-19 09:40:51

统计分析

2010-06-01 14:30:06

Mrtg教程

2010-06-07 17:26:41

Mrtg教程

2022-02-18 12:58:35

go-monitor工具服务质量

2012-09-25 14:18:51

Linux桌面环境

2011-05-27 13:56:04

网站流量

2009-06-29 15:25:21

SessionJSP

2014-06-04 09:42:41

工业控制系统APT

2016-10-18 14:13:21

数据统计模型

2010-12-30 09:44:10

C#Attribute

2015-02-27 09:53:06

Countly

2011-03-14 14:41:59

大数据数据中心

2015-01-05 17:28:02

JMP

2023-10-25 09:39:46

2013-09-10 14:50:12

数组面试题

2014-10-28 14:59:42

手游付费行为数据统计分析

2021-06-10 09:53:04

数据统计统计分析数据

2016-12-01 17:33:52

微信

2020-05-15 15:21:58

SPSS数据分析
点赞
收藏

51CTO技术栈公众号