lscpu
Get CPU Architecture information in ruby.
linux manual
Basic Usage
require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])
result = host.lscpu
result.success?
true
result.architecture
'x86_64'
result.cores
1
result.hypervisor_vendor
'KVM'
result.byte_order
'Little Endian'
Result
Returns CPUArchitecture
struct. Has array of CPUArchitectureVulnerability
structs for possible vulnerabilities with the CPU like specter and meltdown.
CPUArchitecture Fields
Field | Type | Description |
---|---|---|
architecture |
string
|
CPU Architecture. |
operation_modes |
array
|
Which operation modes are supported (32 bit and 64 bit). |
byte_order |
string
|
Little / Big endian ordering, ie the order in which bytes are arranged in memory. |
cores |
integer
|
Number of logical CPUs as seen by the operating system. |
address_sizes |
array
|
Number of physical addressl ines the CPU has, and the virtual address space a single program can address. |
online_cpus |
integer
|
Number of cpus that are online and functioning |
threads_per_core |
integer
|
Indicates if hyperthreading is turned on or off. If number is greater than 1, this indicates this is turned on. |
cores_per_socket |
integer
|
Number of physical cores for a single CPU socket. |
sockets |
integer
|
Number of physical CPU slots on a motherboard. |
vendor_id |
string
|
Name of the vendor |
cpu_family |
integer
|
Processor family value. |
model |
integer
|
Numeric model number for a CPU family. |
model_name |
string
|
Name of the cpu model. |
stepping |
integer
|
Version number of the CPU used in the manufacturing process. |
cpu_mhz |
double
|
Clock speed of processor. |
cpu_max_mhz |
double
|
Max threshold of clock speed for processor. |
cpu_min_mhz |
double
|
Min threshold of clock speed for processor. |
bogo_mips |
double
|
The number of million times per second a processor can do absolutely nothing. |
virtualization |
string
|
Which virtualization mode is supported for the CPU. |
hypervisor_vendor |
string
|
The name of the vendor providing the virtualized CPU. |
virtualization_type |
string
|
What type of virtualization mode is the CPU in. |
l1d_cache |
string
|
Size of L1d cache. |
l1i_cache |
string
|
Size of L1i cache. |
l2_cache |
string
|
Size of L2 cache. |
l3_cache |
string
|
Size of L3 cache. |
numa_nodes |
integer
|
Represents the memory architecture for each socket. |
vulnerabilities |
array
|
Array of CPUArchitectureVulnerability for the CPU. |
flags |
array
|
Features that the CPU supports. |
CPUArchitectureVulnerability Fields
Field | Type | Description |
---|---|---|
name |
string
|
Name of the vulnerability |
data |
string
|
Description of what could be impacted |
Return Example
## Metal
host.lscpu.data
#<Struct:Kanrisuru::Core::System::CPUArchitecture:0x000005a0
address_sizes = [
"46 bits physical",
"48 bits virtual"
],
architecture = "x86_64",
bogo_mips = nil,
byte_order = "Little Endian",
cores = 48,
cores_per_socket = 12,
cpu_family = 6,
cpu_max_mhz = 3300.0,
cpu_mhz = 1250.366,
cpu_min_mhz = 1200.0,
flags = [
"fpu",
"vme",
"de",
[ 3] .. [103],
"pts",
"md_clear",
"flush_l1d"
],
hypervisor_vendor = nil,
l1d_cache = "768 KiB",
l1i_cache = "768 KiB",
l2_cache = "6 MiB",
l3_cache = "60 MiB",
model = 63,
model_name = "Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz",
numa_mode = nil,
numa_nodes = 2,
online_cpus = 0,
operation_modes = [
"32-bit",
"64-bit"
],
sockets = 2,
stepping = 2,
threads_per_core = 2,
vendor_id = "GenuineIntel",
virtualization = "VT-x",
virtualization_type = nil,
vulnerabilities = [
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00001928
data = "KVM: Mitigation: Split huge pages",
name = "Itlb multihit"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x000019a0
data = "Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable",
name = "L1tf"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00001a18
data = "Mitigation; Clear CPU buffers; SMT vulnerable",
name = "Mds"
>,
[3] .. [5],
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00001bf8
data = "Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling",
name = "Spectre v2"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00001c70
data = "Not affected",
name = "Srbds"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00001ce8
data = "Not affected",
name = "Tsx async abort"
>
]
>
## Virtual Machine
host.lscpu.data
#<Struct:Kanrisuru::Core::System::CPUArchitecture:0x00003598
address_sizes = [
"40 bits physical",
"48 bits virtual"
],
architecture = "x86_64",
bogo_mips = nil,
byte_order = "Little Endian",
cores = 1,
cores_per_socket = 1,
cpu_family = 6,
cpu_max_mhz = nil,
cpu_mhz = 2499.996,
cpu_min_mhz = nil,
flags = [
"fpu",
"vme",
"de",
[ 3] .. [77],
"umip",
"md_clear",
"arch_capabilities"
],
hypervisor_vendor = "KVM",
l1d_cache = "32 KiB",
l1i_cache = "32 KiB",
l2_cache = "4 MiB",
l3_cache = "16 MiB",
model = 60,
model_name = "Intel Core Processor (Haswell, no TSX, IBRS)",
numa_mode = nil,
numa_nodes = 1,
online_cpus = 0,
operation_modes = [
"32-bit",
"64-bit"
],
sockets = 1,
stepping = 1,
threads_per_core = 1,
vendor_id = "GenuineIntel",
virtualization = "VT-x",
virtualization_type = "full",
vulnerabilities = [
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00004560
data = "Not affected",
name = "Itlb multihit"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x000045d8
data = "Mitigation; PTE Inversion; VMX flush not necessary, SMT disabled",
name = "L1tf"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00004650
data = "Mitigation; Clear CPU buffers; SMT Host state unknown",
name = "Mds"
>,
[3] .. [5],
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00004830
data = "Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP disabled, RSB filling",
name = "Spectre v2"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x000048a8
data = "Unknown: Dependent on hypervisor status",
name = "Srbds"
>,
#<Struct:Kanrisuru::Core::System::CPUArchitectureVulnerability:0x00004920
data = "Not affected",
name = "Tsx async abort"
>
]
>
Exit Status
Code | Description |
---|---|
0 | Success |
1 | Failure |
Tested On
- Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES