Пример #1
0
 static void InsertProcessSpecificUsage(TopProcessOutput usage_info)
 {
     foreach (var proc_info in usage_info.ProcessesSpecificUsage)
     {
         if (proc_info.Status == "R")
         {
             InsertProcess(proc_info);
             using (var context = new ServerResourcesContext())
             {
                 context.Server_Resource_Info.Add(new Server_Resource_Info()
                 {
                     Value                   = proc_info.CpuUsage,
                     Sample_Time_FK          = context.Sample_Time.Last().Id,
                     Server_Resource_Unit_FK = context.Server_Resource_Unit.Where(SRU => SRU.ShortName == "PRCENT").SingleOrDefault().Id,
                     Process_FK              = context.Process.Where(P => P.PID == proc_info.Pid).SingleOrDefault().Id,
                     Resource_Type_FK        = context.Resource_Type.Where(RT => RT.Short_Name == "CPU_USE").SingleOrDefault().Id
                 });
                 context.Server_Resource_Info.Add(new Server_Resource_Info()
                 {
                     Value                   = proc_info.RamUsage,
                     Sample_Time_FK          = context.Sample_Time.Last().Id,
                     Server_Resource_Unit_FK = context.Server_Resource_Unit.Where(SRU => SRU.ShortName == "PRCENT").SingleOrDefault().Id,
                     Process_FK              = context.Process.Where(P => P.PID == proc_info.Pid).SingleOrDefault().Id,
                     Resource_Type_FK        = context.Resource_Type.Where(RT => RT.Short_Name == "RAM_USE").SingleOrDefault().Id
                 });
                 context.SaveChanges();
             }
         }
     }
 }
Пример #2
0
 static void ManageNewData(TopProcessOutput usage_info, SensorsProcessOutput temperature_info, DateTime samplingTime)
 {
     InsertSamplingTime(samplingTime);
     InsertTemperature(temperature_info);
     InsertTotalUsages(usage_info);
     InsertProcessSpecificUsage(usage_info);
 }
Пример #3
0
        public TopProcessOutput GetCurrentTopProcessReadings()
        {
            var output = new TopProcessOutput()
            {
                ProcessesSpecificUsage = new HashSet <ProcessInformation>(),
                TotalCpuUsage          = 0,
                TotalRamUsage          = 0
            };

            using (var top_process = Process.Start(_topProcessStartInfo))
            {
                var    stream = top_process.StandardOutput;
                string line   = null;
                Regex  reg    = new Regex(@"\s+", RegexOptions.Compiled);


                for (int i = 0; i < 15; i++)
                {
                    line = stream.ReadLine();
                    line = line.Trim();
                    line = reg.Replace(line, ";");
                    if (i >= 6)
                    {
                        int   checkDigit;
                        Regex reg2 = new Regex(";", RegexOptions.Compiled);
                        if (!int.TryParse(line.Substring(0, 1), out checkDigit))
                        {
                            line = reg2.Replace(line, "", 1, 0);
                        }
                    }
                    var array_line = line.Split(";");


                    if (i > 6) //process lines
                    {
                        var process = new ProcessInformation()
                        {
                            Pid      = int.Parse(array_line[0]),
                            User     = array_line[1],
                            Status   = array_line[7],
                            CpuUsage = double.Parse(array_line[8]),
                            RamUsage = double.Parse(array_line[9]),
                            Name     = array_line[11]
                        };
                        output.ProcessesSpecificUsage.Add(process);
                        output.TotalCpuUsage += process.CpuUsage;
                        output.TotalRamUsage += process.RamUsage;
                    }
                }
            }

            return(output);
        }
Пример #4
0
 static void InsertTotalUsages(TopProcessOutput usage_info)
 {
     using (var context = new ServerResourcesContext())
     {
         context.Server_Resource_Info.Add(new Server_Resource_Info()
         {
             Value                   = usage_info.TotalCpuUsage,
             Sample_Time_FK          = context.Sample_Time.Last().Id,
             Server_Resource_Unit_FK = context.Server_Resource_Unit.Where(SRU => SRU.ShortName == "PRCENT").SingleOrDefault().Id,
             Process_FK              = null,
             Resource_Type_FK        = context.Resource_Type.Where(RT => RT.Short_Name == "CPU_USE").SingleOrDefault().Id
         });
         context.Server_Resource_Info.Add(new Server_Resource_Info()
         {
             Value                   = usage_info.TotalRamUsage,
             Sample_Time_FK          = context.Sample_Time.Last().Id,
             Server_Resource_Unit_FK = context.Server_Resource_Unit.Where(SRU => SRU.ShortName == "PRCENT").SingleOrDefault().Id,
             Process_FK              = null,
             Resource_Type_FK        = context.Resource_Type.Where(RT => RT.Short_Name == "RAM_USE").SingleOrDefault().Id
         });
         context.SaveChanges();
     }
 }