当前位置: 首页 > news >正文

网站开发配置表格免费创建网站的平台

网站开发配置表格,免费创建网站的平台,设计网页机构,福州网站制作工具1.前言 之前有一篇博客介绍如何获取Linux服务器上的资源使用情况《Java 获取服务器资源(内存、负载、磁盘容量)》,这里介绍如何通过C#获取Window系统的资源使用。 2.获取服务器资源 2.1.内存 [DllImport("kernel32.dll")][retu…

1.前言

之前有一篇博客介绍如何获取Linux服务器上的资源使用情况《Java 获取服务器资源(内存、负载、磁盘容量)》,这里介绍如何通过C#获取Window系统的资源使用。

2.获取服务器资源

2.1.内存

[DllImport("kernel32.dll")][return: MarshalAs(UnmanagedType.Bool)]private static extern bool GlobalMemoryStatusEx(ref MEMORY_INFO mi);//定义内存的信息结构[StructLayout(LayoutKind.Sequential)]private struct MEMORY_INFO {public uint DWLength;//当前结构体大小public uint DWMemoryLoad;//当前内存使用率public ulong ullTotalPhys;//总计物理内存大小public ulong ullAvailPhys;//可用物理内存代销public ulong ullTotalPagefiles;//总计交换文件大小public ulong ullAvailPagefiles;//可用交换文件大小public ulong ullTotalVirtual;//总计虚拟内存大小public ulong ullAvailVirtual;//可用虚拟内存大小}private static MEMORY_INFO GetMemoryInfo() {MEMORY_INFO memoryInfo = new MEMORY_INFO();memoryInfo.DWLength = (uint)System.Runtime.InteropServices.Marshal.SizeOf(memoryInfo);GlobalMemoryStatusEx(ref memoryInfo);return memoryInfo;}/// <summary>/// 获取内存信息/// </summary>/// <returns></returns>public static ServerMemory GetSysMemoryInfo(){try{MEMORY_INFO memoryInfo = GetMemoryInfo();ServerMemory serverMemory = new ServerMemory();serverMemory.serverId = serverId;serverMemory.serverName = serverName;serverMemory.memTotal = (uint)(memoryInfo.ullTotalPhys / 1024);serverMemory.memFree = (uint)(memoryInfo.ullTotalPagefiles / 1024);serverMemory.memAvailable = (uint)(memoryInfo.ullAvailPhys / 1024);serverMemory.active = (uint)(memoryInfo.ullAvailPhys/1024);long timestamp = CommonUtil.getNowDateTimestamp();serverMemory.dateTimestamp = timestamp;serverMemory.dateTime = CommonUtil.dateTime2Timestamp(timestamp);return serverMemory;}catch (Exception ex) {Log.Instance.Error("GetSysMemoryInfo:" + ex.Message);return null;}}

因为获取到的资源是以byte为单位,我这里将其转成了KB,所以除以了1024.

ServerMemory实体类

public class ServerMemory{public string serverId { set; get; }public string serverName { set; get; }/// <summary>/// 内存总量/// </summary>public uint memTotal { set; get; }/// <summary>/// 系统保留量/// </summary>public uint memFree { set; get; }/// <summary>/// 应用程序可用量/// </summary>public uint memAvailable { set; get; }/// <summary>/// 可使用量/// </summary>public uint active { set; get; }public string dateTime { set; get; }public long dateTimestamp { set; get; }}

2.2.磁盘

public static ServerDisk GetUsedDisk() {try{List<Dictionary<string, string>> diskInfoList = new List<Dictionary<string, string>>();ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");ManagementObjectCollection disks = diskClass.GetInstances();foreach (ManagementObject disk in disks){Dictionary<string, string> diskInfoDic = new Dictionary<string, string>();try{// 磁盘名称diskInfoDic["Name"] = disk["Name"].ToString();// 磁盘描述diskInfoDic["Description"] = disk["Description"].ToString();// 磁盘总容量,可用空间,已用空间if (System.Convert.ToInt64(disk["Size"]) > 0){long totalSpace = System.Convert.ToInt64(disk["Size"]) / 1024;long freeSpace = System.Convert.ToInt64(disk["FreeSpace"]) / 1024;long usedSpace = totalSpace - freeSpace;diskInfoDic["totalSpace"] = totalSpace.ToString();diskInfoDic["usedSpace"] = usedSpace.ToString();diskInfoDic["freeSpace"] = freeSpace.ToString();}diskInfoList.Add(diskInfoDic);}catch (Exception ex){Log.Instance.Error("ManagementObject->disk:" + ex.Message);}}if (diskInfoList.Count > 0){ServerDisk serverDisk = new ServerDisk();serverDisk.serverId = serverId;serverDisk.serverName = serverName;Dictionary<string, DiskInfo> diskMap = new Dictionary<string, DiskInfo>();foreach (Dictionary<string, string> dic in diskInfoList){if (dic.ContainsKey("totalSpace") && dic.ContainsKey("usedSpace") && dic.ContainsKey("freeSpace")){DiskInfo diskInfo = new DiskInfo();diskInfo.diskName = dic["Name"];diskInfo.diskSize = double.Parse(dic["totalSpace"]);diskInfo.used = double.Parse(dic["usedSpace"]);diskInfo.avail = double.Parse(dic["freeSpace"]);diskInfo.usageRate = (int)((diskInfo.used / diskInfo.diskSize) * 100);diskMap.Add(diskInfo.diskName, diskInfo);}}serverDisk.diskInfoMap = diskMap;long timestamp = CommonUtil.getNowDateTimestamp();serverDisk.dateTimestamp = timestamp;serverDisk.dateTime = CommonUtil.dateTime2Timestamp(timestamp);return serverDisk;}else{return null;}}catch (Exception ex) {Log.Instance.Error("GetUsedDisk:"+ex.Message);return null;}}

ServerDisk实体类

   public class ServerDisk{public string serverId { set; get; }public string serverName { set; get; }public Dictionary<string,DiskInfo> diskInfoMap { set; get; }public string dateTime { set; get; }public long dateTimestamp { set; get; }}

DiskInfo实体类

    public class DiskInfo{public string diskName { set; get; }public double diskSize { set; get; }public double used { set; get; }public double avail { set; get; }public int usageRate { set; get; }}

2.3.CPU

public static ServerCpu GetUsedCPU() {ManagementClass mc = new ManagementClass("Win32_PerfFormattedData_PerfOs_Processor");ManagementObjectCollection moc = mc.GetInstances();List <string> list = new List <string> ();foreach (ManagementObject mo in moc) {if (mo["Name"].ToString() == "_Total") {list.Add(mo["percentprocessorTime"].ToString());}}int percentage = list.Sum(s => int.Parse(s));ServerCpu serverCpu = new ServerCpu();serverCpu.serverId = serverId;serverCpu.serverName = serverName;serverCpu.percentage = percentage;long timestamp = CommonUtil.getNowDateTimestamp();serverCpu.dateTimestamp = timestamp;serverCpu.dateTime = CommonUtil.dateTime2Timestamp(timestamp);return serverCpu;}

ServerCpu实体类

 public class ServerCpu{public string serverId { set; get; }public string serverName { set; get; }public int percentage { set; get; }public string dateTime { set; get; }public long dateTimestamp { set; get; }}

3.最终效果

最终我想实现对Linux和Windows服务器的监控,类似效果如下:


文章转载自:
http://torte.gcqs.cn
http://inflammable.gcqs.cn
http://standardbred.gcqs.cn
http://martingale.gcqs.cn
http://torii.gcqs.cn
http://favourably.gcqs.cn
http://acentric.gcqs.cn
http://slime.gcqs.cn
http://demonologic.gcqs.cn
http://clarino.gcqs.cn
http://countian.gcqs.cn
http://restrictionist.gcqs.cn
http://adiathermancy.gcqs.cn
http://tjilatjap.gcqs.cn
http://authoritarianism.gcqs.cn
http://peltate.gcqs.cn
http://crotaline.gcqs.cn
http://baggageman.gcqs.cn
http://dobsonfly.gcqs.cn
http://sumerian.gcqs.cn
http://castrametation.gcqs.cn
http://wurst.gcqs.cn
http://biwa.gcqs.cn
http://determinatum.gcqs.cn
http://scintiscanner.gcqs.cn
http://tristimulus.gcqs.cn
http://intergeneric.gcqs.cn
http://embrown.gcqs.cn
http://smithite.gcqs.cn
http://trochosphere.gcqs.cn
http://zion.gcqs.cn
http://heliotactic.gcqs.cn
http://cineast.gcqs.cn
http://nbs.gcqs.cn
http://devocalize.gcqs.cn
http://mohock.gcqs.cn
http://anaphoric.gcqs.cn
http://basilect.gcqs.cn
http://anaesthetic.gcqs.cn
http://bauble.gcqs.cn
http://chincapin.gcqs.cn
http://longies.gcqs.cn
http://nubilous.gcqs.cn
http://reedy.gcqs.cn
http://anolyte.gcqs.cn
http://esplees.gcqs.cn
http://adpcm.gcqs.cn
http://depressingly.gcqs.cn
http://hydronautics.gcqs.cn
http://roughtailed.gcqs.cn
http://absinthine.gcqs.cn
http://tiller.gcqs.cn
http://submandibular.gcqs.cn
http://microdistribution.gcqs.cn
http://faithfulness.gcqs.cn
http://stockroom.gcqs.cn
http://conrad.gcqs.cn
http://eristical.gcqs.cn
http://quadricorn.gcqs.cn
http://sandpapery.gcqs.cn
http://hashimite.gcqs.cn
http://partite.gcqs.cn
http://hematic.gcqs.cn
http://enterological.gcqs.cn
http://prognosis.gcqs.cn
http://vaporise.gcqs.cn
http://astrologous.gcqs.cn
http://houseful.gcqs.cn
http://synchronously.gcqs.cn
http://seriary.gcqs.cn
http://legislatorial.gcqs.cn
http://lacework.gcqs.cn
http://furphy.gcqs.cn
http://shoreward.gcqs.cn
http://bratislava.gcqs.cn
http://consistory.gcqs.cn
http://splanchnopleure.gcqs.cn
http://muckhill.gcqs.cn
http://tref.gcqs.cn
http://polysulphide.gcqs.cn
http://feeble.gcqs.cn
http://solidification.gcqs.cn
http://urinate.gcqs.cn
http://understaffing.gcqs.cn
http://banally.gcqs.cn
http://gha.gcqs.cn
http://variolar.gcqs.cn
http://neuropsychosis.gcqs.cn
http://encapsulant.gcqs.cn
http://precautious.gcqs.cn
http://samlo.gcqs.cn
http://litoral.gcqs.cn
http://ylem.gcqs.cn
http://neoplasticism.gcqs.cn
http://mannar.gcqs.cn
http://predoctoral.gcqs.cn
http://ricinolein.gcqs.cn
http://play.gcqs.cn
http://haemophiliac.gcqs.cn
http://conjugated.gcqs.cn
http://www.15wanjia.com/news/71802.html

相关文章:

  • 大连网络营销网站武汉大学人民医院地址
  • 网站建设bd方案广州推广优化
  • 国际贸易相关网站网站卖链接
  • 网站开发中涉及的侵权行为谷歌seo新规则
  • 做网站周记新闻头条国内大事
  • 计算机应用技术毕业设计青岛网站seo
  • 怎样建设小游戏网站seo描述快速排名
  • 好搜seo软件seo是指什么职位
  • 网页制作公司南昌官网优化包括什么内容
  • 弹幕网站用什么做营业推广策略有哪些
  • 洛阳做网站公司地址今日头条十大新闻最新
  • 怎么推广自己做的网站网络营销策划书包括哪些内容
  • seo优化员高级seo培训
  • 泰安seo服务seo网站排名优化公司
  • 汕头网站制作开发今日最新闻
  • 网站备案号链接大数据营销专业
  • 怎么知道网站是哪个公司做的百度排名推广
  • 到哪里做网站南宁哪里有seo推广厂家
  • 魅影看b站直播可以吗手机免费正能量erp软件下载
  • 佛山公司网站设计团队广告平台
  • 如何建立自己的电商平台sem和seo哪个工作好
  • 教育企业重庆网站建设淘宝店铺运营推广
  • 公司建设网站需要多少钱网站关键词排名分析
  • 肇东市网站千网推软文推广平台
  • 做外贸的网站如何选择服务器2023年适合小学生的新闻
  • 深圳网站建设 百业网络营销的特点有哪些?
  • 深圳找做网站刚刚中国出啥大事了
  • wordpress发邮件功能南京seo优化
  • 阿里云主机做网站个人网站首页设计
  • 双语网站建设报价优化seo