b692627317
- Create host variable file for vh-01.alexpires.dev with user, SSH, firewall, and VM configurations. - Update playbook_duo_security.yml to target the 2fa group. - Introduce playbook_virt_host.yml for setting up GPU passthrough on Fedora with QEMU/KVM. - Add required collections to requirements.yml for Podman and Libvirt. - Modify ctrlaltdel.yml to remove existing symlink for ctrl-alt-del.target before masking it. - Enhance users.yml to show warnings for users that could not be removed. - Update Duo Security role to use the correct repository and package names. - Improve login role to handle user UID and group assignments. - Create udev rules template for NVMe devices. - Add blacklist template for VFIO drivers. - Implement domain XML template for virtual machines with detailed configurations. - Update inventory to include vh-01.alexpires.dev in relevant groups. - Refactor cpu_power_monitor.py for improved error handling and modularity.
38 lines
1.2 KiB
Python
38 lines
1.2 KiB
Python
import time
|
|
import os
|
|
|
|
RAPL_PATH = "/sys/class/powercap/intel-rapl:0/energy_uj"
|
|
INTERVAL_SEC = 1.0 # configurable via command-line argument or env var
|
|
|
|
def read_energy(path):
|
|
try:
|
|
with open(path, "r") as f:
|
|
return int(f.read().strip())
|
|
except FileNotFoundError:
|
|
raise RuntimeError(f"RAPL support not available: {path}")
|
|
|
|
def calculate_power(energy_before, energy_after, interval_sec):
|
|
delta_uj = energy_after - energy_before
|
|
power_watts = (delta_uj / 1_000_000) / interval_sec
|
|
return f"{power_watts:.2f} Watts"
|
|
|
|
if __name__ == "__main__":
|
|
if os.geteuid() != 0:
|
|
print("Please run this script as root.")
|
|
exit(1)
|
|
|
|
try:
|
|
# RAPL support check
|
|
with open(RAPL_PATH, "r") as f:
|
|
_ = int(f.read().strip())
|
|
|
|
while True:
|
|
energy_before = read_energy(RAPL_PATH)
|
|
time.sleep(INTERVAL_SEC)
|
|
energy_after = read_energy(RAPL_PATH)
|
|
|
|
power_reading = calculate_power(energy_before, energy_after, INTERVAL_SEC)
|
|
print(f"Power Usage: {power_reading}")
|
|
|
|
except KeyboardInterrupt:
|
|
print("\nStopped.") |