Class: HAProxy::CSVParser
- Inherits:
-
Object
- Object
- HAProxy::CSVParser
- Defined in:
- lib/haproxy/csv_parser.rb
Constant Summary collapse
- COLUMNS =
Uses CSV header from HAProxy 1.5, which is backwards compatible
"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".split(",").map(&:to_sym)
- LIMIT =
COLUMNS.length
Class Method Summary collapse
Class Method Details
.parse(line) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/haproxy/csv_parser.rb', line 8 def self.parse(line) line.strip! unless line.start_with? "#" data = line.split(',') pxname = data.shift stats = { :pxname => pxname } data.each_with_index do |value, i| if i < LIMIT stats[COLUMNS[i + 1]] = value else stats[:extra] = Array.new if stats[:extra].nil? stats[:extra] << value end end stats else raise ArgumentError, "Line is a comment" end end |