httpstat - 用于检查网站性能的 Curl 统计工具
httpstat 是一个 Python 脚本,它以一种引人入胜且定义明确的方式反映curl统计信息,它是一个与 Python 3 兼容的单个文件,不需要用户安装额外的软件(依赖项)系统。
它本质上是 cURL 工具的包装,意味着您可以在 URL 后使用多个有效的 cURL 选项,不包括选项 -w、-D、 >-o、-s 和 -S,它们已被 httpstat 使用。
您可以在上图中看到一个ASCII表,显示每个进程花费的时间,对我来说最重要的步骤是“服务器处理” - 如果这个数字更高,那么您需要调整您的服务器以加快网站速度。
对于网站或服务器调整,您可以在此处查看我们的文章:
- 调整 Apache Web 服务器性能的 5 个技巧
- 将 Apache 和 Nginx 性能提升至 10 倍
- 如何使用 Gzip 模块提升 Nginx 性能
- 调整 MySQL/MariaDB 性能的 15 个技巧
使用以下安装说明和用法获取httpstat来检查您的网站速度。
在 Linux 系统中安装 httpstat
您可以使用两种可能的方法安装 httpstat 实用程序:
1. 使用 wget 命令直接从 Github 存储库获取它,如下所示:
wget -c https://raw.githubusercontent.com/reorx/httpstat/master/httpstat.py
2.使用pip(此方法允许httpstat作为命令安装在您的系统上),如下所示:
sudo pip install httpstat
注意:确保系统上安装了 pip 软件包,如果没有,请使用分发包管理器 yum 或 apt 安装它。
如何在 Linux 中使用 httpstat
httpstat 可以根据您安装的方式使用,如果您直接下载它,请在下载目录中使用以下语法运行它:
python httpstat.py url cURL_options
如果您使用 pip 安装它,您可以将其作为以下形式的命令执行:
httpstat url cURL_options
要查看 httpstat 的帮助页面,请发出以下命令:
python httpstat.py --help
OR
httpstat --help
Usage: httpstat URL [CURL_OPTIONS]
httpstat -h | --help
httpstat --version
Arguments:
URL url to request, could be with or without `http(s)://` prefix
Options:
CURL_OPTIONS any curl supported options, except for -w -D -o -S -s,
which are already used internally.
-h --help show this screen.
--version show version.
Environments:
HTTPSTAT_SHOW_BODY Set to `true` to show response body in the output,
note that body length is limited to 1023 bytes, will be
truncated if exceeds. Default is `false`.
HTTPSTAT_SHOW_IP By default httpstat shows remote and local IP/port address.
Set to `false` to disable this feature. Default is `true`.
HTTPSTAT_SHOW_SPEED Set to `true` to show download and upload speed.
Default is `false`.
HTTPSTAT_SAVE_BODY By default httpstat stores body in a tmp file,
set to `false` to disable this feature. Default is `true`
HTTPSTAT_CURL_BIN Indicate the curl bin path to use. Default is `curl`
from current shell $PATH.
HTTPSTAT_DEBUG Set to `true` to see debugging logs. Default is `false`
从上面帮助命令的输出中,您可以看到 httpstat 有一组影响其行为的有用环境变量。
要使用它们,只需在 .bashrc
或 .zshrc
文件中导出具有适当值的变量即可。
例如:
export HTTPSTAT_SHOW_IP=false
export HTTPSTAT_SHOW_SPEED=true
export HTTPSTAT_SAVE_BODY=false
export HTTPSTAT_DEBUG=true
添加完毕后,保存文件并运行以下命令以使更改生效:
source ~/.bashrc
您也可以指定要使用的 cURL 二进制路径,默认为当前 shell ` PATH 环境变量中的curl。
下面的几个示例展示了 httpsat 的工作原理。
python httpstat.py google.com
OR
httpstat google.com
在下一个命令中:
-x
命令标志指定与 HTTP 服务器通信时使用的自定义请求方法。--data-urlencode
data 在打开 URL 编码的情况下发布数据(在本例中为 a=b)。-v
启用详细模式。
python httpstat.py httpbin.org/post -X POST --data-urlencode "a=b" -v
您可以浏览 cURL 手册页以获取更多有用和高级的选项,或者访问 httpstat Github 存储库:https://github.com/reorx/httpstat
在本文中,我们介绍了一个有用的工具,用于监控 cURL 统计信息,这是一种简单明了的方法。如果您知道任何此类工具,请随时告诉我们,您也可以通过下面的反馈部分对本文或 httpstat 提出问题或发表评论。