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
标签:MemTotal,mem,default,export,eval,cpu,1000
From: https://www.cnblogs.com/wangend/p/18405722