Ejemplo n.º 1
0
        private MemoryMetrics GetUnixMetrics()
        {
            string output = ShellHelper.Bash("free -m");

            var lines  = output.Split("\n");
            var memory = lines[1].Split(" ", StringSplitOptions.RemoveEmptyEntries);

            var metrics = new MemoryMetrics();

            metrics.Total = double.Parse(memory[1]);
            metrics.Used  = double.Parse(memory[2]);
            metrics.Free  = double.Parse(memory[3]);

            return(metrics);
        }
Ejemplo n.º 2
0
        private MemoryMetrics GetWindowsMetrics()
        {
            string output = ShellHelper.Cmd("wmic", "OS get FreePhysicalMemory,TotalVisibleMemorySize /Value");

            var lines            = output.Trim().Split("\n");
            var freeMemoryParts  = lines[0].Split("=", StringSplitOptions.RemoveEmptyEntries);
            var totalMemoryParts = lines[1].Split("=", StringSplitOptions.RemoveEmptyEntries);

            var metrics = new MemoryMetrics();

            metrics.Total = Math.Round(double.Parse(totalMemoryParts[1]) / 1024, 0);
            metrics.Free  = Math.Round(double.Parse(freeMemoryParts[1]) / 1024, 0);
            metrics.Used  = metrics.Total - metrics.Free;

            return(metrics);
        }
Ejemplo n.º 3
0
        public static ComputerInfo GetComputerInfo()
        {
            ComputerInfo computerInfo = new ComputerInfo();

            try
            {
                MemoryMetricsClient client        = new MemoryMetricsClient();
                MemoryMetrics       memoryMetrics = client.GetMetrics();
                computerInfo.TotalRAM = Math.Ceiling(memoryMetrics.Total / 1024).ToString() + " GB";
                computerInfo.RAMRate  = Math.Ceiling(100 * memoryMetrics.Used / memoryMetrics.Total).ToString() + " %";
                computerInfo.CPURate  = Math.Ceiling(GetCPURate().ParseToDouble()) + " %";
            }
            catch (Exception ex)
            {
                LogHelper.WriteWithTime(ex);
            }
            return(computerInfo);
        }