diff --git a/tools/GUDEPowerMeter/README.md b/tools/GUDEPowerMeter/README.md new file mode 100644 index 0000000000000000000000000000000000000000..db49cea1d8cba7adad3355b6e683abc89e479a64 --- /dev/null +++ b/tools/GUDEPowerMeter/README.md @@ -0,0 +1,13 @@ +Slimmed down version of check_gude.py from https://github.com/gudesystems/check_gude.py +for the Blauer Engel für Software Measurements +=============== + +- Create **venv**: `python3 -m venv venv` +- Activate: `source venv/bin/activate` +- Install requests: `pip3 install requests` +- Supply the `-i` parameter for the resolution in ms and the `-x` parameter for the IP + + Example: `python3 check_gude_modified.py -i 100 -x 192.168.178.1` + +The script reports the Watts by default. If you want Joules, which will be the integration +over the time since the last poll, supply `--joules` + diff --git a/tools/GUDEPowerMeter/check_gude_modified.py b/tools/GUDEPowerMeter/check_gude_modified.py new file mode 100644 index 0000000000000000000000000000000000000000..9cf3407f79e00c818b543fefa82311111f10e7f4 --- /dev/null +++ b/tools/GUDEPowerMeter/check_gude_modified.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +import requests +import json +import time +import subprocess + +def main(ip, resolution, joules): + url = f'http://{ip}/status.json' + + ONLY_VALUES = 0x4000 + cgi = {'components': ONLY_VALUES} # simple-sensors + and only values + + resolution = float(resolution); + + target_sleep_time = resolution/1000.0 + + while True: # loop until CTRL+C + timestamp_before = time.time_ns() + time.sleep(target_sleep_time) + + data = json.loads(requests.get(url, params=cgi, verify=False, auth=None).text) + + # print(data) # DEBUG + timestamp_after = time.time_ns() + effective_sleep_time = timestamp_after - timestamp_before + # print(effective_sleep_time / 1_000_000_000) # DEBUG + conversion_factor = effective_sleep_time / 1_000_000 # we want microjoule. Therefore / 10**9 to get seconds and then * 10**3 to get mJ + if joules: + print(int(timestamp_after / 1_000), int(data["sensor_values"][0]['values'][0][4]['v']*conversion_factor), flush=True) + else: + print(int(timestamp_after / 1_000), int(data["sensor_values"][0]['values'][0][4]['v']), flush=True) + + +if __name__ == "__main__": + import argparse + + parser = argparse.ArgumentParser() + parser.add_argument("-i", type=int, help="Resolution") + parser.add_argument("-x", type=str, help="IP") + parser.add_argument("--joules", action='store_true', help="Report Joules instead of Watts") + + args = parser.parse_args() + + if args.i is None: + parser.print_help() + print("Please supply -i to set resolution in milliseconds") + exit(2) + + if args.x is None: + parser.print_help() + print("Please supply -x to set the IP where to find the JSON API from GUDE") + exit(2) + + if args.joules is None: + parser.print_help() + print("Please supply --joules to switch to Joules reporting") + exit(2) + + main(args.x, args.i, args.joules)