.NET Core 获取系统平台环境信息、进程信息


.NET Core 中没有获取 Linux 的 CPU使用率等信息的功能,死心吧。

        static void Main(string[] args)
            var proc = Process.GetCurrentProcess();
            var mem = proc.WorkingSet64;
            var cpu = proc.TotalProcessorTime;
                mem / 1024.0, cpu.TotalMilliseconds);
            Console.WriteLine($"当前进程物理内存量:kb { Environment.WorkingSet / 1204}");

            Console.WriteLine("运行框架:" + RuntimeInformation.FrameworkDescription);
            Console.WriteLine("操作系统:" + RuntimeInformation.OSDescription);
            Console.WriteLine("操作系统版本:" + Environment.OSVersion.ToString());
            Console.WriteLine("平台架构:" + RuntimeInformation.OSArchitecture);

            Console.WriteLine("-- 运行环境 --");

            //  <-- Keep this information secure! -->
            Console.WriteLine("机器名称: " + Environment.MachineName);
            Console.WriteLine("用户网络域名:" + Environment.UserDomainName);
            //  <-- Keep this information secure! -->
            string[] drives = Environment.GetLogicalDrives();
            Console.WriteLine("分区磁盘: {0}", String.Join(", ", drives));
            Console.WriteLine("系统目录:" + Environment.SystemDirectory);

            Console.WriteLine("系统已运行时间(毫秒):" + Environment.TickCount);

            //  <-- Keep this information secure! -->

            Console.WriteLine("是否在交互模式中运行:" + Environment.UserInteractive);

            //  <-- Keep this information secure! -->
            Console.WriteLine("当前关联用户名:" + Environment.UserName);

            Console.WriteLine("Web程序核心框架版本:" + Environment.Version.ToString());

            string querySystemDrive = "系统盘位置:%SystemDrive%";
            string querySystemRoot = "系统根目录:%SystemRoot%";

            Console.WriteLine("\n系统变量列表: ");
            IDictionary environmentVariables = Environment.GetEnvironmentVariables();
            foreach (DictionaryEntry de in environmentVariables)
                Console.WriteLine("  {0} = {1}", de.Key, de.Value);

  1. generic sinequan说道:

    I precisely desired to say thanks again. I'm not certain the things I could possibly have carried out in the absence of the concepts contributed by you about my area of interest. Entirely was a daunting circumstance for me, but coming across a expert avenue you dealt with it forced me to cry for contentment. I'm grateful for the assistance and expect you are aware of a powerful job that you are accomplishing educating many people by way of a site. I am certain you've never come across all of us.


邮箱地址不会被公开。 必填项已用*标注

You must enable javascript to see captcha here!