Last active
October 10, 2024 08:01
-
-
Save maurorappa/c1f316f25d8c1820c5acd3d0d0864cdd to your computer and use it in GitHub Desktop.
container for collecting server performance in a nice complete json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM gcc:11.2.0 as build | |
RUN apt update && apt install -y p7zip fio python3 g++ ipmitool groff-base dmidecode perl vim python3-pymongo && mkdir /hwtest | |
COPY . hwtest/ | |
RUN ln -s /usr/local/bin/gcc /usr/bin/gcc && mkdir /etc_phy /data | |
RUN cd /hwtest && g++ -O3 -DNDEBUG c2clat.cpp -o c2clat -pthread | |
RUN cd /hwtest && tar xf memtester-4.6.0.tar.gz && tar xf primegen-0.97.tar.gz && cp /hwtest/memtester.c /hwtest/memtester-4.6.0/ && cp /hwtest/primespeed.c /hwtest/primegen-0.97/ | |
RUN cd /hwtest/primegen-0.97/ && make && cp /hwtest/primegen-0.97/primespeed /bin/primespeed | |
RUN cd /hwtest/memtester-4.6.0/ && make && cp /hwtest/memtester-4.6.0/memtester /bin/memtester | |
RUN git clone https://github.com/cruvolo/ramspeed-smp.git && cd ramspeed-smp && echo |bash build.sh && cp ramsmp /bin/ramsmp | |
RUN git clone https://github.com/eembc/coremark-pro.git coremark-pro && cd coremark-pro && make TARGET=linux64 XCMD='-c4' all | |
RUN curl -o /bin/gobonniego -L https://github.com/cunnie/gobonniego/releases/download/1.0.9/gobonniego-linux-amd64 && chmod +x /bin/gobonniego | |
RUN curl -fsSL https://pgp.mongodb.com/server-6.0.asc | gpg -o /usr/share/keyrings/mongodb-server-6.0.gpg --dearmor && echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-6.0.gpg] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/6.0 main" | tee /etc/apt/sources.list.d/mongodb-org-6.0.list && apt update && apt install -y mongodb-org-tools mongodb-mongosh | |
CMD python3 hwtest/report.py | |
once built run: | |
podman run --privileged -v /dev/ipmi0:/dev/ipmi0 -v /etc:/etc_phy:ro -v /data:/data -v /var/tmp:/var/tmp -ti 7d902bbb7495 python3 hwtest/report.py -a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import re | |
import json | |
import datetime | |
import os | |
import sys | |
import getopt | |
import subprocess | |
import pymongo | |
def seven_zip(): | |
print("7zip") | |
result = subprocess.run(["7zr b -md22"], shell=True, capture_output=True, text=True) | |
# https://7-zip.opensource.jp/chm/cmdline/commands/bench.htm | |
# The R / U column shows the rating normalized for 100% of CPU usage. That column shows the performance of one average CPU thread. | |
avg = re.search('Avr\:(.*)',result.stdout).group(0) | |
avg = re.split('\s+',avg) | |
compress = avg[2] | |
decompress = avg[6] | |
return compress | |
def primespeed(): | |
print("primespeed") | |
result = subprocess.run(["/bin/primespeed"], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
avg = re.split('\s+',result.stdout) | |
speed = avg[1] | |
return speed | |
def memtester(): | |
print("memtester") | |
result = subprocess.run(["/bin/memtester 1G 1"], shell=True, capture_output=True, text=True) | |
elapsed = result.stderr | |
return elapsed.strip() | |
def ram_speed(): | |
print("ram speed") | |
result = subprocess.run(["/bin/ramsmp -l1 -b3"], shell=True, capture_output=True, text=True) | |
avg = re.search('INTEGER(.*)AVERAGE:(.*)',result.stdout).group(0) | |
avg = re.split('\s+',avg) | |
speed = avg[2] | |
return speed | |
def gobonniego(dir): | |
print("bonnie "+dir) | |
result = subprocess.run(["/bin/gobonniego -json -size 2 -dir " + dir], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
data = json.loads(result.stdout) | |
result = { | |
'write_mbps': data["results"][0]["write_megabytes_per_second"], | |
'read_mbps': data["results"][0]["read_megabytes_per_second"] | |
} | |
return result | |
def fio(dir): | |
print("fio "+dir) | |
# https://tobert.github.io/post/2014-04-17-fio-output-explained.html | |
result = subprocess.run(["fio --name=seqwrite --rw=write --direct=1 --ioengine=libaio --bs=4k --numjobs=1 --size=1G --runtime=600 --group_reporting --output-format=json --directory="+dir], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
data = json.loads(result.stdout) | |
result = { | |
'bw_mean': data["jobs"][0]["write"]["bw_mean"], | |
'completion_latency': data["jobs"][0]["write"]["clat_ns"]["mean"] | |
} | |
return result | |
def coremark_pro_livermore(cores): | |
print("coremark livermore") | |
# improved version of the Livermore loops benchmark | |
result = subprocess.run(["/coremark-pro/builds/linux64/gcc64/bin/loops-all-mid-10k-sp.exe -v0 -c" + cores], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
avg = re.search('workloads/sec(.*)',result.stdout).group(0) | |
avg = re.split('\s+',avg) | |
speed = avg[1] | |
return speed | |
def coremark_pro_radix2fft(): | |
print("coremark FFT") | |
# Radix-2 Fast Fourier Transform (FFT) | |
result = subprocess.run(["/coremark-pro/builds/linux64/gcc64/bin/radix2-big-64k.exe -v0 -c" + cores], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
avg = re.search('workloads/sec(.*)',result.stdout).group(0) | |
avg = re.split('\s+',avg) | |
speed = avg[1] | |
return speed | |
def coremark_pro_parser(power): | |
print("coremark parser") | |
# Radix-2 Fast Fourier Transform (FFT) | |
result = subprocess.run(["/coremark-pro/builds/linux64/gcc64/bin/parser-125k.exe -v0 -c" + cores], shell=True, capture_output=True, text=True) | |
avg = re.search('workloads/sec(.*)',result.stdout).group(0) | |
avg = re.split('\s+',avg) | |
watt = 0 | |
if power: | |
power = subprocess.run(["ipmitool dcmi power reading"], shell=True, capture_output=True, text=True) | |
out = re.search('Maximum(.*)',power.stdout).group(0) | |
out = re.split('\s+',out) | |
watt = out[4] | |
data = { | |
"speed": avg[1], | |
"server_power_usage": watt | |
} | |
return data | |
def openssl(): | |
print("openssl") | |
result = subprocess.run(["openssl speed md5 sha512"], shell=True, capture_output=True, text=True) | |
#print(result.stdout) | |
# we take the 64bytes block results | |
md5 = re.search('md5(.*)',result.stdout).group(0) | |
md5 = re.split('\s+',md5) | |
sha512 = re.search('sha512(.*)',result.stdout).group(0) | |
sha512 = re.split('\s+',sha512) | |
data = { | |
'md5_speed': md5[2], | |
'sha512_speed': sha512[2] | |
} | |
return data | |
def c2clat(): | |
print("c2clat") | |
result = subprocess.run(["/hwtest/c2clat -H"], shell=True, capture_output=True, text=True) | |
minmax = re.split(',', result.stdout[:-1]) | |
data = { | |
'max' : minmax[0], | |
'min' : minmax[1] | |
} | |
return data | |
def sw_info(): | |
version = subprocess.run(["cat /etc_phy/redhat-release"], shell=True, capture_output=True, text=True) | |
kernel = subprocess.run(["uname -a"], shell=True, capture_output=True, text=True) | |
kernel_arg = subprocess.run(["cat /proc/cmdline"], shell=True, capture_output=True, text=True) | |
tuned = subprocess.run(["cat /etc_phy/tuned/active_profile"], shell=True, capture_output=True, text=True) | |
host = subprocess.run(["cat /etc_phy/hostname"], shell=True, capture_output=True, text=True) | |
gcc = subprocess.run(["gcc -v"], shell=True, capture_output=True, text=True) | |
gcc_version = re.search('gcc version(.*)',gcc.stderr).group(0) | |
data = { | |
'release': (version.stdout).strip(), | |
'kernel': (kernel.stdout).strip(), | |
'kernel_arg': (kernel_arg.stdout).strip(), | |
'tuned': (tuned.stdout).strip(), | |
'gcc': gcc_version, | |
'host': host | |
} | |
return data | |
def hw_info(): | |
product = subprocess.run(["dmidecode -s system-product-name"], shell=True, capture_output=True, text=True) | |
bios = subprocess.run(["dmidecode -s bios-version"], shell=True, capture_output=True, text=True) | |
cpu = subprocess.run(["dmidecode -s processor-version"], shell=True, capture_output=True, text=True) | |
ram = subprocess.run(["grep MemTotal /proc/meminfo"], shell=True, capture_output=True, text=True) | |
ram = re.split('\s+',ram.stdout) | |
data = { | |
'product': (product.stdout).strip(), | |
'bios': (bios.stdout).strip(), | |
'cpu': (cpu.stdout).strip(), | |
'ram': (ram[1]).strip(), | |
'cores': cores | |
} | |
return data | |
date = datetime.datetime.now() | |
cores = str(os.cpu_count()) | |
args=sys.argv[1:] | |
all_tests = False | |
debug = False | |
mongo_insert = False | |
power = False | |
try: | |
opts, args = getopt.getopt(args,"mhadp") | |
except getopt.GetoptError: | |
print ('Usage: report.py') | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print ('report.py\n-a: all tests\n-d: debug\n-m: insert to mongoDB\n-p: record power consumption') | |
sys.exit() | |
elif opt in ("-a"): | |
print("Running all tests") | |
all_tests = True | |
elif opt in ("-p"): | |
power = True | |
elif opt in ("-d"): | |
debug = True | |
elif opt in ("-m"): | |
mongo_insert = True | |
else: | |
print ('unknown option!') | |
sys.exit() | |
# Main | |
report_version = 0.9 | |
hw_info = hw_info() | |
sw_info = sw_info() | |
cpu_tests = { | |
'primespeed': primespeed(), | |
'openssl': openssl(), | |
'sevenzip': seven_zip(), | |
'coremark_pro_livermore': coremark_pro_livermore(cores), | |
'coremark_pro_radix2fft': coremark_pro_radix2fft(), | |
'coremark_pro_parser': coremark_pro_parser(power), | |
'c2clat': c2clat() | |
} | |
if all_tests: | |
print("Running all tests:\n") | |
ram_tests = { | |
'ram_speed': ram_speed(), | |
'mem_test': memtester() | |
} | |
fs_data = { | |
'gobonniego': gobonniego('/data'), | |
'fio': fio('/data') | |
} | |
fs_boss = { | |
'gobonniego': gobonniego('/var/tmp'), | |
'fio': fio('/var/tmp') | |
} | |
fs_tests = { | |
'boss': fs_boss, | |
'/data': fs_data | |
} | |
summary_json= { | |
'date': date.isoformat(' '), | |
'report_version': report_version, | |
'server': hw_info, | |
'distro': sw_info, | |
'cpu_tests': cpu_tests, | |
'ram_tests': ram_tests, | |
'fs_tests': fs_tests | |
} | |
else: | |
summary_json= { | |
'date': date.isoformat(' '), | |
'report_version': report_version, | |
'server': hw_info, | |
'distro': sw_info, | |
'cpu_test': cpu_tests, | |
} | |
print(json.dumps(summary_json,indent=4)) | |
if mongo_insert: | |
myclient = pymongo.MongoClient("mongodb:///?authSource=admin&compressors=none&gssapiServiceName=mongod") | |
mydb = myclient[""] | |
mycol = mydb[""] | |
ok = mycol.insert_one(summary_json) | |
print(ok.inserted_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment