httpstat:一個檢查網站性能的 curl 統計分析工具
httpstat 是一個 Python 腳本,它以美妙妥善的方式反映了 curl 統計分析,它是一個單一腳本,兼容 Python 3 ,在用戶的係統上不需要安裝額外的軟件(依賴)。
從本質上來說它是一個 cURL 工具的封裝,意味著你可以在 URL 後使用幾個有效的 cURL 選項,但是不包括 -w
、 -D
、 -o
、 -s
和 -S
選項,這些已經被 httpstat 使用了。
httpstat Curl 統計分析工具
你可以看到上圖的一個 ASCII 表顯示了每個過程消耗多長時間,對我來說最重要的一步是“服務器處理server processing” – 如果這個數字很高,那麼你需要優化你網站服務器來加速訪問速度。
網站或服務器優化你可以查看我們的文章:
- 5 個優化 Apache Web 服務器性能的技巧
- 使 Apache 和 Nginx 性能提升 10 倍
- 如何使用 Gzip 模塊提高 Nginx 性能
- 15 個優化 MySQL/MariaDB 性能的建議
使用下麵安裝說明和用法來獲取 httpstat 檢查出你的網站速度。
在 Linux 係統中安裝 httpstat
你可以使用兩種合理的方法安裝 httpstat :
- 使用 wget 命令直接從它的 Github 倉庫獲取如下:
$ wget -c https://raw.githubusercontent.com/reorx/httpstat/master/httpstat.py
- 使用
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
或
$ httpstat --help
httpstat
幫助:
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 環境變量。
下麵是一些展示 httpstat
如何工作的例子。
$ python httpstat.py google.com
或
$ httpstat google.com
httpstat – 展示網站統計分析
接下來的命令中:
-
-X
命令標記指定一個客戶與 HTTP 服務器連接的請求方法。 -
--data-urlencode
這個選項將會把數據(這裏是 a=b)按 URL 編碼的方式編碼後再提交。 -
-v
開啟詳細模式。
$ python httpstat.py httpbin.org/post -X POST --data-urlencode "a=b" -v
httpstat – 定製提交請求
原文發布時間為:2017-12-16
本文來自雲棲社區合作夥伴“Linux中國”
最後更新:2017-06-06 07:37:25