func ResizeReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string, delta int, maximumSize int, minimumSize int) (resized bool, size int, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("ResizeReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			resized = false
			size = -1
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName + "/"
	result, err := restclient.RequestGet(url, headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Get replication controller information failure where delta: %d, endpoint: %s, token: %s, namespace: %s, replicationControllerName: %s, err: %s", delta, kubeApiServerEndPoint, kubeApiServerToken, namespace, replicationControllerName, err.Error())
		return false, -1, err
	} else {
		replicas, _ := jsonparse.ConvertToInt64(jsonMap["spec"].(map[string]interface{})["replicas"])
		currentSize := int(replicas)
		newSize := currentSize + delta
		if newSize < minimumSize {
			newSize = minimumSize
		}
		if newSize > maximumSize {
			newSize = maximumSize
		}

		if newSize == currentSize {
			return false, currentSize, nil
		}

		jsonMap["spec"].(map[string]interface{})["replicas"] = float64(newSize)
		result, err := restclient.RequestPut(url, jsonMap, headerMap, true)
		resultJsonMap, _ := result.(map[string]interface{})
		if err != nil {
			return false, currentSize, err
		} else {
			replicas, _ := jsonparse.ConvertToInt64(resultJsonMap["spec"].(map[string]interface{})["replicas"])
			return true, int(replicas), nil
		}
	}
}
func GetAllReplicationControllerAndRelatedPodSlice(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string) (
	returnedReplicationControllerAndRelatedPodSlice []ReplicationControllerAndRelatedPod, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedReplicationControllerAndRelatedPodSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/replicationcontrollers/", headerMap, true)
	replicationControllerJsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Fail to get all replication controller inofrmation with endpoint %s, token: %s, namespace: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, err.Error())
		return nil, err
	} else {
		result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/", headerMap, true)
		podJsonMap, _ := result.(map[string]interface{})
		if err != nil {
			log.Error("Fail to get all pod information with endpoint %s, token: %s, namespace: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, err.Error())
			return nil, err
		} else {
			replicationControllerAndRelatedPodSlice := make([]ReplicationControllerAndRelatedPod, 0)

			itemSlice, _ := replicationControllerJsonMap["items"].([]interface{})
			for _, item := range itemSlice {
				name, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
				namespace, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["namespace"].(string)
				replicaAmount, _ := jsonparse.ConvertToInt64(item.(map[string]interface{})["spec"].(map[string]interface{})["replicas"])
				aliveReplicaAmount, _ := jsonparse.ConvertToInt64(item.(map[string]interface{})["status"].(map[string]interface{})["replicas"])
				selectorField, _ := item.(map[string]interface{})["spec"].(map[string]interface{})["selector"].(map[string]interface{})
				labelField, _ := item.(map[string]interface{})["metadata"].(map[string]interface{})["labels"].(map[string]interface{})

				selectorMap := make(map[string]string)
				for key, value := range selectorField {
					selectorMap[key], _ = value.(string)
				}

				labelMap := make(map[string]string)
				for key, value := range labelField {
					labelMap[key], _ = value.(string)
				}

				podSlice, _ := GetAllPodBelongToReplicationControllerFromData(name, podJsonMap)
				replicationControllerAndRelatedPod := ReplicationControllerAndRelatedPod{
					name,
					namespace,
					int(replicaAmount),
					int(aliveReplicaAmount),
					selectorMap,
					labelMap,
					podSlice,
				}

				replicationControllerAndRelatedPodSlice = append(replicationControllerAndRelatedPodSlice, replicationControllerAndRelatedPod)
			}

			return replicationControllerAndRelatedPodSlice, nil
		}
	}
}
Example #3
0
func MonitorPod(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, podName string) (returnedPodMetric *PodMetric, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("MonitorPod Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedPodMetric = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/namespaces/"+namespace+"/pods/"+podName+"/", headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Fail to get pod inofrmation with endpoint: %s, token: %s, namespace: %s, pod name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, podName, err.Error())
		return nil, err
	}
	urlSlice, containerNameSlice, kubeletHost := getContainerLocationFromPodInformation(jsonMap)
	jsonMap["container_url_slice"] = urlSlice
	dataSlice, errorSlice := getContainerMonitorData(urlSlice)
	jsonMap["container_monitor_data_slice"] = dataSlice
	jsonMap["container_monitor_error_slice"] = errorSlice

	podMetric := &PodMetric{}
	podMetric.KubeletHost = kubeletHost
	podMetric.Namespace = namespace
	podMetric.PodName = podName
	podMetric.ValidContainerSlice = make([]bool, len(dataSlice))
	podMetric.ContainerMetricSlice = make([]ContainerMetric, len(dataSlice))
	errorMessage := "The following index of container has error: "
	errorHappened := false
	for index, data := range dataSlice {
		if errorSlice[index] != nil {
			errorMessage = errorMessage + errorSlice[index].Error()
			podMetric.ValidContainerSlice[index] = false
			errorHappened = true
		} else {
			podMetric.ValidContainerSlice[index] = true
			podMetric.ContainerMetricSlice[index] = ContainerMetric{}
			podMetric.ContainerMetricSlice[index].ContainerName = containerNameSlice[index]
			length := len(data["stats"].([]interface{}))
			// CPU
			podMetric.ContainerMetricSlice[index].CpuUsageTotalSlice = make([]int64, length)
			// Memory
			podMetric.ContainerMetricSlice[index].MemoryUsageSlice = make([]int64, length)
			// Disk I/O
			podMetric.ContainerMetricSlice[index].DiskIOServiceBytesStatsTotalSlice = make([]int64, length)
			podMetric.ContainerMetricSlice[index].DiskIOServicedStatsTotalSlice = make([]int64, length)
			// Network
			podMetric.ContainerMetricSlice[index].NetworkRXBytesSlice = make([]int64, length)
			podMetric.ContainerMetricSlice[index].NetworkTXBytesSlice = make([]int64, length)
			podMetric.ContainerMetricSlice[index].NetworkRXPacketsSlice = make([]int64, length)
			podMetric.ContainerMetricSlice[index].NetworkTXPacketsSlice = make([]int64, length)
			for i := 0; i < length; i++ {
				// CPU
				podMetric.ContainerMetricSlice[index].CpuUsageTotalSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["cpu"].(map[string]interface{})["usage"].((map[string]interface{}))["total"])
				// Memory
				podMetric.ContainerMetricSlice[index].MemoryUsageSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["memory"].(map[string]interface{})["usage"])
				// Disk I/O
				ioServiceBytesSlice := data["stats"].([]interface{})[i].(map[string]interface{})["diskio"].(map[string]interface{})["io_service_bytes"]
				if ioServiceBytesSlice != nil {
					for _, ioServiceBytes := range ioServiceBytesSlice.([]interface{}) {
						value, _ := jsonparse.ConvertToInt64(ioServiceBytes.(map[string]interface{})["stats"].(map[string]interface{})["Total"])
						podMetric.ContainerMetricSlice[index].DiskIOServiceBytesStatsTotalSlice[i] += value
					}
				}
				ioServicedSlice := data["stats"].([]interface{})[i].(map[string]interface{})["diskio"].(map[string]interface{})["io_serviced"]
				if ioServicedSlice != nil {
					for _, ioServiced := range ioServicedSlice.([]interface{}) {
						value, _ := jsonparse.ConvertToInt64(ioServiced.(map[string]interface{})["stats"].(map[string]interface{})["Total"])
						podMetric.ContainerMetricSlice[index].DiskIOServicedStatsTotalSlice[i] += value
					}
				}
				// Network
				podMetric.ContainerMetricSlice[index].NetworkRXBytesSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["rx_bytes"])
				podMetric.ContainerMetricSlice[index].NetworkTXBytesSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["tx_bytes"])
				podMetric.ContainerMetricSlice[index].NetworkRXPacketsSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["rx_packets"])
				podMetric.ContainerMetricSlice[index].NetworkTXPacketsSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["tx_packets"])
			}
		}
	}

	if errorHappened {
		log.Error("Fail to get all container inofrmation with endpoint %s, token: %s, namespace: %s, pod name: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, namespace, podName, errorMessage)
		return podMetric, errors.New(errorMessage)
	} else {
		return podMetric, nil
	}
}
Example #4
0
func GetAllPodBelongToReplicationControllerFromData(replicationControllerName string, jsonMap map[string]interface{}) (returnedPodSlice []Pod, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllPodBelongToReplicationControllerFromData Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedPodSlice = nil
			returnedError = err.(error)
		}
	}()

	generateName := replicationControllerName + "-"
	podSlice := make([]Pod, 0)
	for _, data := range jsonMap["items"].([]interface{}) {
		generateNameField, _ := data.(map[string]interface{})["metadata"].(map[string]interface{})["generateName"].(string)
		nameField, nameFieldOk := data.(map[string]interface{})["metadata"].(map[string]interface{})["name"].(string)
		if generateName == generateNameField || replicationControllerName == nameField {
			if nameFieldOk {
				containerSlice := make([]PodContainer, 0)
				containerFieldSlice, containerFieldSliceOk := data.(map[string]interface{})["spec"].(map[string]interface{})["containers"].([]interface{})
				containerStatusSlice, containerStatusSliceOk := data.(map[string]interface{})["status"].(map[string]interface{})["containerStatuses"].([]interface{})
				if containerFieldSliceOk && containerStatusSliceOk {
					for _, containerField := range containerFieldSlice {
						portSlice := make([]PodContainerPort, 0)
						portFieldSlice, portFieldSliceOk := containerField.(map[string]interface{})["ports"].([]interface{})
						if portFieldSliceOk {
							for _, portField := range portFieldSlice {
								portName, _ := portField.(map[string]interface{})["name"].(string)
								portContainerPort, _ := jsonparse.ConvertToInt64(portField.(map[string]interface{})["containerPort"])
								portProtocol, _ := portField.(map[string]interface{})["protocol"].(string)

								podContainerPort := PodContainerPort{
									portName,
									int(portContainerPort),
									portProtocol,
								}

								portSlice = append(portSlice, podContainerPort)
							}
						}

						containerName, _ := containerField.(map[string]interface{})["name"].(string)
						containerImage, _ := containerField.(map[string]interface{})["image"].(string)

						containerId := ""
						containerReady := false
						containerRestartCount := 0
						for _, containerStatus := range containerStatusSlice {
							name, _ := containerStatus.(map[string]interface{})["name"].(string)
							if name == containerName {
								containerId, _ = containerStatus.(map[string]interface{})["containerID"].(string)
								containerReady, _ = containerStatus.(map[string]interface{})["ready"].(bool)
								restartCount, _ := jsonparse.ConvertToInt64(containerStatus.(map[string]interface{})["restartCount"])
								containerRestartCount = int(restartCount)
							}
						}

						podContainer := PodContainer{
							containerName,
							containerImage,
							containerId,
							containerRestartCount,
							containerReady,
							portSlice,
						}

						containerSlice = append(containerSlice, podContainer)
					}
				}

				namespace, _ := data.(map[string]interface{})["metadata"].(map[string]interface{})["namespace"].(string)
				creationTimestamp, _ := data.(map[string]interface{})["metadata"].(map[string]interface{})["creationTimestamp"].(string)
				createdTime, err := time.Parse(time.RFC3339, creationTimestamp)
				age := ""
				if err == nil {
					age = GetTheFirstTimeUnit(time.Now().Sub(createdTime))
				}

				phase, _ := data.(map[string]interface{})["status"].(map[string]interface{})["phase"].(string)
				hostIP, _ := data.(map[string]interface{})["status"].(map[string]interface{})["hostIP"].(string)
				podIP, _ := data.(map[string]interface{})["status"].(map[string]interface{})["podIP"].(string)
				pod := Pod{
					nameField,
					namespace,
					hostIP,
					podIP,
					phase,
					age,
					containerSlice,
				}
				podSlice = append(podSlice, pod)
			}
		}
	}

	return podSlice, nil
}
func GetReplicationController(kubeApiServerEndPoint string, kubeApiServerToken string, namespace string, replicationControllerName string) (replicationController *ReplicationController, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetReplicationController Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			replicationController = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/namespaces/" + namespace + "/replicationcontrollers/" + replicationControllerName
	result, err := restclient.RequestGet(url, headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		return nil, err
	} else {
		replicationController := new(ReplicationController)
		replicationController.Name, _ = jsonMap["metadata"].(map[string]interface{})["name"].(string)
		selector := jsonMap["spec"].(map[string]interface{})["selector"]
		if selector != nil {
			replicationController.Selector.Name, _ = selector.(map[string]interface{})["name"].(string)
			replicationController.Selector.Version, _ = selector.(map[string]interface{})["version"].(string)
		}

		replicas, _ := jsonparse.ConvertToInt64(jsonMap["spec"].(map[string]interface{})["replicas"])
		replicationController.ReplicaAmount = int(replicas)
		replicationControllerLabelMap := jsonMap["metadata"].(map[string]interface{})["labels"]
		if replicationControllerLabelMap != nil {
			replicationController.Label.Name, _ = replicationControllerLabelMap.(map[string]interface{})["name"].(string)
		}

		containerSlice := jsonMap["spec"].(map[string]interface{})["template"].(map[string]interface{})["spec"].(map[string]interface{})["containers"]
		if containerSlice != nil {
			replicationController.ContainerSlice = make([]ReplicationControllerContainer, 0)
			for _, container := range containerSlice.([]interface{}) {
				replicationControllerContainer := ReplicationControllerContainer{}
				replicationControllerContainer.Name, _ = container.(map[string]interface{})["name"].(string)
				replicationControllerContainer.Image, _ = container.(map[string]interface{})["image"].(string)
				portSlice, _ := container.(map[string]interface{})["ports"].([]interface{})
				replicationControllerContainer.PortSlice = make([]ReplicationControllerContainerPort, 0)
				for _, port := range portSlice {
					replicationControllerContainerPort := ReplicationControllerContainerPort{}
					replicationControllerContainerPort.Name, _ = port.(map[string]interface{})["name"].(string)
					containerPort, _ := jsonparse.ConvertToInt64(port.(map[string]interface{})["containerPort"])
					replicationControllerContainerPort.ContainerPort = int(containerPort)
					replicationControllerContainer.PortSlice = append(replicationControllerContainer.PortSlice, replicationControllerContainerPort)
				}

				environmentSlice, _ := container.(map[string]interface{})["env"].([]interface{})
				replicationControllerContainer.EnvironmentSlice = make([]ReplicationControllerContainerEnvironment, 0)
				for _, environment := range environmentSlice {
					name := environment.(map[string]interface{})["name"].(string)
					value := environment.(map[string]interface{})["value"].(string)
					replicationControllerContainer.EnvironmentSlice = append(replicationControllerContainer.EnvironmentSlice, ReplicationControllerContainerEnvironment{name, value})
				}

				replicationControllerContainer.ResourceMap, _ = container.(map[string]interface{})["resources"].(map[string]interface{})

				replicationController.ContainerSlice = append(replicationController.ContainerSlice, replicationControllerContainer)
			}
		}

		return replicationController, nil
	}
}
func GetHistoricalReplicationControllerMetrics(namespace string,
	replicationControllerName string, aggregationAmount int, from time.Time,
	to time.Time) (returnedJsonMap map[string]interface{}, returnedError error) {
	byteSlice, err := searchHistoricalReplicationControllerMetrics(namespace,
		replicationControllerName, aggregationAmount, from, to)
	if err != nil {
		return nil, err
	} else {
		jsonMap := make(map[string]interface{})
		decoder := json.NewDecoder(bytes.NewReader(byteSlice))
		decoder.UseNumber()
		err := decoder.Decode(&jsonMap)
		if err != nil {
			return nil, err
		} else {
			timestampSlice := make([]string, 0)
			replicationControllerJsonMap := make(map[string]interface{})

			timeBucketSlice, _ := jsonMap["aggregations"].(map[string]interface{})["aggregation_time_interval"].(map[string]interface{})["buckets"].([]interface{})
			timeBucketAmount := len(timeBucketSlice)
			for timeIndex, timeBucket := range timeBucketSlice {
				timestamp, _ := timeBucket.(map[string]interface{})["key_as_string"].(string)
				timestampSlice = append(timestampSlice, timestamp)

				podBucketSlice, _ := timeBucket.(map[string]interface{})["aggregation_pod"].(map[string]interface{})["buckets"].([]interface{})
				for _, podBucket := range podBucketSlice {
					podName, _ := podBucket.(map[string]interface{})["key"].(string)
					containerBucketSlice, _ := podBucket.(map[string]interface{})["aggregation_container"].(map[string]interface{})["buckets"].([]interface{})

					podJsonMap, _ := replicationControllerJsonMap[podName].(map[string]interface{})
					if podJsonMap == nil {
						podJsonMap = make(map[string]interface{})
					}

					for _, containerBucket := range containerBucketSlice {
						containerName, _ := containerBucket.(map[string]interface{})["key"].(string)

						documentCount, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["doc_count"])
						minimumCpuUsageTotal, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_cpu_usage_total"].(map[string]interface{})["value"])
						averageMemoryUsage, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["average_memory_usage"].(map[string]interface{})["value"])
						minimumDiskioIoServiceBytesStatsTotal, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_diskio_io_service_bytes_stats_total"].(map[string]interface{})["value"])
						minimumDiskioIoServicedStatsTotal, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_diskio_io_serviced_stats_total"].(map[string]interface{})["value"])
						minimumNetworkRxPackets, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_network_rx_packets"].(map[string]interface{})["value"])
						minimumNetworkTxPackets, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_network_tx_packets"].(map[string]interface{})["value"])
						minimumNetworkRxBytes, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_network_rx_bytes"].(map[string]interface{})["value"])
						minimumNetworkTxBytes, _ := jsonparse.ConvertToInt64(containerBucket.(map[string]interface{})["minimum_network_tx_bytes"].(map[string]interface{})["value"])

						containerJsonMap, _ := podJsonMap[containerName].(map[string]interface{})
						if containerJsonMap == nil {
							containerJsonMap = make(map[string]interface{})
						}

						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "documentCountSlice", int64(documentCount))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumCpuUsageTotalSlice", int64(minimumCpuUsageTotal))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "averageMemoryUsageSlice", int64(averageMemoryUsage))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumDiskioIoServiceBytesStatsTotalSlice", int64(minimumDiskioIoServiceBytesStatsTotal))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumDiskioIoServicedStatsTotalSlice", int64(minimumDiskioIoServicedStatsTotal))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumNetworkRxPacketsSlice", int64(minimumNetworkRxPackets))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumNetworkTxPacketsSlice", int64(minimumNetworkTxPackets))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumNetworkRxBytesSlice", int64(minimumNetworkRxBytes))
						appendToSliceInJsonMap(timeBucketAmount, timeIndex, containerJsonMap, "minimumNetworkTxBytesSlice", int64(minimumNetworkTxBytes))

						podJsonMap[containerName] = containerJsonMap
					}

					replicationControllerJsonMap[podName] = podJsonMap
				}
			}

			// Interpolate the hole
			for podName, _ := range replicationControllerJsonMap {
				for containerName, _ := range replicationControllerJsonMap[podName].(map[string]interface{}) {
					for metricsName, _ := range replicationControllerJsonMap[podName].(map[string]interface{})[containerName].(map[string]interface{}) {
						fillTheNullDataWithInterpolationForInt64Slice(replicationControllerJsonMap[podName].(map[string]interface{})[containerName].(map[string]interface{})[metricsName].([]interface{}))
					}
				}
			}

			// Add timestamp
			replicationControllerJsonMap["timestamp"] = timestampSlice

			return replicationControllerJsonMap, nil
		}
	}
}
Example #7
0
func MonitorNode(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedNodeMetricSlice []NodeMetric, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("MonitorNode Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedNodeMetricSlice = nil
			returnedError = err.(error)
		}
	}()

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	result, err := restclient.RequestGet(kubeApiServerEndPoint+"/api/v1/nodes", headerMap, true)
	jsonMap, _ := result.(map[string]interface{})
	if err != nil {
		log.Error("Fail to get node inofrmation with endpoint: %s, token: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, err.Error())
		return nil, err
	}
	urlSlice, addressSlice := getNodeLocationFromNodeInformation(jsonMap)
	dataSlice, errorSlice := getNodeMonitorData(urlSlice)

	nodeAmount := len(dataSlice)
	nodeMetricSlice := make([]NodeMetric, nodeAmount)
	errorMessage := "The following index of container has error: "
	errorHappened := false
	for index, data := range dataSlice {
		if errorSlice[index] != nil {
			errorMessage = errorMessage + errorSlice[index].Error()
			nodeMetricSlice[index].Valid = false
			nodeMetricSlice[index].KubeletHost = addressSlice[index]
			errorHappened = true
		} else {
			nodeMetricSlice[index].Valid = true
			nodeMetricSlice[index].KubeletHost = addressSlice[index]
			length := len(data["stats"].([]interface{}))
			// CPU
			nodeMetricSlice[index].CpuUsageTotalSlice = make([]int64, length)
			// Memory
			nodeMetricSlice[index].MemoryUsageSlice = make([]int64, length)
			// Disk I/O
			nodeMetricSlice[index].DiskIOServiceBytesStatsTotalSlice = make([]int64, length)
			nodeMetricSlice[index].DiskIOServicedStatsTotalSlice = make([]int64, length)
			// Network
			nodeMetricSlice[index].NetworkRXBytesSlice = make([]int64, length)
			nodeMetricSlice[index].NetworkTXBytesSlice = make([]int64, length)
			nodeMetricSlice[index].NetworkRXPacketsSlice = make([]int64, length)
			nodeMetricSlice[index].NetworkTXPacketsSlice = make([]int64, length)
			for i := 0; i < length; i++ {
				// CPU
				nodeMetricSlice[index].CpuUsageTotalSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["cpu"].(map[string]interface{})["usage"].((map[string]interface{}))["total"])
				// Memory
				nodeMetricSlice[index].MemoryUsageSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["memory"].(map[string]interface{})["usage"])
				// Disk I/O
				ioServiceBytesSlice := data["stats"].([]interface{})[i].(map[string]interface{})["diskio"].(map[string]interface{})["io_service_bytes"].([]interface{})
				for _, ioServiceBytes := range ioServiceBytesSlice {
					value, _ := jsonparse.ConvertToInt64(ioServiceBytes.(map[string]interface{})["stats"].(map[string]interface{})["Total"])
					nodeMetricSlice[index].DiskIOServiceBytesStatsTotalSlice[i] += value
				}
				ioServicedSlice := data["stats"].([]interface{})[i].(map[string]interface{})["diskio"].(map[string]interface{})["io_serviced"].([]interface{})
				for _, ioServiced := range ioServicedSlice {
					value, _ := jsonparse.ConvertToInt64(ioServiced.(map[string]interface{})["stats"].(map[string]interface{})["Total"])
					nodeMetricSlice[index].DiskIOServicedStatsTotalSlice[i] += value
				}
				// Network
				nodeMetricSlice[index].NetworkRXBytesSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["rx_bytes"])
				nodeMetricSlice[index].NetworkTXBytesSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["tx_bytes"])
				nodeMetricSlice[index].NetworkRXPacketsSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["rx_packets"])
				nodeMetricSlice[index].NetworkTXPacketsSlice[i], _ = jsonparse.ConvertToInt64(data["stats"].([]interface{})[i].(map[string]interface{})["network"].(map[string]interface{})["tx_packets"])
			}
		}
	}

	if errorHappened {
		log.Error("Fail to get all node inofrmation with endpoint %s, token: %s, error %s", kubeApiServerEndPoint, kubeApiServerToken, errorMessage)
		return nodeMetricSlice, nil
	} else {
		return nodeMetricSlice, nil
	}
}