fixes
This commit is contained in:
39
app/sbin/cpu
Executable file
39
app/sbin/cpu
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Log file
|
||||
OUTPUT="/4server/data/log/cpu_idle.log"
|
||||
|
||||
# Sampling interval in seconds
|
||||
INTERVAL=60
|
||||
|
||||
while true; do
|
||||
DATA="" # buffer to store idle samples
|
||||
|
||||
# Current date for the measurement period
|
||||
DATE=$(date "+%Y-%m-%d")
|
||||
|
||||
echo "Starting measurement for $DATE"
|
||||
|
||||
while [ "$(date +%H:%M)" != "23:45" ]; do
|
||||
# Get idle CPU percentage
|
||||
IDLE=$(mpstat 1 1 | awk '/Average/ {print $12}')
|
||||
|
||||
# Append to buffer
|
||||
DATA="$DATA$IDLE\n"
|
||||
|
||||
sleep $INTERVAL
|
||||
done
|
||||
|
||||
# Write all data to log file with date
|
||||
# Only one line per day: Date + space-separated idle samples
|
||||
echo -n "$DATE " >> "$OUTPUT"
|
||||
echo -e "$DATA" | tr '\n' ' ' >> "$OUTPUT"
|
||||
echo >> "$OUTPUT" # newline at the end
|
||||
echo "Measurement for $DATE written to $OUTPUT"
|
||||
|
||||
# Wait until 00:15 to start next day
|
||||
while [ "$(date +%H:%M)" != "00:15" ]; do
|
||||
sleep 30
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user