[ Status ] 完成Agent Metric部分

This commit is contained in:
zeaslity
2023-07-10 16:24:36 +08:00
parent f5a3db2f56
commit 2f477fd1cc
43 changed files with 491 additions and 381 deletions

View File

@@ -257,47 +257,42 @@ GetIpv4Info() {
country="$(wget -q -T10 -O- ipinfo.io/country)"
region="$(wget -q -T10 -O- ipinfo.io/region)"
public_ipv4="$(wget -q -T10 -O- ipinfo.io/ip)"
public_ipv6="$(curl --max-time 5 -6 https://ifconfig.co/ip)"
public_ipv6="$(curl -q --max-time 5 -6 https://ifconfig.co/ip)"
if [ -z "$public_ipv4" ] ; then
public_ipv4=""
public_ipv4=" "
fi
if [ -z "$public_ipv6" ] ; then
public_ipv6=""
public_ipv6=" "
fi
if [ -z "$public_ipv4" ] ; then
public_ipv4=""
fi
# inner ipinfo
interface_prefix=(" eth[0-9]{1,2}" " ens[0-9]{1,3}" " eno[0-9]{1,3}" " enp[0-9]{1,2}")
real_interface="eth90"
export interface_prefix=("[[:space:]]eth[0-9]{1,2}" "[[:space:]]ens[0-9]{1,3}" "[[:space:]]eno[0-9]{1,3}" "[[:space:]]enp[0-9]{1,2}")
export real_interface="eth90"
for interface in "${interface_prefix[@]}"; do
echo $(ip link show) | grep -oE ${interface}
echo $(ip link show) | grep -oE ${interface} | head -1
if [[ $? -eq 0 ]]; then
real_interface=$(echo $(ip link show) | grep -oE ${interface} | cut -d" " -f2)
echo "当前主机的真实内网网卡为 => $real_interface"
return
real_interface=$(echo $(ip link show) | grep -oE ${interface} | head -1 | cut -d" " -f2)
echo "当前主机的真实内网网卡为 => [$real_interface]"
break
fi
done
# 提取IPv4地址CIDR格式
ipv4_regex="inet (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}"
ipv4_regex="inet[[:space:]](25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\/[0-9]{1,2}"
# 提取IPv6地址CIDR格式
ipv6_regex="inet6 ([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}"
ipv6_regex="inet6[[:space:]]([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){1,7})\/[0-9]{1,3}"
# 查找IPv4地址
inner_ipv4=$(echo $(ip addr show $real_interface) | grep -oE $ipv4_regex | cut -d" " -f2)
echo "Interface: $interface, IPv4 Address: $inner_ipv4"
echo "Interface: $real_interface, IPv4 Address: $inner_ipv4"
# 查找IPv6地址
inner_ipv6=$(echo $(ip addr show $real_interface) | grep -oE $ipv6_regex | cut -d" " -f2)
echo "Interface: $interface, IPv4 Address: $inner_ipv6"
echo "Interface: $real_interface, IPv4 Address: $inner_ipv6"
}
@@ -379,7 +374,7 @@ if [[ $(cat /etc/hostname | cut -d"-" -f 3 | grep -c '^[0-9][0-9]') -gt 0 ]]; th
else
machineNumber=99
fi
agentServerInfoFile="/octopus-agent/octopus-agent.conf "
agentServerInfoFile="/octopus-agent/octopus-agent.conf"
#cat >/etc/environment.d/octopus-agent.conf <<EOF
cat >"$agentServerInfoFile"<<EOF

View File

@@ -171,5 +171,6 @@ tmp() {
chmod +x /root/agent-bootup.sh
/root/agent-bootup.sh"
done
done}
}