Achilleas Tzenetopoulos 5 年 前
コミット
b113372349

+ 1 - 0
kubernetes-v1.15.4/go.mod

@@ -86,6 +86,7 @@ require (
 	github.com/heketi/rest v0.0.0-20180404230133-aa6a65207413 // indirect
 	github.com/heketi/tests v0.0.0-20151005000721-f3775cbcefd6 // indirect
 	github.com/heketi/utils v0.0.0-20170317161834-435bc5bdfa64 // indirect
+	github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d
 	github.com/jonboulle/clockwork v0.0.0-20141017032234-72f9bd7c4e0c
 	github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be
 	github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024

+ 2 - 0
kubernetes-v1.15.4/go.sum

@@ -236,6 +236,8 @@ github.com/imdario/mergo v0.3.5 h1:JboBksRwiiAJWvIYJVo46AfV+IAIKZpfrSzVKj42R4Q=
 github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
 github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
 github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
+github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d h1:/WZQPMZNsjZ7IlCpsLGdQBINg5bxKQ1K1sh6awxLtkA=
+github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
 github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
 github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
 github.com/jonboulle/clockwork v0.0.0-20141017032234-72f9bd7c4e0c h1:XpRROA6ssPlTwJI8/pH+61uieOkcJhmAFz25cu0B94Y=

+ 46 - 20
kubernetes-v1.15.4/pkg/scheduler/algorithm/priorities/custom_resource_allocation.go

@@ -18,10 +18,13 @@ package priorities
 
 import (
 	"database/sql"
+	"fmt"
+	"os"
+
 	_ "github.com/go-sql-driver/mysql"
+	client "github.com/influxdata/influxdb1-client/v2"
 	"gopkg.in/yaml.v2"
 	"k8s.io/klog"
-	"os"
 )
 
 var (
@@ -61,6 +64,7 @@ var nodes = map[string]string{
 	"kube-02": "2",
 	"kube-03": "2",
 	"kube-04": "2",
+	"kube-05": "2",
 }
 
 func readFile(cfg *Config, file string) {
@@ -95,32 +99,54 @@ func customResourceScorer(nodeName string) int64 {
 		panic(err.Error())
 	}
 
-	//Close the database connection in the end of the execution
-	defer db.Close()
+	//TODO InfluxDB
+	c, err := client.NewHttpClient(client.HTTPConfig{
+		Addr: "http://" + cfg.Server.Host + ":" + cfg.Server.Port + "",
+	})
+	if err != nil {
+		fmt.Println("Error while creating InfluxDB client: ", err.Error())
+	}
+
+	// close the connection in the end of execution
+	defer c.Close()
 
 	//Get the uuid of this node in order to query in the database
 	curr_uuid, ok := nodes[nodeName]
 
-	//Get the metrics for the current node
 	if ok {
-		results, err := db.Query("SELECT id, num_sockets, num_cores FROM systems WHERE uuid = ?", curr_uuid)
-
-		if err != nil {
-			panic(err.Error()) // proper error handling instead of panic in your app
-		}
-		sys := System{}
-		sys.Uuid = curr_uuid
-
-		for results.Next() {
-			// for each row, scan the result into our tag composite object
-			err = results.Scan(&sys.ID, &sys.numSockets, &sys.numCores)
-			if err != nil {
-				panic(err.Error()) // proper error handling instead of panic in your app
-			}
-			// and then print out the tag's Name attribute
-			klog.Infof("This is the system with name: %s, id: %d and  number of cores: %d", nodeName, sys.ID, sys.numCores)
+		command := fmt.Sprintf("SELECT ipc from system_metrics where uuid = %s order by time desc limit 1", curr_uuid)
+		q := client.NewQuery(command, "evolve", "")
+		if response, err := c.Query(q); err == nil && response.Error() == nil {
+			fmt.Println(response.Results)
 		}
 	}
+
+	// //Close the database connection in the end of the execution
+	// defer db.Close()
+
+	// //Get the uuid of this node in order to query in the database
+	// curr_uuid, ok := nodes[nodeName]
+
+	// //Get the metrics for the current node
+	// if ok {
+	// 	results, err := db.Query("SELECT id, num_sockets, num_cores FROM systems WHERE uuid = ?", curr_uuid)
+
+	// 	if err != nil {
+	// 		panic(err.Error()) // proper error handling instead of panic in your app
+	// 	}
+	// 	sys := System{}
+	// 	sys.Uuid = curr_uuid
+
+	// 	for results.Next() {
+	// 		// for each row, scan the result into our tag composite object
+	// 		err = results.Scan(&sys.ID, &sys.numSockets, &sys.numCores)
+	// 		if err != nil {
+	// 			panic(err.Error()) // proper error handling instead of panic in your app
+	// 		}
+	// 		// and then print out the tag's Name attribute
+	// 		klog.Infof("This is the system with name: %s, id: %d and  number of cores: %d", nodeName, sys.ID, sys.numCores)
+	// 	}
+	// }
 	res := customRequestedScore(nodeName)
 	klog.Infof("Node name %s, has score %d\n", nodeName, res)
 	return res

+ 1 - 0
kubernetes-v1.15.4/vendor/github.com/influxdata/influxdb1-client

@@ -0,0 +1 @@
+Subproject commit 8bf82d3c094dc06be9da8e5bf9d3589b6ea032ae