eval

mingtian是吧發表於2024-09-10
MemTotal=$(awk '/MemTotal/{print $2}' /proc/meminfo )
# MemTotal=$(echo "scale=2;$MemTotal/1000/1000"|bc)
CpuTotal=$(awk '/processor/{core++} END{print core}' /proc/cpuinfo)


export mongodb_cpu=$(($CpuTotal/5))
export core_cpu=$(($CpuTotal/10))
export nginx_cpu=$(($CpuTotal/10))
export loki_cpu=$(($CpuTotal/5))
export redis_cpu=$(($CpuTotal/10))
export victora_cpu=$(($CpuTotal/5))
export api_cpu=$(($CpuTotal/10))


export api_mem=$(($MemTotal/10/1000))
export victora_mem=$(($MemTotal/5/1000))
export redis_mem=$(($MemTotal/10/1000))
export loki_mem=$(($MemTotal/5/1000))
export mongodb_mem=$(($MemTotal/5/1000))
export core_mem=$(($MemTotal/10/1000))
export nginx_mem=$(($MemTotal/10/1000))


default_cpu(){
    if [ "${!1}" -le 2 ] ; then
        eval "$1=2.0"
    fi
}

default_mem(){
    if [ "${!1}" -le 2048 ] ; then
        eval "$1=2048" # 動態給變數賦值
    fi
}

default_cpu api_cpu
default_mem api_mem
default_cpu victora_cpu
default_mem victora_mem
default_cpu redis_cpu
default_mem redis_mem
default_cpu loki_cpu
default_mem loki_mem
default_cpu mongodb_cpu
default_mem mongodb_mem
default_cpu core_cpu
default_mem core_mem
default_cpu nginx_cpu
default_mem nginx_mem

相關文章