forked from bcicen/go-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.go
139 lines (132 loc) · 4.52 KB
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package haproxy
import (
"encoding/csv"
"fmt"
"github.com/gocarina/gocsv"
)
// Response from HAProxy "show stat" command.
type Stat struct {
PxName string `csv:"# pxname"`
SvName string `csv:"svname"`
Qcur uint64 `csv:"qcur"`
Qmax uint64 `csv:"qmax"`
Scur uint64 `csv:"scur"`
Smax uint64 `csv:"smax"`
Slim uint64 `csv:"slim"`
Stot uint64 `csv:"stot"`
Bin uint64 `csv:"bin"`
Bout uint64 `csv:"bout"`
Dreq uint64 `csv:"dreq"`
Dresp uint64 `csv:"dresp"`
Ereq uint64 `csv:"ereq"`
Econ uint64 `csv:"econ"`
Eresp uint64 `csv:"eresp"`
Wretr uint64 `csv:"wretr"`
Wredis uint64 `csv:"wredis"`
Status string `csv:"status"`
Weight uint64 `csv:"weight"`
Act uint64 `csv:"act"`
Bck uint64 `csv:"bck"`
ChkFail uint64 `csv:"chkfail"`
ChkDown uint64 `csv:"chkdown"`
Lastchg uint64 `csv:"lastchg"`
Downtime uint64 `csv:"downtime"`
Qlimit uint64 `csv:"qlimit"`
Pid uint64 `csv:"pid"`
Iid uint64 `csv:"iid"`
Sid uint64 `csv:"sid"`
Throttle uint64 `csv:"throttle"`
Lbtot uint64 `csv:"lbtot"`
Tracked uint64 `csv:"tracked"`
Type uint64 `csv:"type"`
Rate uint64 `csv:"rate"`
RateLim uint64 `csv:"rate_lim"`
RateMax uint64 `csv:"rate_max"`
CheckStatus string `csv:"check_status"`
CheckCode uint64 `csv:"check_code"`
CheckDuration uint64 `csv:"check_duration"`
Hrsp1xx uint64 `csv:"hrsp_1xx"`
Hrsp2xx uint64 `csv:"hrsp_2xx"`
Hrsp3xx uint64 `csv:"hrsp_3xx"`
Hrsp4xx uint64 `csv:"hrsp_4xx"`
Hrsp5xx uint64 `csv:"hrsp_5xx"`
HrspOther uint64 `csv:"hrsp_other"`
Hanafail uint64 `csv:"hanafail"`
ReqRate uint64 `csv:"req_rate"`
ReqRateMax uint64 `csv:"req_rate_max"`
ReqTot uint64 `csv:"req_tot"`
CliAbrt uint64 `csv:"cli_abrt"`
SrvAbrt uint64 `csv:"srv_abrt"`
CompIn uint64 `csv:"comp_in"`
CompOut uint64 `csv:"comp_out"`
CompByp uint64 `csv:"comp_byp"`
CompRsp uint64 `csv:"comp_rsp"`
LastSess int64 `csv:"lastsess"`
LastChk string `csv:"last_chk"`
LastAgt uint64 `csv:"last_agt"`
Qtime uint64 `csv:"qtime"`
Ctime uint64 `csv:"ctime"`
Rtime uint64 `csv:"rtime"`
Ttime uint64 `csv:"ttime"`
AgentStatus uint64 `csv:"agent_status"`
AgentCode uint64 `csv:"agent_code"`
AgentDuration uint64 `csv:"agent_duration"`
CheckDesc string `csv:"check_desc"`
AgentDesc string `csv:"agent_desc"`
CheckRise uint64 `csv:"check_rise"`
CheckFall uint64 `csv:"check_fall"`
CheckHealth uint64 `csv:"check_health"`
AgentRise uint64 `csv:"agent_rise"`
AgentFall uint64 `csv:"agent_fall"`
AgentHealth uint64 `csv:"agent_health"`
Addr string `csv:"addr"`
Cookie uint64 `csv:"cookie"`
Mode string `csv:"mode"`
Algo string `csv:"algo"`
ConnRate uint64 `csv:"conn_rate"`
ConnRateMax uint64 `csv:"conn_rate_max"`
ConnTot uint64 `csv:"conn_tot"`
Intercepted uint64 `csv:"intercepted"`
Dcon uint64 `csv:"dcon"`
Dses uint64 `csv:"dses"`
Wrew uint64 `csv:"wrew"`
Connect uint64 `csv:"connect"`
Reuse uint64 `csv:"reuse"`
CacheLookups uint64 `csv:"cache_lookups"`
CacheHits uint64 `csv:"cache_hits"`
SrvIcur uint64 `csv:"srv_icur"`
SrcIlim uint64 `csv:"src_ilim"`
QtimeMax uint64 `csv:"qtime_max"`
CtimeMax uint64 `csv:"ctime_max"`
RtimeMax uint64 `csv:"rtime_max"`
TtimeMax uint64 `csv:"ttime_max"`
Eint uint64 `csv:"eint"`
IdleConnCur uint64 `csv:"idle_conn_cur"`
SafeConnCur uint64 `csv:"safe_conn_cur"`
UsedConnCur uint64 `csv:"used_conn_cur"`
NeedConnEst uint64 `csv:"need_conn_est"`
}
// Equivalent to HAProxy "show stat" command.
func (h *HAProxyClient) Stats() (stats []*Stat, err error) {
res, err := h.RunCommand("show stat")
if err != nil {
return nil, err
}
reader := csv.NewReader(res)
reader.TrailingComma = true
err = gocsv.UnmarshalCSV(reader, &stats)
if err != nil {
return nil, fmt.Errorf("error reading csv: %s", err)
}
// for _, s := range allStats {
// switch s.SvName {
// case "FRONTEND":
// services.Frontends = append(services.Frontends, s)
// case "BACKEND":
// services.Backends = append(services.Backends, s)
// default:
// services.Listeners = append(services.Listeners, s)
// }
// }
return stats, nil
}