From 59e26361efb9ebd8cc447bf73a972a573b5cf453 Mon Sep 17 00:00:00 2001 From: Pei Hsuan Tsai Date: Thu, 16 Aug 2018 18:15:15 +0800 Subject: [PATCH 1/2] use exported_node to query metric fome node-exporter --- deploy/helm/config/production.yaml | 2 +- src/prometheuscontroller/controller.go | 56 +++++++++++++++----------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/deploy/helm/config/production.yaml b/deploy/helm/config/production.yaml index fd942922..2cff8db0 100644 --- a/deploy/helm/config/production.yaml +++ b/deploy/helm/config/production.yaml @@ -61,7 +61,7 @@ services: pvc: volumeType: nfs nfsPath: /nfsshare - nfsServer: 172.17.8.100 + nfsServer: 10.1.14.86q reclaimPolicy: Recycle accessModes: ReadWriteMany storageClass: mongo diff --git a/src/prometheuscontroller/controller.go b/src/prometheuscontroller/controller.go index 15421e7c..b90de9e5 100644 --- a/src/prometheuscontroller/controller.go +++ b/src/prometheuscontroller/controller.go @@ -107,7 +107,7 @@ func ListNodeName(sp *serviceprovider.Container, queryLabels map[string]string) nodeList := []string{} for _, result := range results { - nodeList = append(nodeList, string(result.Metric["node"])) + nodeList = append(nodeList, string(result.Metric["exported_node"])) } return nodeList, nil @@ -553,11 +553,10 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro expression.Metrics = []string{ "kube_node_info", "kube_node_created", - "node_network_interface", "kube_node_labels", "kube_node_status_capacity.*", "kube_node_status_allocatable.*"} - expression.QueryLabels = map[string]string{"node": id} + expression.QueryLabels = map[string]string{"exported_node": id} str := basicExpr(expression.Metrics) str = queryExpr(str, expression.QueryLabels) @@ -586,24 +585,6 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro } } - case "node_network_interface": - nic := entity.NICMetrics{} - defaultValue, err := strconv.ParseBool(string(result.Metric["default"])) - if err != nil { - return node, err - } - nic.Default = defaultValue - dpdkValue, err := strconv.ParseBool(string(result.Metric["dpdk"])) - if err != nil { - return node, err - } - nic.DPDK = dpdkValue - nic.Type = string(result.Metric["type"]) - nic.IP = string(result.Metric["ip_address"]) - nic.PCIID = string(result.Metric["pci_id"]) - nic.NICNetworkTraffic = entity.NICNetworkTrafficMetrics{} - node.NICs[string(result.Metric["device"])] = nic - case "kube_node_status_allocatable_cpu_cores": node.Resource.AllocatableCPU = float32(result.Value) @@ -624,10 +605,39 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro } } + // nics + expression = Expression{} + expression.Metrics = []string{"node_network_interface"} + 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 + } + + nic := entity.NICMetrics{} + defaultValue, err := strconv.ParseBool(string(results[0].Metric["default"])) + if err != nil { + return node, err + } + nic.Default = defaultValue + dpdkValue, err := strconv.ParseBool(string(results[0].Metric["dpdk"])) + if err != nil { + return node, err + } + nic.DPDK = dpdkValue + nic.Type = string(results[0].Metric["type"]) + nic.IP = string(results[0].Metric["ip_address"]) + nic.PCIID = string(results[0].Metric["pci_id"]) + nic.NICNetworkTraffic = entity.NICNetworkTrafficMetrics{} + node.NICs[string(results[0].Metric["device"])] = nic + // status expression = Expression{} expression.Metrics = []string{"kube_node_status_condition"} - expression.QueryLabels = map[string]string{"node": id, "status": "true"} + expression.QueryLabels = map[string]string{"exported_node": id, "status": "true"} str = basicExpr(expression.Metrics) str = queryExpr(str, expression.QueryLabels) @@ -644,7 +654,7 @@ func GetNode(sp *serviceprovider.Container, id string) (entity.NodeMetrics, erro expression.Metrics = []string{ "kube_pod_container_resource_limits.*", "kube_pod_container_resource_requests.*"} - expression.QueryLabels = map[string]string{"node": id} + expression.QueryLabels = map[string]string{"exported_node": id} expression.SumByLabels = []string{"__name__", "resource"} str = basicExpr(expression.Metrics) From 4d86dc9a8922aa7d68c35c9a0f59f4c51dcaef4c Mon Sep 17 00:00:00 2001 From: Pei Hsuan Tsai Date: Thu, 16 Aug 2018 18:16:08 +0800 Subject: [PATCH 2/2] typo --- deploy/helm/config/production.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/helm/config/production.yaml b/deploy/helm/config/production.yaml index 2cff8db0..00244e29 100644 --- a/deploy/helm/config/production.yaml +++ b/deploy/helm/config/production.yaml @@ -61,7 +61,7 @@ services: pvc: volumeType: nfs nfsPath: /nfsshare - nfsServer: 10.1.14.86q + nfsServer: 10.1.14.86 reclaimPolicy: Recycle accessModes: ReadWriteMany storageClass: mongo