
少し前に、某所のサーバ(自分たちで管理)で、通常時は問題ないのだけど、時々HTTPレスポンスで数秒かかる現象が見受けられたので、再現させるときに目視確認でひたすらHTTPリクエストが送れてレイテンシが確認できる「httping」を利用しました。
httpingは、所謂"ping"のHTTP版。HTTPリクエストでポーリングしてくれるコマンドです。ICMPは受け付けないけどHTTPはOK、そんなサーバにも監視などで使えます。
インストール
Ubuntuでは、aptでインストールできました。簡単。
$ sudo apt-get install httping
これだけです。
簡単な使い方
$ httping (URLまたはIPアドレス)
で、実行可能です。以下、実行例。
$ httping http://xxx.xxx.xxx.xxx/ PING xxx.xxx.xxx.xxx:80 (http://xxx.xxx.xxx.xxx/): connected to xxx.xxx.xxx.xxx:80, seq=0 time=17.03 ms connected to xxx.xxx.xxx.xxx:80, seq=1 time=9.49 ms connected to xxx.xxx.xxx.xxx:80, seq=2 time=17.71 ms connected to xxx.xxx.xxx.xxx:80, seq=3 time=17.24 ms connected to xxx.xxx.xxx.xxx:80, seq=4 time=15.96 ms --- http://xxx.xxx.xxx.xxx/ ping statistics --- 5 connects, 5 ok, 0.00% failed round-trip min/avg/max = 9.5/15.5/17.7 ms
特定のURLに対して、HTTPでのリクエスト/レスポンスの確認となり、応答時間(RTT)の最小/平均/最大がわかります。
ちなみに、デフォルトで利用されるのはHEADリクエストです。(レスポンスのボディが含まれない。)
オプションを特に何も付けないと、Linuxでのpingコマンド同様、延々とリクエストを繰り返します。
レスポンスボディの送受信時間も確認したい場合
以下のような感じで実行してみます。(よく使うオプションを色々付けてみました。)
$ httping -c 5 -G -b -s -g http://yyy.xxx.com/img/xxx.jpg PING yyy.xxx.com:80 (http://yyy.xxx.com/img/xxx.jpg): connected to yyy.xxx.com:80, seq=0 time=1668.50 ms 200 OK 129KB/s connected to yyy.xxx.com:80, seq=1 time=1897.33 ms 200 OK 113KB/s connected to yyy.xxx.com:80, seq=2 time=2075.83 ms 200 OK 99KB/s connected to yyy.xxx.com:80, seq=3 time=2197.23 ms 200 OK 97KB/s connected to yyy.xxx.com:80, seq=4 time=1920.53 ms 200 OK 111KB/s --- http://yyy.xxx.com/img/xxx.jpg ping statistics --- 5 connects, 5 ok, 0.00% failed round-trip min/avg/max = 1668.5/1951.9/2197.2 ms Transfer speed: min/avg/max = 97/110/129 KB
この例では、少しサイズのある画像をリクエストし、"-G"オプションを利用してGETリクエストを送り、ファイルデータといったBODY自体の送受信時間も含んでいるため、応答時間が↑の例より大きくなっていることが確認できるかと思います。
ちなみに"-c"は回数の指定、"-G"はGETリクエストの指定、"-b"はデータ転送速度の表示(KB/sec)、"-s"はステータスコードの表示、"-g"はターゲットとなるURLを指定するオプションです。
尚、"-b"オプションを付けているため、転送速度の最小/平均/最大値も確認できます。
その他のオプション
を参考までに載せておきます。
ちなみに、今回↑で私が使ったバージョンは、1.4.4でした。
$ httping -V HTTPing v1.4.4, (C) 2003-2010 folkert@vanheusden.com SSL support included
SSLもサポートしていますね。(自分でビルドするときはopensslなどのライブラリが必要なはず。)
他にも、インターバルのオプションはよく使うし、↓のオプション一覧を見ていると、Proxyの設定や、UserAgentやリファラの定義、何をもってしてOKとするかなどの定義、BASIC認証の対応、Cookieの付加、Nagios modeなんてのもありました。
気になる方は、色々試してみてください。
$ httping --help
-g url url (e.g. -g http://localhost/)
-h hostname hostname (e.g. localhost)
-p portnr portnumber (e.g. 80)
-x host:port hostname+portnumber of proxyserver
-c count how many times to connect
-i interval delay between each connect
-t timeout timeout (default: 30s)
-6 use IPv6
-s show statuscodes
-S split time in connect-time and processing time
-G do a GET request instead of HEAD (read the
contents of the page as well)
-b show transfer speed in KB/s (use with -G)
-B like -b but use compression if available
-L x limit the amount of data transferred (for -b)
to 'x' (in bytes)
-X show the number of KB transferred (for -b)
-l connect using SSL
-z show fingerprint (SSL)
-f flood connect (no delays)
-a audible ping
-m give machine parseable output (see
also -o and -e)
-o rc,rc,... what http results codes indicate 'ok'
coma seperated WITHOUT spaces inbetween
default is 200, use with -e
-e str string to display when http result code
doesn't match
-I str use 'str' for the UserAgent header
-R str use 'str' for the Referer header
-r resolve hostname only once (usefull when
pinging roundrobin DNS: also takes the first
DNS lookup out of the loop so that the first
measurement is also correct)
-n warn,crit Nagios-mode: return 1 when avg. response time
>= warn, 2 if >= crit, otherwhise return 0
-N x Nagios mode 2: return 0 when all fine, 'x'
when anything failes
-y ip[:port] bind to ip-address (and thus interface) [/port]
-q quiet, only returncode
-A Activate Basic authentication
-U Username needed for authentication
-P Password needed for authentication
-C cookie=value Add a cookie to the request
-V show the version
--url -g
--hostname -h
--port -p
--host-port -x
--count -c
--interval -i
--timeout -t
--ipv6 - 6
--show-statusodes -s
--split-time -S
--get-request -G
--show-transfer-speed -b
--show-xfer-speed-compressed -B
--data-limit -L
--show-kb -X
--use-ssl -l
--show-fingerprint -z
--flood -f
--audible-ping -a
--parseable-output -m
--ok-result-codes -o
--result-string -e
--user-agent -I
--referer -S
--resolve-once -r
--nagios-mode-1 -n
--nagios-mode-2 -n
--bind-to -y
--quiet -q
--basic-auth -A
--username -U
--password -P
--cookie -C
--version -V
--help -h
- 作者: John Allspaw,Jesse Robbins,角征典
- 出版社/メーカー: オライリージャパン
- 発売日: 2011/05/14
- メディア: 大型本
- 購入: 10人 クリック: 923回
- この商品を含むブログ (50件) を見る