|
@@ -18,10 +18,13 @@ package priorities
|
|
|
|
|
|
import (
|
|
import (
|
|
"database/sql"
|
|
"database/sql"
|
|
|
|
+ "fmt"
|
|
|
|
+ "os"
|
|
|
|
+
|
|
_ "github.com/go-sql-driver/mysql"
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
+ client "github.com/influxdata/influxdb1-client/v2"
|
|
"gopkg.in/yaml.v2"
|
|
"gopkg.in/yaml.v2"
|
|
"k8s.io/klog"
|
|
"k8s.io/klog"
|
|
- "os"
|
|
|
|
)
|
|
)
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -61,6 +64,7 @@ var nodes = map[string]string{
|
|
"kube-02": "2",
|
|
"kube-02": "2",
|
|
"kube-03": "2",
|
|
"kube-03": "2",
|
|
"kube-04": "2",
|
|
"kube-04": "2",
|
|
|
|
+ "kube-05": "2",
|
|
}
|
|
}
|
|
|
|
|
|
func readFile(cfg *Config, file string) {
|
|
func readFile(cfg *Config, file string) {
|
|
@@ -95,32 +99,54 @@ func customResourceScorer(nodeName string) int64 {
|
|
panic(err.Error())
|
|
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
|
|
//Get the uuid of this node in order to query in the database
|
|
curr_uuid, ok := nodes[nodeName]
|
|
curr_uuid, ok := nodes[nodeName]
|
|
|
|
|
|
- //Get the metrics for the current node
|
|
|
|
if ok {
|
|
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)
|
|
res := customRequestedScore(nodeName)
|
|
klog.Infof("Node name %s, has score %d\n", nodeName, res)
|
|
klog.Infof("Node name %s, has score %d\n", nodeName, res)
|
|
return res
|
|
return res
|