Renamed container description types

This commit is contained in:
Abin Shahab 2014-10-14 08:45:18 +00:00
parent 07fbd1ddab
commit 99d2c31f4d
3 changed files with 40 additions and 28 deletions

View File

@ -13,7 +13,7 @@
// limitations under the License. // limitations under the License.
// Unmarshal's a Containers description json file. The json file contains // Unmarshal's a Containers description json file. The json file contains
// an array of ContainerDesc structs, each with a container's id and network_interface // an array of ContainerHint structs, each with a container's id and networkInterface
// This allows collecting stats about network interfaces configured outside docker // This allows collecting stats about network interfaces configured outside docker
// and lxc // and lxc
package raw package raw
@ -23,25 +23,25 @@ import (
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
) )
var argContainersDesc = flag.String("cDescription", "/etc/docker/cdesc.json", "container description file") var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_description.json", "container hints file")
type containersDesc struct { type containerHints struct {
All_hosts []containerDesc All_hosts []containerHint `json:"all_hosts,omitempty"`
} }
type containerDesc struct { type containerHint struct {
Id string Id string `json:"id,omitempty"`
Network_interface *networkInterface NetworkInterface *networkInterface `json:"network_interface,omitempty"`
} }
type networkInterface struct { type networkInterface struct {
VethHost string VethHost string `json:"VethHost,omitempty"`
VethChild string VethChild string `json:"VethChild,omitempty"`
NsPath string NsPath string `json:"NsPath,omitempty"`
} }
func Unmarshal(containerDescFile string) (containersDesc, error) { func Unmarshal(containerHintsFile string) (containerHints, error) {
dat, err := ioutil.ReadFile(containerDescFile) dat, err := ioutil.ReadFile(containerHintsFile)
var cDesc containersDesc var cDesc containerHints
if err == nil { if err == nil {
err = json.Unmarshal(dat, &cDesc) err = json.Unmarshal(dat, &cDesc)
} }

View File

@ -11,8 +11,8 @@ func TestUnmarshal(t *testing.T) {
t.Fatalf("Error in unmarshalling: %s", err) t.Fatalf("Error in unmarshalling: %s", err)
} }
if cDesc.All_hosts[0].Network_interface.VethHost != "veth24031eth1" && if cDesc.All_hosts[0].NetworkInterface.VethHost != "veth24031eth1" &&
cDesc.All_hosts[0].Network_interface.VethChild != "eth1" { cDesc.All_hosts[0].NetworkInterface.VethChild != "eth1" {
t.Errorf("Cannot find network interface in %s", cDesc) t.Errorf("Cannot find network interface in %s", cDesc)
} }
} }

View File

@ -44,7 +44,7 @@ type rawContainerHandler struct {
stopWatcher chan error stopWatcher chan error
watches map[string]struct{} watches map[string]struct{}
fsInfo fs.FsInfo fsInfo fs.FsInfo
network_interface *networkInterface networkInterface *networkInterface
} }
func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, machineInfoFactory info.MachineInfoFactory) (container.ContainerHandler, error) { func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, machineInfoFactory info.MachineInfoFactory) (container.ContainerHandler, error) {
@ -52,15 +52,21 @@ func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, mac
if err != nil { if err != nil {
return nil, err return nil, err
} }
cDesc, err := Unmarshal(*argContainersDesc) cDesc, err := Unmarshal(*argContainerHints)
var network_interface *networkInterface if err != nil {
return nil, err
}
var networkInterface *networkInterface
for _, container := range cDesc.All_hosts { for _, container := range cDesc.All_hosts {
var cName string
if strings.Contains(container.Id, "/") {
cName = name
} else {
names := strings.SplitAfter(name, "/") names := strings.SplitAfter(name, "/")
cName := names[len(names) - 1] cName = names[len(names)-1]
glog.Infof("container %s Name %s \n\n", container, name) }
if cName == container.Id { if cName == container.Id {
network_interface = container.Network_interface networkInterface = container.NetworkInterface
fmt.Printf("Found network interface %s \n\n", network_interface)
break break
} }
} }
@ -75,7 +81,7 @@ func newRawContainerHandler(name string, cgroupSubsystems *cgroupSubsystems, mac
stopWatcher: make(chan error), stopWatcher: make(chan error),
watches: make(map[string]struct{}), watches: make(map[string]struct{}),
fsInfo: fsInfo, fsInfo: fsInfo,
network_interface: network_interface, networkInterface: networkInterface,
}, nil }, nil
} }
@ -174,10 +180,16 @@ func (self *rawContainerHandler) GetSpec() (info.ContainerSpec, error) {
func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) { func (self *rawContainerHandler) GetStats() (*info.ContainerStats, error) {
var stats *info.ContainerStats var stats *info.ContainerStats
var err error var err error
if self.network_interface != nil { if self.networkInterface != nil {
n := network.NetworkState{VethHost: self.network_interface.VethHost, VethChild: self.network_interface.VethChild, NsPath: "unknown"} state := dockerlibcontainer.State{
s := dockerlibcontainer.State{NetworkState: n} NetworkState: network.NetworkState{
stats, err = libcontainer.GetStats(self.cgroup, &s) VethHost: self.networkInterface.VethHost,
VethChild: self.networkInterface.VethChild,
NsPath: "unknown",
},
}
stats, err = libcontainer.GetStats(self.cgroup, &state)
} else { } else {
stats, err = libcontainer.GetStatsCgroupOnly(self.cgroup) stats, err = libcontainer.GetStatsCgroupOnly(self.cgroup)
} }