haproxyのステータス確認

f:id:komeiy:20150107164847j:plain haproxyのステータス確認方法をいつも忘れてしまうのでメモ代わりに書いておきます。

haproxyのsocketをcatするsocatコマンドを使います。 以下のように書くことで8080番への入力を標準出力に書き込むことができます。 簡単dす。

$ socat tcp-listen:8080 stdout

haproxyではechoを使って取得したいログの種別を指定します。 まずはバージョン情報など基本的な情報を取ってみます。

root@gw01:~# echo "show info" | socat unix-connect:/etc/haproxy/sock stdio
Name: HAProxy
Version: 1.4.24
Release_date: 2013/06/17
Nbproc: 1
Process_num: 1
Pid: 24498
Uptime: 0d 0h08m59s
Uptime_sec: 539
Memmax_MB: 0
Ulimit-n: 4013
Maxsock: 4013
Maxconn: 2000
Maxpipes: 0
CurrConns: 1
PipesUsed: 0
PipesFree: 0
Tasks: 2
Run_queue: 1
node:gw01
description:

コマンド一覧をhelpで取ってみました。

  clear counters : clear max statistics counters (add 'all' for all counters)
  help           : this message
  prompt         : toggle interactive mode with prompt
  quit           : disconnect
  show info      : report information about the running process
  show stat      : report counters for each proxy and server
  show errors    : report last request and response errors for each proxy
  show sess [id] : report the list of current sessions or dump this session
  get weight     : report a server's current weight
  set weight     : change a server's weight
  set timeout    : change a timeout setting
  disable server : set a server in maintenance mode
  enable server  : re-enable a server that was previously in maintenance mode

backendのステータスなどはshow statで確認可能です。

root@gw01:~# echo "show stat" | socat unix-connect:/etc/haproxy/sock stdio
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,
07625016-88cc-4533-a0b0-cd006b54c110,FRONTEND,,,0,0,2000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,0,,,,,,,,,,,0,0,0,,,
2c8ff70e-1345-4642-8689-1ce7d74506a8,6f37e25b-713e-4c31-8671-aec5c23a878e,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,1278,0,,1,2,1,,0,,2,0,,0,L4OK,,3,,,,,,,0,,,,0,0,
2c8ff70e-1345-4642-8689-1ce7d74506a8,BACKEND,0,0,0,0,0,0,0,0,0,0,,0,0,0,0,UP,1,1,0,,0,1278,0,,1,2,0,,0,,1,0,,0,,,,,,,,,,,,,,0,0,

こんな感じで必要な情報だけ引っ張ります。svnamestatusをピックアップしています。

root@gw01:~# echo "show stat" | socat unix-connect:/etc/haproxy/sock stdio | grep -v -e '^#\|^$' | cut -d ',' -f 2,18 --output-delimiter=':'
FRONTEND:OPEN
6f37e25b-713e-4c31-8671-aec5c23a878e:UP
BACKEND:UP

サーバ負荷分散入門

サーバ負荷分散入門

サーバ負荷分散入門

サーバ負荷分散入門


シェアして頂けると嬉しいです。
参考になったという方がいれば是非お願いしますm(_ _ )m
モチベーション維持の観点で非常に励みになります。

このエントリーをはてなブックマークに追加




パーフェクトPHP
パーフェクトPHP
posted with amazlet at 15.08.29
技術評論社 (2014-10-31)
売り上げランキング: 10,488