Skip to content

Commit

Permalink
Merge pull request #263 from linkernetworks/phstsai/VX-273
Browse files Browse the repository at this point in the history
[Task] VX-273: Report container version and hugepages resource
  • Loading branch information
Hung-Wei Chiu authored Aug 21, 2018
2 parents 7378867 + 39f10f6 commit 6f9c863
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
23 changes: 13 additions & 10 deletions src/entity/metrics_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,18 @@ type NICOverviewMetrics struct {

// NodeResourceMetrics is the structure for node resource metrics
type NodeResourceMetrics struct {
CPURequests float32 `json:"cpuRequests"`
CPULimits float32 `json:"cpuLimits"`
MemoryRequests float32 `json:"memoryRequests"`
MemoryLimits float32 `json:"memoryLimits"`
AllocatableCPU float32 `json:"allocatableCPU"`
AllocatableMemory float32 `json:"allocatableMemory"`
AllocatablePods float32 `json:"allocatablePods"`
CapacityCPU float32 `json:"capacityCPU"`
CapacityMemory float32 `json:"capacityMemory"`
CapacityPods float32 `json:"capacityPods"`
CPURequests float32 `json:"cpuRequests"`
CPULimits float32 `json:"cpuLimits"`
MemoryRequests float32 `json:"memoryRequests"`
MemoryLimits float32 `json:"memoryLimits"`
MemoryTotalHugepages float32 `json:"memoryTotalHugepages"`
MemoryFreeHugepages float32 `json:"memoryFreeHugepages"`
AllocatableCPU float32 `json:"allocatableCPU"`
AllocatableMemory float32 `json:"allocatableMemory"`
AllocatablePods float32 `json:"allocatablePods"`
CapacityCPU float32 `json:"capacityCPU"`
CapacityMemory float32 `json:"capacityMemory"`
CapacityPods float32 `json:"capacityPods"`
}

// NodeDetailMetrics is the structure for node detail metrics
Expand All @@ -56,6 +58,7 @@ type NodeDetailMetrics struct {
Status string `json:"status"`
OS string `json:"os"`
KernelVersion string `json:"kernelVersion"`
ContainerVersion string `json:"containerVersion"`
KubeproxyVersion string `json:"kubeproxyVersion"`
KubernetesVersion string `json:"kubernetesVersion"`
Labels map[string]string `json:"labels"`
Expand Down
27 changes: 26 additions & 1 deletion src/prometheuscontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro
case "kube_node_info":
node.Detail.Hostname = id
node.Detail.KernelVersion = string(result.Metric["kernel_version"])
node.Detail.ContainerVersion = strings.Split(string(result.Metric["container_runtime_version"]), "//")[1]
node.Detail.KubeproxyVersion = string(result.Metric["kubeproxy_version"])
node.Detail.OS = string(result.Metric["os_image"])
node.Detail.KubernetesVersion = string(result.Metric["kubelet_version"])
Expand Down Expand Up @@ -652,7 +653,7 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro

node.Detail.Status = string(results[0].Metric["condition"])

// resource
// resource reported from kube-state-metrics
expression = Expression{}
expression.Metrics = []string{
"kube_pod_container_resource_limits.*",
Expand Down Expand Up @@ -684,6 +685,30 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro
}
}

// resource resported form node-exporter
expression = Expression{}
expression.Metrics = []string{
"node_memory_HugePages_Total",
"node_memory_HugePages_Free"}
expression.QueryLabels = map[string]string{"node": id}

str = basicExpr(expression.Metrics)
str = queryExpr(str, expression.QueryLabels)
results, err = query(sp, str)
if err != nil {
return node, err
}

for _, result := range results {
switch result.Metric["__name__"] {
case "node_memory_HugePages_Total":
node.Resource.MemoryTotalHugepages = float32(result.Value)

case "node_memory_HugePages_Free":
node.Resource.MemoryFreeHugepages = float32(result.Value)
}
}

// network traffic receive bytes
expression.Metrics = []string{"node_network_receive_bytes_total"}
expression.QueryLabels = map[string]string{"node": id}
Expand Down

0 comments on commit 6f9c863

Please sign in to comment.