Exemplo n.º 1
0
        public ActionResult <Server_Resource_Info> GetCpu()
        {
            var request = new HttpRequestMessage();

            try
            {
                using (var context = new ServerResourcesContext())
                {
                    var lastCpuUsage = context.Server_Resource_Info
                                       .Include(SRI => SRI.Resource_Type)
                                       .Include(SRI => SRI.Sample_Time)
                                       .Include(SRI => SRI.Server_Resource_Unit)
                                       .Where(SRI => SRI.Process_FK == null && SRI.Resource_Type_FK == 2)
                                       .OrderBy(SRI => SRI.Id)
                                       .LastOrDefault();

                    if (lastCpuUsage.Sample_Time.Time >= (DateTime.Now - TimeSpan.FromSeconds(2)))
                    {
                        return(Ok(lastCpuUsage));
                    }
                }

                var topOutput = _topHelper.GetCurrentTopProcessReadings();
                var lastCalculatedCpuUsage = new Server_Resource_Info()
                {
                    Id                      = 0,
                    Value                   = topOutput.TotalCpuUsage,
                    Sample_Time_FK          = 0,
                    Server_Resource_Unit_FK = 2,
                    Sample_Time             = new Sample_Time()
                    {
                        Id = 0, Time = DateTime.Now
                    },
                    Resource_Type = new Resource_Type()
                    {
                        Id = 0, Short_Name = "CPU_USE"
                    },
                    Server_Resource_Unit = new Server_Resource_Unit()
                    {
                        Id = 0, Unit = "%", ShortName = "PRCENT"
                    }
                };

                return(Ok(lastCalculatedCpuUsage));
            }
            catch (Exception e)
            {
                //return request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var topHelper     = new TopProcessHelper();
            var sensorsHelper = new SensorsProcessHelper();

            while (true)
            {
                var sampling_time    = DateTime.Now;
                var usage_info       = topHelper.GetCurrentTopProcessReadings();
                var temperature_info = sensorsHelper.GetCurrentSensorsProcessReadings();
                ManageNewData(usage_info, temperature_info, sampling_time);
                ManageOldData(sampling_time);
                Thread.Sleep(60000
                             );
            }
        }