Esempio n. 1
0
        private MemoryMetrics GetUnixMetrics()
        {
            var 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);
        }
Esempio n. 2
0
        private MemoryMetrics GetWindowsMetrics()
        {
            var 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);
        }