Exemplo n.º 1
0
        /// <summary>
        /// 获取内存使用信息
        /// </summary>
        /// <returns></returns>
        public MemoryMetrics GetMetrics()
        {
            string output = ShellHelper.Bash("free -m");

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

            var metrics = new MemoryMetrics();

            metrics.RAMTotal = double.Parse(memory[1]);
            metrics.RAMUsed  = double.Parse(memory[2]);
            metrics.RAMFree  = double.Parse(memory[3]);
            metrics.RAMRate  = Math.Ceiling(100 * metrics.RAMUsed / metrics.RAMTotal);
            return(metrics);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取内存使用信息
        /// </summary>
        /// <returns></returns>
        public MemoryMetrics GetMetrics()
        {
            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.RAMTotal = Math.Round(double.Parse(totalMemoryParts[1]) / 1024, 0);
            metrics.RAMFree  = Math.Round(double.Parse(freeMemoryParts[1]) / 1024, 0);
            metrics.RAMUsed  = metrics.RAMTotal - metrics.RAMFree;
            metrics.RAMRate  = Math.Ceiling(100 * metrics.RAMUsed / metrics.RAMTotal);
            return(metrics);
        }