跳转至

Haproxy :使用Socat获得统计数据


2015-07-21 by dongnan

环境

操作系统: CentOS 6.6 amd64
软件版本: Haproxy 1.5.x(源码方式安装)

Socat

  • 功能: 是一个基于命令行的实用程序,它建立了两个双向字节流并在它们之间传输数据。
  • 安装: yum install socat

目标

输出 Haproxy 统计数据,为 Zabbix 采集 Haproxy 统计数据提供支持。

举个栗子

支持的命令参数

echo "help" | socat stdio /var/run/haproxy.sock

Unknown command. Please enter one of the following commands only :
  clear counters : clear max statistics counters (add 'all' for all counters)
  clear table    : remove an entry from a table
  help           : this message
  prompt         : toggle interactive mode with prompt
  quit           : disconnect
  show info      : report information about the running process
  show pools     : report information about the memory pools usage
  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
  show table [id]: report table usage stats or dump this table's contents
  get weight     : report a server's current weight
  set weight     : change a server's weight
  set server     : change a server's state or weight
  set table [id] : update or create a table entry's data
  set timeout    : change a timeout setting
  set maxconn    : change a maxconn setting
  set rate-limit : change a rate limiting value
  disable        : put a server or frontend in maintenance mode
  enable         : re-enable a server or frontend which is in maintenance mode
  shutdown       : kill a session or a frontend (eg:to release listening ports)
  show acl [id]  : report avalaible acls or dump an acl's contents
  get acl        : reports the patterns matching a sample for an ACL
  add acl        : add acl entry
  del acl        : delete acl entry
  clear acl <id> : clear the content of this acl
  show map [id]  : report avalaible maps or dump a map's contents
  get map        : reports the keys and values matching a sample for a map
  set map        : modify map entry
  add map        : add map entry
  del map        : delete map entry
  clear map <id> : clear the content of this map
  set ssl <stmt> : set statement for ssl

Haproxy 状态统计

# 输入命令
/bin/echo "show stat" | /usr/bin/socat stdio /var/run/haproxy.sock | awk -F, '/localhost/'

# 返回结果
localhost,FRONTEND,,,1,97,30000,17380,56105353,528129617,0,0,1856,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,23,,,,0,25469,7923,2127,53,1,,0,63,35573,,,0,0,0,0,,,,,,,,

参考

欢迎关注微信公众号: 运维录

Back to top