some fixes

This commit is contained in:
Florian Koch 2015-09-24 15:25:51 +02:00
parent c331982f21
commit dd041457b5
2 changed files with 30 additions and 19 deletions

View File

@ -200,13 +200,15 @@ func tcpStatsFromProc(rootFs string, pid int, file string) (info.TcpStat, error)
func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) { func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) {
//FIXME besser lösen var stats info.TcpStat
var s info.TcpStat
data, err := ioutil.ReadFile(tcpStatsFile) data, err := ioutil.ReadFile(tcpStatsFile)
if err != nil { if err != nil {
return s, fmt.Errorf("failure opening %s: %v", tcpStatsFile, err) return stats, fmt.Errorf("failure opening %s: %v", tcpStatsFile, err)
} }
tcpStatLineRE, _ := regexp.Compile("[0-9:].*")
tcpStateMap := map[string]uint64{ tcpStateMap := map[string]uint64{
"01": 0, //ESTABLISHED "01": 0, //ESTABLISHED
"02": 0, //SYN_SENT "02": 0, //SYN_SENT
@ -226,23 +228,21 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) {
scanner.Split(bufio.ScanLines) scanner.Split(bufio.ScanLines)
r, _ := regexp.Compile("[0-9:].*")
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
//skip header //skip header
matched := r.MatchString(line) matched := tcpStatLineRE.MatchString(line)
if matched { if matched {
state := strings.Fields(line) state := strings.Fields(line)
//#file header tcp state is the 4 filed:
//sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode //sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
tcpStateMap[state[3]]++ tcpStateMap[state[3]]++
} }
} }
tcpStats := info.TcpStat{ stats = info.TcpStat{
Established: tcpStateMap["01"], Established: tcpStateMap["01"],
SynSent: tcpStateMap["02"], SynSent: tcpStateMap["02"],
SynRecv: tcpStateMap["03"], SynRecv: tcpStateMap["03"],
@ -256,7 +256,7 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) {
Closing: tcpStateMap["0B"], Closing: tcpStateMap["0B"],
} }
return tcpStats, nil return stats, nil
} }
func GetProcesses(cgroupManager cgroups.Manager) ([]int, error) { func GetProcesses(cgroupManager cgroups.Manager) ([]int, error) {

View File

@ -348,16 +348,27 @@ type NetworkStats struct {
} }
type TcpStat struct { type TcpStat struct {
//Count of TCP connections in state "Established"
Established uint64 Established uint64
//Count of TCP connections in state "Syn_Sent"
SynSent uint64 SynSent uint64
//Count of TCP connections in state "Syn_Recv"
SynRecv uint64 SynRecv uint64
//Count of TCP connections in state "Fin_Wait2"
FinWait1 uint64 FinWait1 uint64
//Count of TCP connections in state "Fin_Wait2"
FinWait2 uint64 FinWait2 uint64
//Count of TCP connections in state "Time_Wait
TimeWait uint64 TimeWait uint64
//Count of TCP connections in state "Close"
Close uint64 Close uint64
//Count of TCP connections in state "Close_Wait"
CloseWait uint64 CloseWait uint64
//Count of TCP connections in state "Listen_Ack"
LastAck uint64 LastAck uint64
//Count of TCP connections in state "Listen"
Listen uint64 Listen uint64
//Count of TCP connections in state "Closing"
Closing uint64 Closing uint64
} }