func getContainerAlias(cAdvisorClient *client.Client, ContainerName string) string {
	containerAliases.Lock()
	defer containerAliases.Unlock()

	if containerAliases.Aliases == nil {
		containerAliases.Aliases = make(map[string]ContainerAliasInfo)
	}

	alias := containerAliases.Aliases[ContainerName].ContainerAlias

	if alias == "" {
		request := info.ContainerInfoRequest{
			NumStats: 1,
		}
		cInfo, err := cAdvisorClient.ContainerInfo(ContainerName, &request)
		if err == nil {
			alias := getAliasSafely(cInfo.Aliases)
			glog.V(4).Infof("Adding map during get: " + ContainerName + " -> " + alias)
			info := &ContainerAliasInfo{alias, time.Now()}
			containerAliases.Aliases[ContainerName] = *info
		}
		alias = containerAliases.Aliases[ContainerName].ContainerAlias
	}

	return alias
}
Example #2
0
func c_cadvisor(c *client.Client, config *conf.Cadvisor) (opentsdb.MultiDataPoint, error) {
	var md opentsdb.MultiDataPoint

	containers, err := c.AllDockerContainers(&v1.ContainerInfoRequest{NumStats: 1})
	if err != nil {
		slog.Errorf("Error fetching containers from cadvisor: %v", err)
		return md, err
	}

	for _, container := range containers {
		statsForContainer(&md, &container, config)
	}

	return md, nil
}
Example #3
0
func (self *cadvisorSource) getAllContainers(client *cadvisorClient.Client, start, end time.Time, resolution time.Duration, align bool) (subcontainers []*api.Container, root *api.Container, err error) {
	allContainers, err := client.SubcontainersInfo("/", &cadvisor.ContainerInfoRequest{Start: start, End: end})
	if err != nil {
		return nil, nil, err
	}

	for _, containerInfo := range allContainers {
		container := parseStat(&containerInfo, start, resolution, align)
		if containerInfo.Name == "/" {
			root = container
		} else {
			subcontainers = append(subcontainers, container)
		}
	}

	return subcontainers, root, nil
}
Example #4
0
func (self *cadvisorSource) getAllContainers(client *cadvisorClient.Client, numStats int) (subcontainers []*api.Container, root *api.Container, err error) {
	allContainers, err := client.SubcontainersInfo("/",
		&cadvisor.ContainerInfoRequest{NumStats: numStats})
	if err != nil {

		return nil, nil, err
	}

	for _, containerInfo := range allContainers {
		container := self.parseStat(&containerInfo)
		if containerInfo.Name == "/" {
			root = container
		} else {
			subcontainers = append(subcontainers, container)
		}
	}

	return subcontainers, root, nil
}
Example #5
0
// Get all containers from cAdvisor and separates the root container and other contianers.
func (self *CadvisorSource) getAllContainers(client *cadvisorClient.Client, start, end time.Time) (subcontainers []*Container, root *Container, err error) {
	allContainers, err := client.SubcontainersInfo("/",
		&cadvisor.ContainerInfoRequest{})
	if err != nil {
		glog.Errorf("Got error when trying to get container info: %v", err)
		return nil, nil, err
	}

	for _, containerInfo := range allContainers {
		container := self.parseStat(&containerInfo)
		if containerInfo.Name == "/" {
			root = container
		} else {
			subcontainers = append(subcontainers, container)
		}
	}

	return subcontainers, root, nil
}
Example #6
0
func getContainerInfo(client *client.Client, container string) (containerInfo info.ContainerInfo, err error) {
	query := info.ContainerInfoRequest{}
	cinfos, err := client.SubcontainersInfo("/", &query)
	if err != nil {
		return info.ContainerInfo{}, err
	}
	tempContainer := "/" + container
	for _, cinfo := range cinfos {
		if strings.HasSuffix(cinfo.Name, tempContainer) {
			return cinfo, nil
		}
	}
	return info.ContainerInfo{}, errors.New("not find container " + container)
}
Example #7
0
func GetAllContainer(client *client.Client) ([]info.ContainerInfo, error) {
	query := info.ContainerInfoRequest{}
	query.NumStats = 1
	cinfos, err := client.SubcontainersInfo("/", &query)
	return cinfos, err
}