git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/sysinfo/sysinfo.go (about)

     1  // Copyright © 2016 Zlatko Čalušić
     2  //
     3  // Use of this source code is governed by an MIT-style license that can be found in the LICENSE file.
     4  
     5  // Package sysinfo is a Go library providing Linux OS / kernel / hardware system information.
     6  package sysinfo
     7  
     8  // SysInfo struct encapsulates all other information structs.
     9  type SysInfo struct {
    10  	Meta    Meta            `json:"sysinfo"`
    11  	Node    Node            `json:"node"`
    12  	OS      OS              `json:"os"`
    13  	Kernel  Kernel          `json:"kernel"`
    14  	Product Product         `json:"product"`
    15  	Board   Board           `json:"board"`
    16  	Chassis Chassis         `json:"chassis"`
    17  	BIOS    BIOS            `json:"bios"`
    18  	CPU     CPU             `json:"cpu"`
    19  	Memory  Memory          `json:"memory"`
    20  	Storage []StorageDevice `json:"storage,omitempty"`
    21  	Network []NetworkDevice `json:"network,omitempty"`
    22  }
    23  
    24  // GetSysInfo gathers all available system information.
    25  func (si *SysInfo) GetSysInfo() {
    26  	// Meta info
    27  	si.getMetaInfo()
    28  
    29  	// DMI info
    30  	si.getProductInfo()
    31  	si.getBoardInfo()
    32  	si.getChassisInfo()
    33  	si.getBIOSInfo()
    34  
    35  	// SMBIOS info
    36  	si.getMemoryInfo()
    37  
    38  	// Node info
    39  	si.getNodeInfo() // depends on BIOS info
    40  
    41  	// Hardware info
    42  	si.getCPUInfo() // depends on Node info
    43  	si.getStorageInfo()
    44  	si.getNetworkInfo()
    45  
    46  	// Software info
    47  	si.getOSInfo()
    48  	si.getKernelInfo()
    49  }
    50  
    51  func GetOS() OS {
    52  	var si SysInfo
    53  	si.getOSInfo()
    54  	return si.OS
    55  }