Skip to content

Commit 2ced287

Browse files
committed
Merge branch 'andrew/add-power-metric-scripts' into 'master'
Add power metric verification scripts See merge request dfinity-lab/public/ic!12582
2 parents b57f504 + a6db25f commit 2ced287

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

ic-os/scripts/README.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
= Scripts
22

3-
This folder contains build and utility scripts for HostOS, which are intended to be consolidated with `ic-os/guestos/scripts` and `ic-os/generic-guestos/scripts`. This unified system will serve as a common build process for any Docker-based images.
3+
This folder contains build and utility scripts for the IC-OS.
4+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
= Power Metric Verification
2+
3+
This directory contains the scripts needed to perform power metric verification on a node.
4+
5+
* `collect_voltage_readings.sh`: collects voltage readings during alternating cycles of stress tests and rest periods.
6+
* `parse_voltage_readings.py`: invoked by collect_voltage_readings.sh, parses the collected voltage readings and generates a CSV file containing the instantaneous voltage readings.
7+
8+
After running these scripts, the resulting data can be cross-verified with the readings from an on-site power distribution unit. This comparison helps validate the readings acquired by the `ipmitool`.
9+
10+
Note: for the scripts to work, you must install `stress-ng` and `ipmitool`
11+
12+
$ sudo apt-get install -y ipmitool stress-ng
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
output_file="voltage_readings.txt"
4+
sudo rm "$output_file"
5+
6+
collect_voltage_readings() {
7+
duration_in_minutes=$1
8+
end_time=$(($(date +%s) + duration_in_minutes * 60))
9+
10+
while [ $(date +%s) -lt $end_time ]; do
11+
sudo ipmitool dcmi power reading >>$output_file
12+
sleep 10s
13+
done
14+
}
15+
16+
# duration_in_minutes is the maximum amount of time to collect voltage readings
17+
duration_in_minutes=120
18+
collect_voltage_readings $duration_in_minutes &
19+
voltage_readings_pid=$!
20+
21+
# alternating cycles of stress tests and rest periods in order to get voltage readings under different conditions.
22+
for i in 10 5 10 5 10; do
23+
timeout "${i}m" stress-ng --sequential "$(nproc)"
24+
sleep "${i}m"
25+
done
26+
27+
sudo kill $voltage_readings_pid
28+
29+
python3 parse_voltage_readings.py voltage_readings.txt
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import csv
2+
import re
3+
import sys
4+
5+
voltage_readings = sys.argv[1]
6+
7+
with open(voltage_readings, 'r') as in_file, open('voltage_readings.csv', 'w', newline='') as out_file:
8+
writer = csv.writer(out_file)
9+
writer.writerow(['Time', 'Instantaneous voltage reading'])
10+
11+
lines = in_file.readlines()
12+
13+
for line in lines:
14+
if line.startswith(' Instantaneous power reading:'):
15+
voltage_reading = re.search(r'\d+', line).group()
16+
17+
elif line.startswith(' IPMI timestamp:'):
18+
time = re.search(r'\d{2}:\d{2}:\d{2}', line).group()
19+
20+
writer.writerow([time, voltage_reading])

0 commit comments

Comments
 (0)