mirror of
https://github.com/telekom-security/tpotce.git
synced 2025-07-02 01:27:27 -04:00
tweaking
healthcheck, watch pid not cpu cleanup dockerfiles bump dicompot, heralding, elasticpot, endlessh to alpine 3.19 bump dionaea, heralding to latest master
This commit is contained in:
42
docker/conpot/dist/cpu_check.py
vendored
Normal file
42
docker/conpot/dist/cpu_check.py
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
import psutil
|
||||
import sys
|
||||
import time
|
||||
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: script.py <PID> <CPU_USAGE_THRESHOLD>")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
pid = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print("Please provide a valid integer value for the PID.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
cpu_threshold = float(sys.argv[2])
|
||||
except ValueError:
|
||||
print("Please provide a valid number for the CPU usage threshold.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
target_process = psutil.Process(pid)
|
||||
except psutil.NoSuchProcess:
|
||||
print(f"No process with the PID {pid} was found.")
|
||||
sys.exit(1)
|
||||
|
||||
# Prepare to calculate the average CPU usage over 3 intervals of 1 second each
|
||||
cpu_usages = []
|
||||
for _ in range(3):
|
||||
cpu_usages.append(target_process.cpu_percent(interval=1))
|
||||
|
||||
# Calculate the average CPU usage
|
||||
average_cpu_usage = sum(cpu_usages) / len(cpu_usages)
|
||||
print(f"Average CPU Usage of PID {pid} over 3 seconds: {average_cpu_usage}%")
|
||||
|
||||
# Check average CPU usage against the threshold
|
||||
if average_cpu_usage >= cpu_threshold:
|
||||
print(f"Average CPU usage of PID {pid} is above or equal to the threshold of {cpu_threshold}%.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
print(f"Average CPU usage of PID {pid} is below the threshold of {cpu_threshold}%. Exiting with code 0.")
|
||||
sys.exit(0)
|
Reference in New Issue
Block a user