Skip to content

Instantly share code, notes, and snippets.

@joshforbes
Last active November 30, 2020 21:48
Show Gist options
  • Save joshforbes/83e825976750bbeffc7bc890ed331a97 to your computer and use it in GitHub Desktop.
Save joshforbes/83e825976750bbeffc7bc890ed331a97 to your computer and use it in GitHub Desktop.

System Metrics

  • OS
  • OS Version
  • OS Architecture
  • Computer Name
  • Device Type (server or workstation, probably based on OS)
  • RAM
  • CPU
  • HD Sizes
  • Model
  • Manufacturer
  • Public IPv4
  • Private IPv4
  • Gateway
  • DNS
  • Subnet Mask
  • Last Seen
  • Last Logged In User
  • Last Reboot Time
  • System Uptime

OS + OS Version + Computer Name + Last Reboot Time + System Uptime + Device Type

// go-psutil
host.Info()

// Mac
{
  "hostname": "macbook-pro-2.lan", // Computer Name
  "uptime": 342925, // System Uptime
  "bootTime": 1585842869, // Last Reboot Time
  "procs": 526,
  "os": "darwin", // OS
  "platform": "darwin",
  "platformFamily": "Standalone Workstation", // Device Type
  "platformVersion": "10.15.3", // OS Version
  "kernelVersion": "19.3.0",
  "kernelArch": "x86_64",
  "virtualizationSystem": "",
  "virtualizationRole": "",
  "hostid": "a8dde75c-cd97-3c37-b35d-1070cc50d2ce"
}

// Windows
{
  "hostname": "DESKTOP-KIKDP63", // Computer Name
  "uptime": 2050723, // System Uptime
  "bootTime": 1584135243, // Last Reboot Time
  "procs": 168,
  "os": "windows", // OS
  "platform": "Microsoft Windows 10 Pro", // OS
  "platformFamily": "Standalone Workstation", // Device Type
  "platformVersion": "10.0.18362 Build 18362", // OS Version
  "kernelVersion": "",
  "kernelArch": "x86_64",
  "virtualizationSystem": "",
  "virtualizationRole": "",
  "hostid": "e0507b2b-eb3e-47cd-82ca-91f317241216"
}

// Ubuntu
{
   "hostname":"level-virtual-machine", // Computer Name
   "uptime":10211, // System Uptime
   "bootTime":1586194787, // Last Reboot Time
   "procs":342,
   "os":"linux", // OS
   "platform":"ubuntu", // OS
   "platformFamily":"debian",
   "platformVersion":"18.04", // OS Version
   "kernelVersion":"5.3.0-46-generic",
   "kernelArch":"x86_64",
   "virtualizationSystem":"",
   "virtualizationRole":"",
   "hostid":"f15a4a13-80a7-4540-a24e-0ad5a71ee5b4"
}

OS Architecture

// stdlib
runtime.GOARCH

amd64

RAM

// go-psutil
mem.VirtualMemory()

{
  "total": 34359738368, // RAM
  "available": 18029178880,
  "used": 16330559488,
  "usedPercent": 47.528183460235596,
  "free": 10042241024,
  "active": 10496745472,
  "inactive": 7986937856,
  "wired": 3364196352,
}

CPU

// go-psutil
cpu.Info()

[{
   “cpu”:0,
   "vendorId":"GenuineIntel",
   "family":"6",
   "model":"158",
   "stepping":10,
   "physicalId":"",
   "coreId":"",
   "cores":6,
   "modelName":"Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz",
   "mhz":2600,
   "cacheSize":256,
   “flags”:[*],
   "microcode":""
}]

HD Sizes

// go-psutil (works on windows too)
disk.Usage("/")

{
  "path": "/",
  "fstype": "",
  "total": 53009707008, // HD Size
  "free": 24934088704,
  "used": 28075618304,
  "usedPercent": 52.96316446299721,
  "inodesTotal": 0,
  "inodesUsed": 0,
  "inodesFree": 0,
  "inodesUsedPercent": 0
}

Public IPv4

// https://github.com/rdegges/go-ipify/blob/master/ipify.go
or 
// remote.request_ip on Rails API
or 
// https://ipv6.encryption.io/json
// https://ipv4.encryption.io/json

Private IPv4 + Subnet Mask

// stdlib
ifaces, _ := net.Interfaces()
for _, i := range ifaces {
  addrs, _ := i.Addrs()
  for _, a := range addrs {
    fmt.Println(a)
  }
}

192.168.86.234/24
172.16.42.40/32

Gateway

// github.com/jackpal/gateway
gateway.DiscoverGateway()

192.168.86.1 <nil>

DNS

??? Can’t figure this one out yet

Last Seen

I think this would be a timestamp of the last time the computer was online. Calculated by API.

Last Logged In User

// stdlib
user, _ := user.Current()
fmt.Println(user.Username)

forbes

Model + Manufacturer

// windows only cli command
c:\>wmic csproduct get vendor, version
Vendor  Version
LENOVO  ThinkPad T410
Other Resources
@jacobhaug
Copy link

  • IP Lookup: If we are going to use ipify, I'd rather self-host it. Otherwise, if we are looking for a service, I'd rather pay for IPStack. (https://api.ipstack.com/check?access_key=YOUR_ACCESS_KEY) IPStack is used by AirBNB, HubSpot, and Microsoft. The one I have on Encryption is echoip. (https://github.com/mpolden/echoip) If you like that one, I will deploy it on AWS for Level.

  • DNS: We can skip this one and do later.

Overall, looks great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment