infrastructure.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package priorities
  2. import (
  3. "os"
  4. "time"
  5. client "github.com/influxdata/influxdb1-client/v2"
  6. "gopkg.in/yaml.v2"
  7. "k8s.io/klog"
  8. )
  9. type scorerInput struct {
  10. metricName string
  11. metrics map[string]float64
  12. }
  13. type Config struct {
  14. Server struct {
  15. Port string `yaml:"port"`
  16. Host string `yaml:"host"`
  17. } `yaml:"server"`
  18. Database struct {
  19. Type string `yaml:"type"`
  20. Name string `yaml:"name"`
  21. Username string `yaml:"username"`
  22. Password string `yaml:"password"`
  23. } `yaml:"database"`
  24. MonitoringSpecs struct {
  25. TimeInterval float32 `yaml:"interval"`
  26. } `yaml:"monitoring"`
  27. }
  28. type Application struct {
  29. Metrics map[string]float64
  30. Duration time.Duration
  31. }
  32. var Applications = map[string]Application{
  33. "scikit-lasso": Application{
  34. Metrics: map[string]float64{
  35. "ipc": 1.87,
  36. "mem_read": 0.1753,
  37. "mem_write": 0.008856,
  38. "c6res": 0.003058,
  39. },
  40. Duration: 69 * time.Second,
  41. },
  42. "scikit-ada": Application{
  43. Metrics: map[string]float64{
  44. "ipc": 1.10,
  45. "mem_read": 0.09868,
  46. "mem_write": 0.00669,
  47. "c6res": 0,
  48. },
  49. Duration: 138 * time.Second,
  50. },
  51. "scikit-rfr": Application{
  52. Metrics: map[string]float64{
  53. "ipc": 1.25,
  54. "mem_read": 0.0228,
  55. "mem_write": 0.00503,
  56. "c6res": 0,
  57. },
  58. Duration: 115 * time.Second,
  59. },
  60. "scikit-rfc": Application{
  61. Metrics: map[string]float64{
  62. "ipc": 1.802,
  63. "mem_read": 0.02423,
  64. "mem_write": 0.010603,
  65. "c6res": 0,
  66. },
  67. Duration: 38 * time.Second,
  68. },
  69. "scikit-linregr": Application{
  70. Metrics: map[string]float64{
  71. "ipc": 1.9464,
  72. "mem_read": 0.040475,
  73. "mem_write": 0.01974,
  74. "c6res": 0.00928149,
  75. },
  76. Duration: 45 * time.Second,
  77. },
  78. "scikit-lda": Application{
  79. Metrics: map[string]float64{
  80. "ipc": 1.9162,
  81. "mem_read": 0.0541,
  82. "mem_write": 0.029381,
  83. "c6res": 0.003805,
  84. },
  85. Duration: 53 * time.Second,
  86. },
  87. "cloudsuite-data-serving-client": Application{
  88. Metrics: map[string]float64{
  89. "ipc": 0.6619,
  90. "mem_read": 0,
  91. "mem_write": 0,
  92. "c6res": 44.48,
  93. },
  94. Duration: 72 * time.Second,
  95. },
  96. "cloudsuite-in-memory-analytics": Application{
  97. Metrics: map[string]float64{
  98. "ipc": 1.3399,
  99. "mem_read": 0.0052142,
  100. "mem_write": 0.61361,
  101. "c6res": 3.76196,
  102. },
  103. Duration: 60 * time.Second,
  104. },
  105. "cloudsuite-web-serving-client": Application{
  106. Metrics: map[string]float64{
  107. "ipc": 0.6619,
  108. "mem_read": 0,
  109. "mem_write": 0,
  110. "c6res": 44.48,
  111. },
  112. Duration: 203 * time.Second,
  113. },
  114. "spec-sphinx": Application{
  115. Metrics: map[string]float64{
  116. "ipc": 2.035,
  117. "mem_read": 0.0042372,
  118. "mem_write": 0.0021131,
  119. "c6res": 0.07497,
  120. },
  121. Duration: 592 * time.Second,
  122. },
  123. "spec-cactus": Application{
  124. Metrics: map[string]float64{
  125. "ipc": 1.353,
  126. "mem_read": 0.07105,
  127. "mem_write": 0.0273161,
  128. "c6res": 0.0532267,
  129. },
  130. Duration: 780 * time.Second,
  131. },
  132. "spec-astar": Application{
  133. Metrics: map[string]float64{
  134. "ipc": 0.86314,
  135. "mem_read": 0.0063,
  136. "mem_write": 0.0032874,
  137. "c6res": 0.09115,
  138. },
  139. Duration: 468 * time.Second,
  140. },
  141. "spec-leslie": Application{
  142. Metrics: map[string]float64{
  143. "ipc": 1.5225,
  144. "mem_read": 0.3221,
  145. "mem_write": 0.1532,
  146. "c6res": 0.1215,
  147. },
  148. Duration: 378 * time.Second,
  149. },
  150. }
  151. var Nodes = map[string]string{
  152. "kube-01": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  153. "kube-02": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  154. "kube-03": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  155. "kube-04": "e77467ad-636e-4e7e-8bc9-53e46ae51da1",
  156. "kube-05": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  157. "kube-06": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  158. "kube-07": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  159. "kube-08": "c4766d29-4dc1-11ea-9d98-0242ac110002",
  160. }
  161. var links = map[string][]float32{
  162. "e77467ad-636e-4e7e-8bc9-53e46ae51da1": []float32{3, 10.4},
  163. "c4766d29-4dc1-11ea-9d98-0242ac110002": []float32{2, 9.6},
  164. }
  165. var maxSpeed = map[string]float32{
  166. "e77467ad-636e-4e7e-8bc9-53e46ae51da1": 2.2,
  167. "c4766d29-4dc1-11ea-9d98-0242ac110002": 2.0,
  168. }
  169. var Sockets = map[string]int{
  170. "kube-01": 1,
  171. "kube-02": 0,
  172. "kube-03": 0,
  173. "kube-04": 1,
  174. "kube-05": 0,
  175. //"kube-06": 1,
  176. "kube-07": 0,
  177. "kube-08": 1,
  178. }
  179. var Cores = map[string][]int{
  180. "kube-01": []int{20, 21, 22, 23},
  181. "kube-02": []int{2, 3, 4, 5, 6, 7, 8, 9},
  182. "kube-03": []int{40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55},
  183. "kube-04": []int{24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75},
  184. "kube-05": []int{0, 1, 2, 3},
  185. //"kube-06": []int{12, 13, 14, 15, 16, 17, 18, 19},
  186. "kube-07": []int{4, 5, 6, 7, 8, 9, 10, 11, 24, 25, 26, 27, 28, 29, 30, 31},
  187. "kube-08": []int{20, 21, 22, 23, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47},
  188. }
  189. func readFile(cfg *Config, file string) error {
  190. f, err := os.Open(file)
  191. if err != nil {
  192. klog.Infof("Config file for scheduler not found. Error: %v", err)
  193. return err
  194. }
  195. defer f.Close()
  196. decoder := yaml.NewDecoder(f)
  197. err = decoder.Decode(&cfg)
  198. if err != nil {
  199. klog.Infof("Unable to decode the config file. Error: %v", err)
  200. return err
  201. }
  202. return nil
  203. }
  204. func connectToInfluxDB(cfg Config) (client.Client, error) {
  205. c, err := client.NewHTTPClient(client.HTTPConfig{
  206. Addr: "http://" + cfg.Server.Host + ":" + cfg.Server.Port + "",
  207. })
  208. if err != nil {
  209. klog.Infof("Error while connecting to InfluxDB: %v ", err.Error())
  210. return nil, err
  211. }
  212. klog.Infof("Connected Successfully to InfluxDB")
  213. return c, nil
  214. }