閱讀780 返回首頁    go 阿裏雲 go 技術社區[雲棲]


httpstat:一個檢查網站性能的 curl 統計分析工具

httpstat 是一個 Python 腳本,它以美妙妥善的方式反映了 curl 統計分析,它是一個單一腳本,兼容 Python 3 ,在用戶的係統上不需要安裝額外的軟件(依賴)。

從本質上來說它是一個 cURL 工具的封裝,意味著你可以在 URL 後使用幾個有效的 cURL 選項,但是不包括 -w、 -D、 -o、 -s 和 -S 選項,這些已經被 httpstat 使用了。

httpstat Curl 統計分析工具

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. $ 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 `true` to 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 `false` to disable this feature. Default is `true`.
  17. HTTPSTAT_SHOW_SPEED Set to `true` to 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 `false` to 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 `true` to 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

你一旦添加完它們,保存文件然後運行下麵的命令使改變生效:

$ source  ~/.bashrc

你可以指定使用 cURL 執行文件的路徑,默認使用的是當前 shell 的 $PATH 環境變量

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


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

httpstat  展示網站統計分析

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  定製提交請求

httpstat – 定製提交請求

原文發布時間為:2017-12-16

本文來自雲棲社區合作夥伴“Linux中國”

最後更新:2017-06-06 07:37:25

  上一篇:go  Linux 中的 DTrace :BPF 進入 4.9 內核
  下一篇:go  修複 Ubuntu 中“Unable to lock the administration directory (/var/lib/dpkg/)”的