-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathdmirow
executable file
·78 lines (66 loc) · 3.5 KB
/
dmirow
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Collect Linux server info you can only grab as root, mostly DMI.
# This is not pretty or robust, it's bootstrapping until I can do better.
source ./config
RESULTUSER="gsmith"
RESULTPSQL="psql -h $RESULTHOST -U $RESULTUSER -p $RESULTPORT -d $RESULTDB"
SERVERNAME=`hostname`
OS=`uname`
OS_REL=`uname -mrs`
if [ "$OS" = "Linux" ] ; then
CPU=`more /proc/cpuinfo | grep "^model name" | head -n 1 | cut -d: -f 2`
BOARDVENDOR=`sudo dmidecode | grep -A 1 "Base Board" | grep "Manufacturer:" | cut -d: -f 2`
BOARD=`sudo dmidecode | grep -A 2 "Base Board" | grep "Product Name:" | cut -d: -f 2`
PROCS=`cat /proc/cpuinfo | grep ^processor | wc -l`
MEMVENDOR=`sudo dmidecode -t memory | grep "Manufacturer:" | sort | uniq | head -n 1 | cut -d: -f2`
MEMTYPE=`sudo dmidecode -t memory | grep "Type:" | cut -d: -f 2 | grep -v "None" | sort | uniq | head -n 1`
MEMSPEED=`sudo dmidecode -t memory | grep "Speed:" | sort | uniq | head -n 1 | cut -d: -f2`
MEMPART=`sudo dmidecode -t memory | grep "Part Number" | head -n 1 | cut -d" " -f3`
# TODO Handle more than one entry in disklist
DISKMODEL=`sudo smartctl -i /dev/${DISKLIST} | egrep "^Model Number|^Device Model" | cut -d":" -f2`
DISKFW=`sudo smartctl -i /dev/${DISKLIST} | grep "^Firmware Version" | cut -d":" -f2`
DISKGB=`df -B1G | grep ${DISKLIST} | head -n 1 | awk '{print $4}'`
MEMGB=`free -h | grep "^Mem:" | awk '{print $2}'`
# Remove possible endings of G or Gi
MEMGB=${MEMGB%"Gi"}
MEMGB=${MEMGB%"G"}
DISTRIB_ID=`grep ^DISTRIB_ID /etc/lsb-release | cut -d"=" -f 2`
DISTRIB_REL=`grep ^DISTRIB_RELEASE /etc/lsb-release | cut -d"=" -f 2`
DISTRIB="$DISTRIB_ID $DISTRIB_REL"
elif [ "$OS" = "Darwin" ] ; then
BOARDVENDOR=`system_profiler SPHardwareDataType | grep "Model Name:" | cut -d":" -f 2`
BOARD=`system_profiler SPHardwareDataType | grep "Model Identifier:" | cut -d":" -f 2`
CPU=`sysctl machdep.cpu.brand_string | cut -d" " -f 2-`
PROCS=`sysctl hw.ncpu | cut -d" " -f 2`
MEMGB=`sysctl hw.memsize | awk '{print $2 / 1024 / 1024 / 1024}'`
MEMSPEED=`system_profiler SPMemoryDataType | grep "Speed:" | head -n 1 | awk '{print $2}'`
MEMTYPE=`system_profiler SPMemoryDataType | grep "Type:" | head -n 1 | awk '{print $2}'`
MEMVENDOR=`system_profiler SPMemoryDataType | grep "Manufacturer:" | head -n 1 | cut -d":" -f 2`
# Memory part number is often "-", save it regardless.
MEMPART=`system_profiler SPMemoryDataType | grep "Part Number:" | head -n 1 | cut -d":" -f 2`
DISKMODEL=`system_profiler SPStorageDataType | grep "Device Name:" | head -n 1 | cut -d":" -f 2`
DISKGB=`df -g | grep ${DISKLIST} | head -n 1 | awk '{print $2}'`
# There doesn't seem to be a way to get at disk firmware on Darwin.
# Use the volume type, like "AppleAPFSMedia", instead.
DISKFW=`system_profiler SPStorageDataType | grep "Media Name:" | head -n 1 | cut -d":" -f 2`
DISTRIB=`sw_vers | cut -d":" -f 2 | xargs echo`
else
echo Unsupported OS: $OS
exit 1
fi
$RESULTPSQL -c "DELETE FROM server WHERE server='${SERVERNAME}'"
$RESULTPSQL -c "
INSERT INTO server
(server,server_info,server_cpu,server_mem,server_disk,
server_num_proc,server_mem_gb,server_disk_gb,server_os_release)
VALUES
(
TRIM('${SERVERNAME}'),
TRIM('${BOARDVENDOR}') || ' - ' || TRIM('${BOARD}'),
TRIM('${CPU}'),
TRIM('${MEMPART}') || ' - ' || TRIM('${MEMVENDOR}') || ' - ' || TRIM('${MEMTYPE}') || '-' || TRIM('${MEMSPEED}'),
TRIM('${DISKMODEL}') || ' - ' || TRIM('${DISKFW}'),
${PROCS},${MEMGB},${DISKGB},'${DISTRIB} ${OS_REL}'
);
"
$RESULTPSQL -x -c "SELECT * FROM server WHERE server='${SERVERNAME}'"