Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
753 B
3
Indexable
Never
#!/bin/bash

# Output file
output_file="pod_statistics_$(date +%Y-%m-%d_%H-%M-%S).log"

# Duration settings
duration_seconds=$((30 * 60))  # 30 minutes in seconds
interval_seconds=10

# Calculate end time
end_time=$((SECONDS + duration_seconds))

# Function to get pod statistics and write to output file
get_pod_statistics() {
    kubectl get pods --all-namespaces --no-headers -o custom-columns=NAME:.metadata.name,NAMESPACE:.metadata.namespace,STATUS:.status.phase,RESTARTS:.status.containerStatuses[*].restartCount | while read -r line; do
        echo "$(date +"%Y-%m-%d %H:%M:%S") $line" >> "$output_file"
    done
}

# Main loop
while [ $SECONDS -lt $end_time ]; do
    get_pod_statistics
    sleep $interval_seconds
done
Leave a Comment