diff --git a/container/libcontainer/helpers.go b/container/libcontainer/helpers.go index 33dc950b..850ab80d 100644 --- a/container/libcontainer/helpers.go +++ b/container/libcontainer/helpers.go @@ -200,13 +200,15 @@ func tcpStatsFromProc(rootFs string, pid int, file string) (info.TcpStat, error) func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) { - //FIXME besser lösen - var s info.TcpStat + var stats info.TcpStat + data, err := ioutil.ReadFile(tcpStatsFile) 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{ "01": 0, //ESTABLISHED "02": 0, //SYN_SENT @@ -226,23 +228,21 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) { scanner.Split(bufio.ScanLines) - r, _ := regexp.Compile("[0-9:].*") - for scanner.Scan() { line := scanner.Text() //skip header - matched := r.MatchString(line) + matched := tcpStatLineRE.MatchString(line) if matched { 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 tcpStateMap[state[3]]++ - } } - tcpStats := info.TcpStat{ + stats = info.TcpStat{ Established: tcpStateMap["01"], SynSent: tcpStateMap["02"], SynRecv: tcpStateMap["03"], @@ -256,7 +256,7 @@ func scanTcpStats(tcpStatsFile string) (info.TcpStat, error) { Closing: tcpStateMap["0B"], } - return tcpStats, nil + return stats, nil } func GetProcesses(cgroupManager cgroups.Manager) ([]int, error) { diff --git a/info/v1/container.go b/info/v1/container.go index 593ae9a6..e90e3b92 100644 --- a/info/v1/container.go +++ b/info/v1/container.go @@ -348,17 +348,28 @@ type NetworkStats struct { } type TcpStat struct { + //Count of TCP connections in state "Established" Established uint64 - SynSent uint64 - SynRecv uint64 - FinWait1 uint64 - FinWait2 uint64 - TimeWait uint64 - Close uint64 - CloseWait uint64 - LastAck uint64 - Listen uint64 - Closing uint64 + //Count of TCP connections in state "Syn_Sent" + SynSent uint64 + //Count of TCP connections in state "Syn_Recv" + SynRecv uint64 + //Count of TCP connections in state "Fin_Wait2" + FinWait1 uint64 + //Count of TCP connections in state "Fin_Wait2" + FinWait2 uint64 + //Count of TCP connections in state "Time_Wait + TimeWait uint64 + //Count of TCP connections in state "Close" + Close uint64 + //Count of TCP connections in state "Close_Wait" + CloseWait uint64 + //Count of TCP connections in state "Listen_Ack" + LastAck uint64 + //Count of TCP connections in state "Listen" + Listen uint64 + //Count of TCP connections in state "Closing" + Closing uint64 } type TcpStats struct {