Exemple #1
0
func (a *Api) nodeMetricsList(request *restful.Request, response *restful.Response) {
	selector := request.QueryParameter("labelSelector")

	labelSelector, err := labels.Parse(selector)
	if err != nil {
		errMsg := fmt.Errorf("Error while parsing selector %v: %v", selector, err)
		glog.Error(errMsg)
		response.WriteError(http.StatusBadRequest, errMsg)
		return
	}

	nodes, err := a.nodeLister.NodeCondition(func(node *kube_api.Node) bool {
		if labelSelector.Empty() {
			return true
		}
		return labelSelector.Matches(labels.Set(node.Labels))
	}).List()
	if err != nil {
		errMsg := fmt.Errorf("Error while listing nodes: %v", err)
		glog.Error(errMsg)
		response.WriteError(http.StatusInternalServerError, errMsg)
		return
	}

	res := v1alpha1.NodeMetricsList{}
	for _, node := range nodes {
		if m := a.getNodeMetrics(node.Name); m != nil {
			res.Items = append(res.Items, *m)
		}
	}
	response.WriteEntity(&res)
}
Exemple #2
0
func (a *Api) nodeMetricsList(request *restful.Request, response *restful.Response) {
	res := v1alpha1.NodeMetricsList{}
	for _, node := range a.metricSink.GetNodes() {
		if m := a.getNodeMetrics(node); m != nil {
			res.Items = append(res.Items, *m)
		}
	}
	response.WriteEntity(&res)
}