Naposledy aktivní 1757947372

Revize 105c159d6ac3fca088237ca716ef9b012b047723

logfile_with_pods.sh Raw
1#!/bin/bash
2
3echo -e "SIZE\tPOD_NAME\tNAMESPACE\tCONTAINER_NAME\tLOG_PATH"
4
5# Step 1: Find all container logs and sort by size
6sudo find /var/lib/docker/containers/ -type f -name "*.log" | while read -r logfile; do
7# echo -e "$logfile"
8 # Get file size
9 size=$(sudo du -h "$logfile" | awk '{print $1}')
10 #echo -e "$size\t$logfile"
11 # Get container ID from filename or path
12 container_id=$(basename "$logfile" | cut -d'-' -f1)
13 #echo -e "$size\t$container_id"
14
15 # Use docker inspect to get Kubernetes labels
16 #pod_name=$(docker inspect "$container_id" 2>/dev/null | grep '"io.kubernetes.pod.name"' | cut -d':' -f2 | tr -d ' ",')
17 #namespace=$(docker inspect "$container_id" 2>/dev/null | grep '"io.kubernetes.pod.namespace"' | cut -d':' -f2 | tr -d ' ",')
18 container_name=$(docker inspect "$container_id" 2>/dev/null | grep '"io.kubernetes.container.name"' | cut -d':' -f2 | tr -d ' ",')
19
20 # Print results
21 #echo -e "$size\t$pod_name\t$namespace\t$container_name\t$logfile"
22 echo -e "$size\t$container_name"
23done | sort -h
24