zoukankan      html  css  js  c++  java
  • .net 获取CPU频率 内存 磁盘大小,域名 端口 虚拟目录等

    CPU个数: @Environment.GetEnvironmentVariable("NUMBER_OF_PROCESSORS")

    CPU类型: @Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")

    CPU频率: @ViewBag.CPUGHZ

    服务器内存大小: @ViewBag.TotalMemory

    服务器磁盘大小: @ViewBag.TotalDisk

    虚拟目录绝对路径: @Request.ServerVariables["APPL_PHYSICAL_PATH"]

    执行文件绝对路径: @Request.ServerVariables["PATH_TRANSLATED"]

    虚拟目录Session总数: @Session.Contents.Count

      /// <summary>
            /// 获取CPU频率
            /// </summary>
            /// <returns></returns>
            public string GetCpuGHZ()
            {
                ManagementClass mc = new ManagementClass("Win32_Processor");
                ManagementObjectCollection cpus = mc.GetInstances();
    
                string str = "";
                string[] mHz = new string[cpus.Count];
                int c = 0;
                ManagementObjectSearcher mySearch = new ManagementObjectSearcher("select * from Win32_Processor");
                foreach (ManagementObject mo in mySearch.Get())
                {
                    double temp = Convert.ToInt64(mo.Properties["CurrentClockSpeed"].Value);
                    mHz[c] = temp.ToString();
                    str += (temp/1000).ToString("0.00") + "GHz,";
                    c++;        
                }
                mc.Dispose();
                mySearch.Dispose();
                // return mHz;
                return str.TrimEnd(',');
            }
    
    
            /// <summary>
            /// 获取内存大小
            /// </summary>
            /// <returns></returns>
            public string GetTotalPhysicalMemory()
            {
                try
                {
                    string st = " ";
                    ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
                    ManagementObjectCollection moc = mc.GetInstances();
                    foreach (ManagementObject mo in moc)
                    {
                        st = mo["TotalPhysicalMemory"].ToString();
                    }
                    moc = null;
                    mc = null;
                    return st;
                }
                catch
                {
                    return "0";
                }
                finally
                {
                }
            }
    
            /// <summary>
            /// 硬盘大小
            /// </summary>
            /// <returns></returns>
            public string GetSizeOfDisk()
            {
                ManagementClass mc = new ManagementClass("Win32_DiskDrive");
                ManagementObjectCollection moj = mc.GetInstances();
                foreach (ManagementObject m in moj)
                {
                    return m.Properties["Size"].Value.ToString();
                }
                return "0";
            }

    比较全的获取服务器信息:

    https://www.cnblogs.com/tylerdonet/archive/2013/04/07/3006278.html

    比较全的Request 用法:

    https://www.cnblogs.com/mazhenyu/p/9468441.html

  • 相关阅读:
    postgresql批量删除表
    Oracle迁移至PostgreSQL工具之Ora2Pg
    postgresql获取表最后更新时间(通过发布订阅机制将消息发送给应用程序)
    postgresql获取表最后更新时间(通过表磁盘存储文件时间)
    postgresql获取表最后更新时间(通过触发器将时间写入另外一张表)
    postgresql源码编译安装(centos)
    Java 学习笔记(7)——接口与多态
    Java 学习笔记(6)——继承
    Java 学习笔记(4)——java 常见类
    Java 学习笔记(4)——面向对象
  • 原文地址:https://www.cnblogs.com/fuqiang88/p/11593767.html
Copyright © 2011-2022 走看看