Hi all...
I have a new F4-424 Pro and I'm getting emails at 4am approx warning me about high cpu usage above 80% on my NAS. I am trying to pinpoint exactly what can be causing this issue but I haven't been able to...
Is there a way to get a log (or set up one) to verify the different processes running at certain time intervals so I can see exactly which process is the culprit? as far as I know, the only thing running could be the plex scanner (which starts at 1am), but I had made no change to my media libraries and the scanning process is set to run using low system resources (in the plex server app).
Any help or guidance would be appreciated... thanks!
Log to check high cpu usage
- carlosdesedas
- Posts: 22
- Joined: 08 Aug 2024, 10:10

Re: Log to check high cpu usage
ok.. si i used chatgpt... it's not perfect.. but it's something..
#!/bin/bash
# Define the log file location
LOG_FILE="/home/YOURUSERHERE/desktop/cpu_usage_log.csv"
# Write the CSV header (only once at the start of the script)
if [ ! -f "$LOG_FILE" ]; then
echo "Timestamp,PID,Command,CPU_Usage(%)" > "$LOG_FILE"
fi
# Function to monitor CPU usage indefinitely
monitor_cpu_usage() {
echo "Monitoring CPU usage indefinitely..." >> "$LOG_FILE"
while true; do
# Get the current timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
# Get the list of processes using more than 60% CPU
# Format the output to capture the full command and ensure correct CPU usage column
ps -eo pid,comm,%cpu --sort=-%cpu | awk -v ts="$timestamp" '
BEGIN { OFS="," }
NR>1 && $3 > 60 {
cmd=$2
for (i=3; i<=NF-1; i++) cmd=cmd" "$i
print ts, $1, cmd, $(NF)
}' >> "$LOG_FILE"
# Sleep for 1 minute before the next check
sleep 60
done
}
# Start monitoring CPU usage indefinitely
monitor_cpu_usage
#!/bin/bash
# Define the log file location
LOG_FILE="/home/YOURUSERHERE/desktop/cpu_usage_log.csv"
# Write the CSV header (only once at the start of the script)
if [ ! -f "$LOG_FILE" ]; then
echo "Timestamp,PID,Command,CPU_Usage(%)" > "$LOG_FILE"
fi
# Function to monitor CPU usage indefinitely
monitor_cpu_usage() {
echo "Monitoring CPU usage indefinitely..." >> "$LOG_FILE"
while true; do
# Get the current timestamp
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
# Get the list of processes using more than 60% CPU
# Format the output to capture the full command and ensure correct CPU usage column
ps -eo pid,comm,%cpu --sort=-%cpu | awk -v ts="$timestamp" '
BEGIN { OFS="," }
NR>1 && $3 > 60 {
cmd=$2
for (i=3; i<=NF-1; i++) cmd=cmd" "$i
print ts, $1, cmd, $(NF)
}' >> "$LOG_FILE"
# Sleep for 1 minute before the next check
sleep 60
done
}
# Start monitoring CPU usage indefinitely
monitor_cpu_usage