需要使用python3环境,
安装
代码语言:javascript复制pip install httpstat
源码地址: https://github.com/reorx/httpstat/blob/master/httpstat.py
使用
代码语言:javascript复制 httpstat -h
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`
通常情况下,默认参数就够用了。 如果要指定参数,可以直接在命令行里面设置,例如
代码语言:javascript复制export HTTPSTAT_SHOW_IP=false
export HTTPSTAT_SHOW_SPEED=true
export HTTPSTAT_SAVE_BODY=false
export HTTPSTAT_DEBUG=true
例子:
代码语言:javascript复制# 1 使用curl
$ curl -s -I https://cloud.tencent.com/developer/user/3663994
HTTP/1.1 200 OK
Date: Sat, 23 Sep 2023 03:26:06 GMT
Content-Type: text/html; charset=utf-8
Server: nginx
Vary: Accept-Encoding
X-Req-Id: HkDRqAi1T
Pragma: no-cache
ETag: W/"1b5f6-R3/vN8Mhnsn1PcpBX1yoSgmu6T0"
Cache-Control: must-revalidate, no-cache, no-store
Content-Length: 112118
Connection: keep-alive
EO-LOG-UUID: 5463840665232321097
EO-Cache-Status: MISS
# 2 使用httpstat
# 看下访问http自动跳转到https的日志
$ httpstat http://cloud.tencent.com/developer/user/3663994
Connected to 117.185.119.97:80 from 192.168.31.181:30972
HTTP/1.1 302 Found
Location: https://cloud.tencent.com/developer/user/3663994
Content-Length: 0
Connection: keep-alive
Server: EdgeOne_IS_OC
Date: Sat, 23 Sep 2023 03:30:50 GMT
EO-LOG-UUID: 5226869486337378465
Body stored in: /tmp/tmpjua8agof
DNS Lookup TCP Connection Server Processing Content Transfer
[ 61ms | 20ms | 21ms | 0ms ]
| | | |
namelookup:61ms | | |
connect:81ms | |
starttransfer:102ms |
total:102ms
$ httpstat https://cloud.tencent.com/developer/user/3663994
Connected to 117.185.119.97:443 from 192.168.31.181:38104
HTTP/1.1 200 OK
Date: Sat, 23 Sep 2023 03:24:00 GMT
Content-Type: text/html; charset=utf-8
Server: nginx
Vary: Accept-Encoding
X-Req-Id: SkOIc0oka
Pragma: no-cache
ETag: W/"1b5f6-J3k EAhiOek0KE56QPJKyOlQSCg"
Cache-Control: must-revalidate, no-cache, no-store
Content-Length: 112118
Connection: keep-alive
EO-LOG-UUID: 15136775719166136109
EO-Cache-Status: MISS
Body stored in: /tmp/tmpa0i1zv_m
DNS Lookup TCP Connection TLS Handshake Server Processing Content Transfer
[ 62ms | 25ms | 203ms | 397ms | 50ms ]
| | | | |
namelookup:62ms | | | |
connect:87ms | | |
pretransfer:290ms | |
starttransfer:687ms |
total:737ms
可以看到httpstat 自动把访问的结果存到/tmp/下的临时文件了,并且给出了每个阶段的耗时情况。