forked from akashihi/graphite-haproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.go
More file actions
137 lines (128 loc) · 3.19 KB
/
status.go
File metadata and controls
137 lines (128 loc) · 3.19 KB
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
/*
conntrack-logger
Copyright (C) 2015 Denis V Chapligin <akashihi@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"encoding/csv"
"io"
"strings"
)
type Status struct {
Type string
Name string
QCur string
SCur string
STot string
BytesIn string
BytesOut string
EReq string
Econ string
EResp string
Chkfail string
ChkDown string
Downtime string
ChkDur string
HRSP1 string
HRSP2 string
HRSP3 string
HRSP4 string
HRSP5 string
HRSPO string
ReqTot string
QTime string
CTime string
RTime string
TTime string
MaxReqRate string
CurrReqRate string
}
func parse(page io.ReadCloser) ([]Status, error) {
var result = []Status{}
r := csv.NewReader(page)
records, err := r.ReadAll()
page.Close()
if err != nil {
log.Error("Can't parse status page: %v", err)
return result, err
}
for _, entry := range records {
var item = Status{}
item.Type = entry[32]
item.Name = strings.Join(entry[0:2], "-")
item.SCur = entry[4]
item.STot = entry[7]
item.BytesIn = entry[8]
item.BytesOut = entry[9]
switch item.Type { //Type
case "type": //Header
continue
case "0": //Frontend
item.Type = "Frontend"
item.EReq = entry[12]
item.HRSP1 = entry[39]
item.HRSP2 = entry[40]
item.HRSP3 = entry[41]
item.HRSP4 = entry[42]
item.HRSP5 = entry[43]
item.HRSPO = entry[44]
item.CurrReqRate = entry[46]
item.MaxReqRate = entry[47]
item.ReqTot = entry[48]
break
case "1": //Backend
item.Type = "Backend"
item.QCur = entry[2]
item.Econ = entry[13]
item.EResp = entry[14]
item.ChkDown = entry[22]
item.Downtime = entry[24]
item.HRSP1 = entry[39]
item.HRSP2 = entry[40]
item.HRSP3 = entry[41]
item.HRSP4 = entry[42]
item.HRSP5 = entry[43]
item.HRSPO = entry[44]
item.QTime = entry[58]
item.CTime = entry[59]
item.RTime = entry[60]
item.TTime = entry[61]
break
case "2": //Server
item.Type = "Server"
item.QCur = entry[2]
item.Econ = entry[13]
item.EResp = entry[14]
item.Chkfail = entry[21]
item.ChkDown = entry[22]
item.Downtime = entry[24]
item.HRSP1 = entry[39]
item.HRSP2 = entry[40]
item.HRSP3 = entry[41]
item.HRSP4 = entry[42]
item.HRSP5 = entry[43]
item.HRSPO = entry[44]
item.QTime = entry[58]
item.CTime = entry[59]
item.RTime = entry[60]
item.TTime = entry[61]
break
case "3": //Listener
item.Type = "Listener"
item.EReq = entry[12]
break
}
result = append(result, item)
}
return result, nil
}