Exemple #1
0
func (self *manager) GetContainerInfoV2(containerName string, options v2.RequestOptions) (map[string]v2.ContainerInfo, error) {
	containers, err := self.getRequestedContainers(containerName, options)
	if err != nil {
		return nil, err
	}

	infos := make(map[string]v2.ContainerInfo, len(containers))
	for name, container := range containers {
		cinfo, err := container.GetInfo()
		if err != nil {
			return nil, err
		}

		var nilTime time.Time // Ignored.
		stats, err := self.memoryCache.RecentStats(name, nilTime, nilTime, options.Count)
		if err != nil {
			return nil, err
		}

		infos[name] = v2.ContainerInfo{
			Spec:  self.getV2Spec(cinfo),
			Stats: v2.ContainerStatsFromV1(&cinfo.Spec, stats),
		}
	}

	return infos, nil
}
func (self *version2_1) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
	// Get the query request.
	opt, err := getRequestOptions(r)
	if err != nil {
		return err
	}

	switch requestType {
	case machineStatsApi:
		glog.V(4).Infof("Api - MachineStats(%v)", request)
		cont, err := m.GetRequestedContainersInfo("/", opt)
		if err != nil {
			return err
		}
		return writeResult(v2.MachineStatsFromV1(cont["/"]), w)
	case statsApi:
		name := getContainerName(request)
		glog.V(4).Infof("Api - Stats: Looking for stats for container %q, options %+v", name, opt)
		conts, err := m.GetRequestedContainersInfo(name, opt)
		if err != nil {
			return err
		}
		contStats := make(map[string][]*v2.ContainerStats, len(conts))
		for name, cont := range conts {
			contStats[name] = v2.ContainerStatsFromV1(&cont.Spec, cont.Stats)
		}
		return writeResult(contStats, w)
	default:
		return self.baseVersion.HandleRequest(requestType, request, m, w, r)
	}
}
Exemple #3
0
func (self *manager) GetContainerInfoV2(containerName string, options v2.RequestOptions) (map[string]v2.ContainerInfo, error) {
	containers, err := self.getRequestedContainers(containerName, options)
	if err != nil {
		return nil, err
	}

	var errs partialFailure
	var nilTime time.Time // Ignored.

	infos := make(map[string]v2.ContainerInfo, len(containers))
	for name, container := range containers {
		result := v2.ContainerInfo{}
		cinfo, err := container.GetInfo()
		if err != nil {
			errs.append(name, "GetInfo", err)
			infos[name] = result
			continue
		}
		result.Spec = self.getV2Spec(cinfo)

		stats, err := self.memoryCache.RecentStats(name, nilTime, nilTime, options.Count)
		if err != nil {
			errs.append(name, "RecentStats", err)
			infos[name] = result
			continue
		}

		result.Stats = v2.ContainerStatsFromV1(&cinfo.Spec, stats)
		infos[name] = result
	}

	return infos, errs.OrNil()
}
Exemple #4
0
func (self *version2_1) HandleRequest(requestType string, request []string, m manager.Manager, w http.ResponseWriter, r *http.Request) error {
	// Get the query request.
	opt, err := getRequestOptions(r)
	if err != nil {
		return err
	}

	switch requestType {
	case machineStatsApi:
		glog.V(4).Infof("Api - MachineStats(%v)", request)
		cont, err := m.GetRequestedContainersInfo("/", opt)
		if err != nil {
			if len(cont) == 0 {
				return err
			}
			glog.Errorf("Error calling GetRequestedContainersInfo: %v", err)
		}
		return writeResult(v2.MachineStatsFromV1(cont["/"]), w)
	case statsApi:
		name := getContainerName(request)
		glog.V(4).Infof("Api - Stats: Looking for stats for container %q, options %+v", name, opt)
		conts, err := m.GetRequestedContainersInfo(name, opt)
		if err != nil {
			if len(conts) == 0 {
				return err
			}
			glog.Errorf("Error calling GetRequestedContainersInfo: %v", err)
		}
		contStats := make(map[string]v2.ContainerInfo, len(conts))
		for name, cont := range conts {
			if name == "/" {
				// Root cgroup stats should be exposed as machine stats
				continue
			}
			contStats[name] = v2.ContainerInfo{
				Spec:  v2.ContainerSpecFromV1(&cont.Spec, cont.Aliases, cont.Namespace),
				Stats: v2.ContainerStatsFromV1(&cont.Spec, cont.Stats),
			}
		}
		return writeResult(contStats, w)
	default:
		return self.baseVersion.HandleRequest(requestType, request, m, w, r)
	}
}