Esempio n. 1
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 {
			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)
	}
}
Esempio n. 2
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)
	}
}