From 3d2026421c8662a407d198370148727ea62cbab9 Mon Sep 17 00:00:00 2001 From: Sebastian <379651+czarly@users.noreply.github.com> Date: Sun, 3 Nov 2024 10:13:32 +0100 Subject: [PATCH] try to figure --- show-file-size.sh | 19 +++++++++++++ show-size.sh | 56 +++++++++++++++++++++++++++++++++++++++ show-static-file-size.sh | 31 ++++++++++++++++++++++ static-file-path-list.txt | 4 +++ 4 files changed, 110 insertions(+) create mode 100755 show-file-size.sh create mode 100755 show-size.sh create mode 100755 show-static-file-size.sh create mode 100644 static-file-path-list.txt diff --git a/show-file-size.sh b/show-file-size.sh new file mode 100755 index 00000000..4f576310 --- /dev/null +++ b/show-file-size.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Read the JSON input and extract the list of keys +keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') + +total_size=0 + +# Iterate over the list of keys +for key in $keys; do + #echo "checking: /var/lib/docker/volumes/rpc_$key" + + prefix="/var/lib/docker/volumes/rpc_$key" + + volume_size=$(du -s $prefix 2>/dev/null | awk '{print $1}') + + total_size=$((total_size + volume_size)) +done + +echo "$total_size" diff --git a/show-size.sh b/show-size.sh new file mode 100755 index 00000000..146c55be --- /dev/null +++ b/show-size.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +BASEPATH="$(dirname "$0")" +source $BASEPATH/.env + +IFS=':' read -ra parts <<< $COMPOSE_FILE + +blacklist=("drpc.yml" "drpc-free.yml" "base.yml" "rpc.yml" "monitoring.yml" "ftp.yml" "backup-http.yml") + +total_size=0 +static_size=0 + +for part in "${parts[@]}"; do + include=true + for word in "${blacklist[@]}"; do + if echo "$part" | grep -qE "$word"; then + #echo "The path $path contains a blacklisted word: $word" + include=false + fi + done + + # Check if any parameters were passed + if [ $# -gt 0 ]; then + # Put parameters into an array (list) + params=("$@") + + # Check if a string is part of the list + if [[ " ${params[@]} " =~ " ${part%.yml} " ]]; then + include=$include # don't change anything + else + include=false + fi + fi + + if $include; then + static_ratio="$($BASEPATH/show-static-file-size.sh ${part%.yml})" + static_ratio="0$static_ratio" + total_kb=$($BASEPATH/show-file-size.sh ${part%.yml}) + + total_size=$((total_size + total_kb)) + + #output=$(echo "$((total_kb * 1024))" | numfmt --to=iec --suffix=B --format="%.2f") + #echo "$output" + static_part=$(echo "$total_kb * $static_ratio" | bc) + + static_size=$(echo "$static_size + $static_part" | bc) + #output=$(echo "$static_size" | numfmt --to=iec --suffix=B --format="%.2f") + #echo "$output" + fi +done + +total=$(echo "$(( total_size * 1024 ))" | numfmt --to=iec --suffix=B --format="%.2f") +static=$(echo $(echo "$static_size * 1024" | bc) | numfmt --to=iec --suffix=B --format="%.2f") + +echo "total: $total" +echo "static: $static" diff --git a/show-static-file-size.sh b/show-static-file-size.sh new file mode 100755 index 00000000..e0dc035a --- /dev/null +++ b/show-static-file-size.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Read the JSON input and extract the list of keys +keys=$(cat /root/rpc/$1.yml | yaml2json - | jq '.volumes' | jq -r 'keys[]') + +static_size=0 +total_size=0 + +# Iterate over the list of keys +for key in $keys; do + #echo "checking: /var/lib/docker/volumes/rpc_$key" + + prefix="/var/lib/docker/volumes/rpc_$key" + + volume_size=$(du -s $prefix 2>/dev/null | awk '{print $1}') + + total_size=$((total_size + volume_size)) + + while IFS= read -r path; do + # Check if the path exists + if [[ -e "$prefix/_data/$path" ]]; then + # Print the size of the file or directory + size=$(du -s "$prefix/_data/$path" 2>/dev/null | awk '{print $1}') + static_size=$((static_size + size)) + #echo "$path: $size" + fi + done < static-file-path-list.txt +done + +ratio=$(bc -l <<< "scale=2; $static_size/$total_size") +echo "$ratio" diff --git a/static-file-path-list.txt b/static-file-path-list.txt new file mode 100644 index 00000000..d75fc702 --- /dev/null +++ b/static-file-path-list.txt @@ -0,0 +1,4 @@ +static_files +chain/nitro/l2chaindata/ancient +ancient +geth/chaindata/ancient