62 lines
1.5 KiB
Bash
62 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
get_cpu_model() {
|
|
awk -F: '
|
|
$1 ~ /^model name[[:space:]]*$/ {
|
|
value = $2
|
|
sub(/^[[:space:]]*/, "", value)
|
|
print value
|
|
exit
|
|
}
|
|
' /proc/cpuinfo
|
|
}
|
|
|
|
get_cpu_count() {
|
|
getconf _NPROCESSORS_ONLN
|
|
}
|
|
|
|
get_memory_bytes() {
|
|
awk '
|
|
$1 == "MemTotal:" {
|
|
print $2 * 1024
|
|
exit
|
|
}
|
|
' /proc/meminfo
|
|
}
|
|
|
|
build_storage_devices_json() {
|
|
lsblk \
|
|
--bytes \
|
|
--json \
|
|
--nodeps \
|
|
--output NAME,TYPE,MODEL,SERIAL,SIZE,TRAN |
|
|
jq '
|
|
[
|
|
.blockdevices[]
|
|
| select(.type == "disk")
|
|
| {
|
|
name: .name,
|
|
model: (
|
|
if .model == null or .model == ""
|
|
then null
|
|
else (.model | gsub("^[[:space:]]+|[[:space:]]+$"; ""))
|
|
end
|
|
),
|
|
serial: (
|
|
if .serial == null or .serial == ""
|
|
then null
|
|
else (.serial | gsub("^[[:space:]]+|[[:space:]]+$"; ""))
|
|
end
|
|
),
|
|
size_bytes: .size,
|
|
transport: (
|
|
if .tran == null or .tran == ""
|
|
then null
|
|
else .tran
|
|
end
|
|
)
|
|
}
|
|
]
|
|
'
|
|
}
|