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.
// 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
// and lxc
package raw
@ -23,25 +23,25 @@ import (
"encoding/json"
"io/ioutil"
)
var argContainersDesc = flag.String("cDescription", "/etc/docker/cdesc.json", "container description file")
type containersDesc struct {
All_hosts []containerDesc
var argContainerHints = flag.String("container_hints", "/etc/cadvisor/container_description.json", "container hints file")
type containerHints struct {
All_hosts []containerHint `json:"all_hosts,omitempty"`
}
type containerDesc struct {
Id string
Network_interface *networkInterface
type containerHint struct {
Id string `json:"id,omitempty"`
NetworkInterface *networkInterface `json:"network_interface,omitempty"`
}
type networkInterface struct {
VethHost string
VethChild string
NsPath string
VethHost string `json:"VethHost,omitempty"`
VethChild string `json:"VethChild,omitempty"`
NsPath string `json:"NsPath,omitempty"`
}
func Unmarshal(containerDescFile string) (containersDesc, error) {
dat, err := ioutil.ReadFile(containerDescFile)
var cDesc containersDesc
func Unmarshal(containerHintsFile string) (containerHints, error) {
dat, err := ioutil.ReadFile(containerHintsFile)
var cDesc containerHints
if err == nil {
err = json.Unmarshal(dat, &cDesc)
}

View File

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

View File

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