|
@@ -27,8 +27,9 @@ package noderesources
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "database/sql"
|
|
|
"fmt"
|
|
|
-
|
|
|
+ _ "github.com/go-sql-driver/mysql"
|
|
|
v1 "k8s.io/api/core/v1"
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
"k8s.io/klog"
|
|
@@ -50,10 +51,27 @@ type nodeMetrics struct {
|
|
|
averageIPC float32
|
|
|
}
|
|
|
|
|
|
+type System struct {
|
|
|
+ ID int `json:"id"`
|
|
|
+ Uuid string `json:"uuid"`
|
|
|
+ numSockets int `json:"num_sockets"`
|
|
|
+ numCores int `json:"num_cores`
|
|
|
+}
|
|
|
+
|
|
|
type wrongValueError struct{}
|
|
|
|
|
|
var _ = framework.ScorePlugin(&CustomAllocated{})
|
|
|
|
|
|
+//Map nodes to uuid
|
|
|
+//var nodes = make(map[string]string)
|
|
|
+
|
|
|
+var nodes = map[string]string{
|
|
|
+ "kube-01": "c4766d29-4dc1-11ea-9d98-0242ac110002",
|
|
|
+ "kube-02": "2",
|
|
|
+ "kube-03": "2",
|
|
|
+ "kube-04": "2",
|
|
|
+}
|
|
|
+
|
|
|
// CustomAllocatedName is the name of the plugin used in the plugin registry and configurations.
|
|
|
const CustomAllocatedName = "NodeResourcesCustomAllocated"
|
|
|
|
|
@@ -64,7 +82,39 @@ func (ca *CustomAllocated) Name() string {
|
|
|
|
|
|
func getCustomMetrics(name string) *nodeMetrics {
|
|
|
|
|
|
+ //Open the database connection
|
|
|
+ db, err := sql.Open("mysql", "client:password@tcp(147.102.37.161:3306)/evolve")
|
|
|
+ if err != nil {
|
|
|
+ panic(err.Error())
|
|
|
+ }
|
|
|
+
|
|
|
+ defer db.Close()
|
|
|
+
|
|
|
+ curr_uuid, ok := nodes[name]
|
|
|
+
|
|
|
nd := nodeMetrics{}
|
|
|
+
|
|
|
+ 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", name, sys.ID, sys.numCores)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //nd := nodeMetrics{}
|
|
|
if name == "kube-01" {
|
|
|
nd.L3cacheMisses = 1
|
|
|
nd.memoryReads = 1
|