예제 #1
0
        private Task <MemoryMetrics> WindowsMetricsAsync()
        {
            var processInfo = new ProcessStartInfo
            {
                FileName  = "wmic",
                Arguments = "OS get FreePhysicalMemory, TotalVisibleMemorySize /Value",
                RedirectStandardOutput = true
            };

            using var process = Process.Start(processInfo);
            var output = process.StandardOutput.ReadToEnd();

            var lines = output.Trim().Split("\n");

            var metrics = new Domain.MemoryMetrics()
            {
                Free  = double.Parse(lines[0].Split("=", StringSplitOptions.RemoveEmptyEntries)[1]) * 1024,
                Total = double.Parse(lines[1].Split("=", StringSplitOptions.RemoveEmptyEntries)[1]) * 1024
            };

            return(Task.FromResult(metrics));
        }
예제 #2
0
        private Task <MemoryMetrics> LinuxMetricsAsync()
        {
            var processInfo = new ProcessStartInfo("free -m")
            {
                FileName  = "/bin/bash",
                Arguments = "-c \"free -m\"",
                RedirectStandardOutput = true
            };

            using var process = Process.Start(processInfo);
            var output = process.StandardOutput.ReadToEnd();

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

            var metrics = new Domain.MemoryMetrics()
            {
                Total = double.Parse(memory[1]),
                Free  = double.Parse(memory[3])
            };

            return(Task.FromResult(metrics));
        }