用C++和shell获取本机CPU.网卡.内存.磁盘等的基本信息: 由于对C++相关的函数没多少了解,但是觉得用shell反而相对简单一些: 一.shell脚本,用来辅助C++获取主机的资源使用信息 (1) cpurate.sh 获取cpu的使用率 #!/bin/sh ##echo user nice system idle iowait irq softirq CPULOG_1=$(cat /proc/stat | grep 'cpu ' | awk '{print $2" "$3&…
用 shell 获取本机的网卡名称 # 用 shell 获取本机的网卡名称 ls /sys/class/net # 或者 ifconfig | grep "Link" | awk '{print $1}' # 当前网卡的IP地址 ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' # 用 shell 获取当前IP的C类地址 sed 's/\.[0-9]*$/\.0\/24…
第三方包下载 $ github.com/shirou/gopsutil 获取内存方面的信息 package main import ( "fmt" "github.com/shirou/gopsutil/mem" ) func main() { v, _ := mem.VirtualMemory() fmt.Println(v) } total // 内存大小 available // 闲置可用内存 used // 已使用内存 usedPercent // 已使用百…
早上的时候接到主管的一个任务,要获取服务器上的cpu,硬盘, 数据库等 的使用情况,并以邮件的方式发给boss, = =没办法,公司的服务器真是不敢恭维,顺便吐槽一下公司的网速,卡的时候30k左右徘徊,这不是在浪费我们的时间吗!!! 话不多说上代码,因为是实习,主管还是挺关照我的,一早就给我发了个类库(里面涉及到要查询本机信息的都有).这样我剩下了一大半的时间, 这个功能总的来说就两步:  一,先获取本机的信息    二,发送邮件. 获取本机信息用到的类库 SystemInfo.cs 和 Dis…
Linux可用下top.ps命令检查当前的cpu.mem用法.下面简单的例子: 一.采用ps查看资源消耗的过程 ps -aux 当您查看进程信息,第三列是CPU入住. [root@localhost utx86]# ps -aux | grep my_process Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ root   14415  3.4  0.9   37436  20328 …
github地址:https://github.com/charygao/SmsComputerMonitor 软件用于实时监控当前系统资源等情况,并调用接口,当资源被超额占用时,发送警报到个人手机:界面模拟Console的显示方式,信息缓冲大小由配置决定:可以定制监控的资源,包括: cpu使用率: 内存使用率: 磁盘使用率: 网络使用率: 进程线程数: using System; using System.Collections.Generic; using System.Diagnostic…
using System; using System.Collections.Generic; using System.Management; using System.Runtime.InteropServices; using System.Text.RegularExpressions; namespace Splash.Util { public class NetworkAdapterInformation { public String PNPDeviceID; // 设备ID p…
首先引入服务 然后 调用 本文转载自http://blog.sina.com.cn/s/blog_7eeb43210101hf7f.html public class Computer { public static string CpuID; //1.cpu序列号 public static string MacAddress; //2.mac序列号 public static string DiskID; //3.硬盘id public static string IpAddress; //…
此功能参考了ProcessHacker项目的代码. 声明定义 typedef struct _UINT64_DELTA { ULONG64 Value; ULONG64 Delta; } UINT64_DELTA, *PUINT64_DELTA; typedef struct _UINTPTR_DELTA { ULONG_PTR Value; ULONG_PTR Delta; } UINTPTR_DELTA, *PUINTPTR_DELTA; #define InitializeDelta(Dl…
0 运行环境 本机系统:Windows 10 虚拟机软件:Oracle VM VirtualBox 6 虚拟机系统:Ubuntu 18 1 代码 #include <sys/ioctl.h> #include <net/if.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <stdio.h> int get_localIPAn…