Esempio n. 1
0
        public IActionResult GetRunningInstances()
        {
            string cmd    = "";
            string output = "";

            List <InstanceResponse> getAllInstances = InstancePayload.Get();

            #region GPU listing

            cmd = "gpustat --json";
            try
            {
                output = cmd.Bash();
                if (!string.IsNullOrEmpty(output))
                {
                    JObject jsonObj = JObject.Parse(output);
                    JArray  arr     = (JArray)jsonObj["gpus"];
                    int     gpuctr  = 1;
                    foreach (var a in arr)
                    {
                        JArray tmpArr = (JArray)a["processes"];
                        List <InstanceProperty> _props = new List <InstanceProperty>();

                        _props.Add(new InstanceProperty {
                            key = "temperature.gpu [celsius]", value = a["temperature.gpu"]
                        });
                        _props.Add(new InstanceProperty {
                            key = "utilization.gpu [%]", value = a["utilization.gpu"]
                        });
                        _props.Add(new InstanceProperty {
                            key = "power.draw [W]", value = a["power.draw"]
                        });
                        _props.Add(new InstanceProperty {
                            key = "enforced.power.limit [W]", value = a["enforced.power.limit"]
                        });
                        _props.Add(new InstanceProperty {
                            key = "memory.used [MB]", value = a["memory.used"]
                        });
                        _props.Add(new InstanceProperty {
                            key = "memory.total [MB]", value = a["memory.total"]
                        });

                        InstanceResponse _instance = new InstanceResponse()
                        {
                            Id         = a["uuid"].ToString(),
                            Name       = $"GPU {gpuctr}",
                            Type       = "GPU",
                            Properties = _props,
                            Processes  = tmpArr
                        };
                        getAllInstances.Add(_instance);
                        gpuctr++;
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = "running instance loading failed.", exception = ex.StackTrace }));
            }
            #endregion

            #region ZMK listing
            IList <InstanceResponse> zmkList = ZMKDockerCmdHelper.GetAllRunningZMK();
            if (zmkList.Count > 0)
            {
                getAllInstances.AddRange(zmkList);
            }

            #endregion

            return(Json(getAllInstances));
        }