Add configuration and playbook for virtualization host setup
- 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.
This commit is contained in:
@@ -1,33 +1,38 @@
|
||||
import time
|
||||
import os
|
||||
|
||||
RAPL_PATH = "/sys/class/powercap/intel-rapl:0/energy_uj"
|
||||
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():
|
||||
def read_energy(path):
|
||||
try:
|
||||
with open(RAPL_PATH, "r") as f:
|
||||
with open(path, "r") as f:
|
||||
return int(f.read().strip())
|
||||
except FileNotFoundError:
|
||||
print(f"Error: {RAPL_PATH} not found.")
|
||||
exit(1)
|
||||
raise RuntimeError(f"RAPL support not available: {path}")
|
||||
|
||||
def calculate_power(interval=1.0):
|
||||
print(f"Monitoring CPU package power every {interval} second(s)... (Ctrl+C to stop)")
|
||||
while True:
|
||||
energy_before = read_energy()
|
||||
time.sleep(interval)
|
||||
energy_after = read_energy()
|
||||
|
||||
delta_uj = energy_after - energy_before
|
||||
power_watts = (delta_uj / 1_000_000) / interval
|
||||
|
||||
print(f"Power Usage: {power_watts:.2f} Watts")
|
||||
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:
|
||||
calculate_power(interval=1.0)
|
||||
# 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.")
|
||||
Reference in New Issue
Block a user