/// <summary> /// 获取CPU使用率 % /// </summary> /// <returns></returns> public static float CPULoad() { var br = CmdTo.Shell("vmstat 1 2"); var cpuitems = br.Output.Split(Environment.NewLine.ToCharArray()).LastOrDefault().Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); var us = cpuitems[cpuitems.Count - 5]; return(float.Parse(us)); }
/// <summary> /// 获取处理器名称 /// </summary> /// <returns></returns> public static string ProcessorName() { var cmd = "wmic cpu get name"; var cr = CmdTo.Run(cmd).TrimEnd(Environment.NewLine.ToCharArray()); var pvalue = cr.Split(Environment.NewLine.ToCharArray()).LastOrDefault(); return(pvalue); }
/// <summary> /// 运行时长 /// </summary> /// <returns></returns> public static long RunTime() { var cmd = "net statistics WORKSTATION"; var cr = CmdTo.Run(cmd).Split(Environment.NewLine.ToCharArray())[14].Split(' ').ToList(); while (!"1234567890".Contains(cr.First()[0])) { cr.RemoveAt(0); } DateTime.TryParse(string.Join(" ", cr), out DateTime startTime); var pvalue = Convert.ToInt64((DateTime.Now - startTime).TotalMilliseconds); return(pvalue); }
/// <summary> /// 获取磁盘信息 /// </summary> /// <returns></returns> public static List <object> LogicalDisk() { var listld = new List <object>(); var dfresult = CmdTo.Shell("df"); var listdev = dfresult.Output.Split(Environment.NewLine.ToCharArray()).Where(x => x.StartsWith("/dev/")); foreach (var devitem in listdev) { var dis = devitem.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList(); listld.Add(new { Name = dis[0], Size = long.Parse(dis[1]) * 1024, FreeSpace = long.Parse(dis[3]) * 1024 }); } return(listld); }