initial commit

This commit is contained in:
chenjinsong
2018-09-27 16:11:54 +08:00
commit 56d71f261a
143 changed files with 23523 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
configPath=/home/nms/nmsdata/nc_config
sysinfoPath=/root/zhong/sysinfo
ip1=192.168.11.211
ip2=192.168.11.211
ip3=192.168.11.211

View File

@@ -0,0 +1,590 @@
#!/bin/bash
basePath=$(cd `dirname $0`; pwd)
date=`date +%Y%m%d%H%M%S`
d=`date "+%Y-%m-%d %H:%M:%S"` #temp column
t=`date -d "$d" +%s` #temp column
t2=`date "+%N" | awk '{print int($0)}'`
dateStamp=$((t*1000+t2/1000000)) #current time stamp
sep=\$@\$
cd ${basePath}
while read line;do # 读取config
eval "$line"
done < config
if [ ! -d macInfo ]
then
mkdir macInfo
fi
if [ ! -d result ]
then
mkdir result
fi
if [ ! -f firstTimeDate ]
then
touch firstTimeDate
echo ${dateStamp} > firstTimeDate
firstTimeDate=${dateStamp}
else
firstTimeDate=`cat firstTimeDate`
fi
# 读取任务配置文件
OLD_IFS="$IFS"
IFS=","
cpu_pubInfo=`cat ${configPath}/cpu_cpu.cfg | grep pubInfo | awk -F'=' '{print $2}'`
cpu_checkState=`cat ${configPath}/cpu_cpu.cfg | grep checkState | awk -F'=' '{print $2}'`
cpu_checkGap=`cat ${configPath}/cpu_cpu.cfg | grep checkGap | awk -F'=' '{print $2}'`
cpu_checkOutTime=`cat ${configPath}/cpu_cpu.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
cpu_checkMaxTimes=`cat ${configPath}/cpu_cpu.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
cpu_planCheckTime=`cat ${configPath}/cpu_cpu.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
cpu_uploadGap=`cat ${configPath}/cpu_cpu.cfg | grep uploadGap | awk -F'=' '{print $2}'`
cpu_dataFileDir=`cat ${configPath}/cpu_cpu.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
cpu_polices=`cat ${configPath}/cpu_cpu.cfg | grep police | awk -F'=' '{print $2}'`
cpu_polices_arr=($cpu_polices)
cpu_police_flag=0
cpu_nextDateStamp=$((cpu_checkGap*60*1000+dateStamp))
mem_pubInfo=`cat ${configPath}/memory_memory.cfg | grep pubInfo | awk -F'=' '{print $2}'`
mem_checkState=`cat ${configPath}/memory_memory.cfg | grep checkState | awk -F'=' '{print $2}'`
mem_checkGap=`cat ${configPath}/memory_memory.cfg | grep checkGap | awk -F'=' '{print $2}'`
mem_checkOutTime=`cat ${configPath}/memory_memory.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
mem_checkMaxTimes=`cat ${configPath}/memory_memory.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
mem_planCheckTime=`cat ${configPath}/memory_memory.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
mem_uploadGap=`cat ${configPath}/memory_memory.cfg | grep uploadGap | awk -F'=' '{print $2}'`
mem_dataFileDir=`cat ${configPath}/memory_memory.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
mem_polices=`cat ${configPath}/memory_memory.cfg | grep police | awk -F'=' '{print $2}'`
mem_polices_arr=($mem_polices)
mem_police_flag=0
mem_nextDateStamp=$((mem_checkGap*60*1000+dateStamp))
disk_pubInfo=`cat ${configPath}/disk_disk.cfg | grep pubInfo | awk -F'=' '{print $2}'`
disk_checkState=`cat ${configPath}/disk_disk.cfg | grep checkState | awk -F'=' '{print $2}'`
disk_checkGap=`cat ${configPath}/disk_disk.cfg | grep checkGap | awk -F'=' '{print $2}'`
disk_checkOutTime=`cat ${configPath}/disk_disk.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
disk_checkMaxTimes=`cat ${configPath}/disk_disk.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
disk_planCheckTime=`cat ${configPath}/disk_disk.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
disk_uploadGap=`cat ${configPath}/disk_disk.cfg | grep uploadGap | awk -F'=' '{print $2}'`
disk_dataFileDir=`cat ${configPath}/disk_disk.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
disk_polices=`cat ${configPath}/disk_disk.cfg | grep police | awk -F'=' '{print $2}'`
disk_polices_arr=($disk_polices)
disk_police_flag=0
disk_nextDateStamp=$((disk_checkGap*60*1000+dateStamp))
net_pubInfo=`cat ${configPath}/net_net.cfg | grep pubInfo | awk -F'=' '{print $2}'`
net_checkState=`cat ${configPath}/net_net.cfg | grep checkState | awk -F'=' '{print $2}'`
net_checkGap=`cat ${configPath}/net_net.cfg | grep checkGap | awk -F'=' '{print $2}'`
net_checkOutTime=`cat ${configPath}/net_net.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
net_checkMaxTimes=`cat ${configPath}/net_net.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
net_planCheckTime=`cat ${configPath}/net_net.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
net_uploadGap=`cat ${configPath}/net_net.cfg | grep uploadGap | awk -F'=' '{print $2}'`
net_dataFileDir=`cat ${configPath}/net_net.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
net_polices=`cat ${configPath}/net_net.cfg | grep police | awk -F'=' '{print $2}'`
net_polices_arr=($net_polices)
net_police_flag=0
net_nextDateStamp=$((net_checkGap*60*1000+dateStamp))
sys_pubInfo=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep pubInfo | awk -F'=' '{print $2}'`
sys_checkState=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkState | awk -F'=' '{print $2}'`
sys_checkGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkGap | awk -F'=' '{print $2}'`
sys_checkOutTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkOutTime | awk -F'=' '{print $2}'`
sys_checkMaxTimes=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep checkMaxTimes | awk -F'=' '{print $2}'`
sys_planCheckTime=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep planCheckTime | awk -F'=' '{print $2}'`
sys_uploadGap=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep uploadGap | awk -F'=' '{print $2}'`
sys_dataFileDir=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep dataFileDir | awk -F'=' '{print $2}'`
sys_polices=`cat ${configPath}/systeminfo_servicessysinfo.cfg | grep police | awk -F'=' '{print $2}'`
sys_polices_arr=($sys_polices)
sys_police_flag=0
sys_nextDateStamp=$((sys_checkGap*60*1000+dateStamp))
IFS="$OLD_IFS"
sysinfoSrc=`cat ${sysinfoPath}`
## begin content weaving ##
# task info
cpuResult_taskInfo=${cpu_pubInfo}","${firstTimeDate}","${cpu_checkOutTime}","${dateStamp}",1,"${cpu_nextDateStamp}","
memResult_taskInfo=${mem_pubInfo}","${firstTimeDate}","${mem_checkOutTime}","${dateStamp}",1,"${mem_nextDateStamp}","
diskResult_taskInfo=${disk_pubInfo}","${firstTimeDate}","${disk_checkOutTime}","${dateStamp}",1,"${disk_nextDateStamp}","
netResult_taskInfo=${net_pubInfo}","${firstTimeDate}","${net_checkOutTime}","${dateStamp}",1,"${net_nextDateStamp}","
sysResult_taskInfo=${sys_pubInfo}","${firstTimeDate}","${sys_checkOutTime}","${dateStamp}",1,"${sys_nextDateStamp}",1,"
cpuResult_coreNum=0
disk_total_num=0
net_total_num=0
sys_net_total_num=0
diskResult_baseInfo="\""
memResult_baseInfo="\""
netResult_baseInfo="\""
sysResult_baseInfo="\""
# result file
cpuResult=result/cpuResult_${date}
memResult=result/memResult_${date}
diskResult=result/diskResult_${date}
netResult=result/netResult_${date}
sysResult=result/sysResult_${date}
function getDetail {
cpuInfo=macInfo/$1_cpuInfo_${date}
memInfo=macInfo/$1_memInfo_${date}
diskInfo=macInfo/$1_diskInfo_${date}
netInfo=macInfo/$1_netInfo_${date}
sysInfo=macInfo/$1_sysInfo_${date}
ssh -tt $2 "sar -P ALL 1 1" > ${cpuInfo}
ssh -tt $2 "cat /proc/cpuinfo | grep MHz" > ${cpuInfo}2
ssh -tt $2 "free|awk 'NR>1{print}'" > ${memInfo}
ssh -tt $2 "df -l|grep -v tmpfs|awk 'NR>1{print}'" > ${diskInfo}
# 网卡信息
special_net_result_t=`ssh -C $2 "/bin/bash" < remote_net.sh` # 获取特殊网卡信息
special_net_result_base=${special_net_result_t%details,*}
special_net_result_details_t=${special_net_result_t#*details,}
special_net_result_details="\""${special_net_result_details_t#*\"}
special_net_result_details_t_arr=($special_net_result_details_t)
special_net_result_detailsNum=${special_net_result_details_t_arr[0]}
special_net_result=${special_net_result_base}"details,"${special_net_result_detailsNum}$'\n'
for((i=1;i<${#special_net_result_details_t_arr[@]};i++));do
special_net_result=${special_net_result}${special_net_result_details_t_arr[$i]}$'\n'
done
echo "$special_net_result" > ${netInfo}3
getNetInfo
dos2unix ${cpuInfo} > /dev/null 2>&1
dos2unix ${cpuInfo}2 > /dev/null 2>&1
dos2unix ${memInfo} > /dev/null 2>&1
dos2unix ${diskInfo} > /dev/null 2>&1
#dos2unix ${diskInfo} > /dev/null 2>&1
# cpu info
cpu_t=`awk -F "(" '{print $3}' ${cpuInfo}` # temp column
cpu_coreNum=`echo $cpu_t|awk -F " " '{print $1}'`
cpuResult_coreNum=$((cpuResult_coreNum+cpu_coreNum))
cpu_totalMHz=`awk '{total+=$4}END{print total}' ${cpuInfo}2`
cpu_averMHz=`echo "scale=2;$cpu_totalMHz/$cpu_coreNum"|bc|awk '{printf "%.2f",$0}'`
cpu_idle_total=`awk 'NR==4{print $9}' ${cpuInfo}`
cpu_shiyonglv=`bc <<<100-$cpu_idle_total|awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu${index} i18n_client.SystemInfo.mhz_n81i"${cpu_averMHz}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_shiyonglv}"%; "
getCpuBase2 ${cpuInfo} ${cpuInfo}2
getCpuDetail ${cpuInfo} ${cpuInfo}2
# mem info
swap_total_t=`cat ${memInfo}|grep '^S'|awk '{print $2}'`
swap_total=`echo "scale=2;${swap_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
swap_free_t=`cat ${memInfo}|grep '^S'|awk '{print $4}'`
swap_free=`echo "scale=2;${swap_free_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_total_t=`awk 'NR==1{print $2}' ${memInfo}`
mem_total=`echo "scale=2;${mem_total_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_used_t=`awk 'NR==1{print $3}' ${memInfo}`
mem_used=`echo "scale=2;${mem_used_t}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
mem_free=`echo "${mem_total}-${mem_used}"|bc|awk '{printf "%.2f",$0}'`
mem_shiyonglv=`echo "scale=2;${mem_used}/${mem_total}*100.00"|bc|awk '{printf "%.2f",$0}'`
memResult_baseInfo="${memResult_baseInfo}"${sep}"i18n_client.SystemInfo.memerySize_n81i: "${mem_total}"G, i18n_client.SystemInfo.currentUsed_n81i"${mem_used}"G, i18n_client.SystemInfo.spaceRemain_n81i"${mem_free}"G, i18n_client.SystemInfo.shiyonglv_n81i"${mem_shiyonglv}"% "
mem_detail_nopolice=${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
OLD_IFS="$IFS"
IFS=","
mem_detail_nopolice_arr=(${mem_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $mem_polices ]
then
mem_police_most_level=0
mem_police_flag_t=0 #临时变量
mem_baseInfo_police=""
for((j=0;j<${#mem_polices_arr[@]};j++));do
mem_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
mem_police_arr=(${mem_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]} ${mem_police_arr[1]} ${mem_police_arr[2]}"|bc) == 1))
then #触发告警
mem_detail_police_t=${mem_police_arr[0]}","${mem_police_arr[3]}","${mem_police_arr[2]}","
mem_police_flag=1
mem_police_flag_t=1
if ((${mem_police_arr[3]} > ${mem_police_most_level}))
then
mem_police_most_level=${mem_police_arr[3]}
mem_detail_police=$mem_detail_police_t
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $mem_police_flag_t -eq 0 ]&&[ -z "${mem_baseInfo_police}" ];then
mem_detail_police="\"\",,,"
mem_baseInfo_police="${mem_detail_nopolice_arr[0]}"${mem_police_arr[4]}${mem_detail_nopolice_arr[((${mem_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
memResult_baseInfo_police=${memResult_baseInfo_police}${mem_baseInfo_police}
else
mem_detail_police="\"\",,,"
fi
memResult_detail=${memResult_detail}${mem_detail_police}${mem_detail_nopolice}
#memResult_detail="${memResult_detail}""\"\",,,"${swap_total}","${swap_free}","${mem_total}","${mem_used}","${mem_free}","${mem_shiyonglv}","$'\n'
# disk info
disk_total_size=`awk '{total+=$2}END{print total}' ${diskInfo}` # Kb
disk_total_used_size=`awk '{total+=$3}END{print total}' ${diskInfo}`
disk_total_shiyonglv=`echo "scale=2;(${disk_total_used_size}*100)/${disk_total_size}"|bc|awk '{printf "%.2f",$0}'`
diskResult_baseInfo=${diskResult_baseInfo}${sep}"disk-"${index}"i18n_client.SystemInfo.diskSize_n81i"`echo "scale=2;${disk_total_size}/1024/1024"|bc|awk '{printf "%.2f",$0}'`"Gi18n_client.SystemInfo.used2_n81i "${disk_total_shiyonglv}"% ;"
getDiskBase ${diskInfo}
getDiskDetail
# net info
#net_avai_if_arr=($(awk 'NR==1{print $0}' ${netInfo}))
#net_all_if_arr=($(awk 'NR>1{print}' ${netInfo} | awk -F ':' '{print $1 NR}'))
#getNetInfo
}
function getCpuBase2 {
arr1=($(awk '/^[0-2]/{print $9}' $1|awk 'NR>2{print $0}'))
arr2=($(awk '{print $4}' $2))
for((i=0;i<${#arr1[@]};i++));do
cpu_t2=`bc <<<100-${arr1[$i]} |awk '{printf "%.2f",$0}'`
cpuResult_baseInfo=${cpuResult_baseInfo}${sep}"cpu"${index}"-$i i18n_client.SystemInfo.mhz_n81i"${arr2[$i]}"MHzi18n_client.SystemInfo.shiyonglv_n81i "${cpu_t2}"%; "
done
}
function getCpuDetail {
cpu_t3=`awk '/^[0-2]/{print $0}' $1|awk 'NR>1{print $0}'`
for((i=2;i<=`echo "${cpu_t3}"|awk 'END{print NR}'`;i++));do
cpu_row=`echo "${cpu_t3}"|awk 'NR=="'$i'"{print $0}'`
cpu_idle=`echo "${cpu_row}"|awk '{print $9}'`
cpu_shiyonglv_t=`bc <<<100-${cpu_idle} |awk '{printf "%.2f",$0}'`
cpu_detail_nopolice="cpu${index}-$((i-2)),"`echo "${cpu_row}"|awk '{print $4}'`","`echo "${cpu_row}"|awk '{print $6}'`","`echo "${cpu_row}"|awk '{print $7}'`","`echo "${cpu_row}"|awk '{print $5}'`","`echo "${cpu_row}"|awk '{print $9}'`","${cpu_shiyonglv_t}","`awk 'NR=="'$((i-1))'"{print $4}' $2`$'\n'
# police
if [ ! -z $cpu_polices ]
then
OLD_IFS="$IFS"
IFS=","
cpu_detail_nopolice_arr=(${cpu_detail_nopolice})
IFS=$OLD_IFS
cpu_police_most_level=0
cpu_police_flag_t=0 #临时变量
cpu_baseInfo_police=""
for((j=0;j<${#cpu_polices_arr[@]};j++));do
cpu_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
cpu_police_arr=(${cpu_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]} ${cpu_police_arr[1]} ${cpu_police_arr[2]}"|bc) == 1))
then #触发告警
cpu_detail_police_t=${cpu_police_arr[0]}","${cpu_police_arr[3]}","${cpu_police_arr[2]}","
cpu_police_flag=1
cpu_police_flag_t=1
if ((${cpu_police_arr[3]} > ${cpu_police_most_level}))
then
cpu_police_most_level=${cpu_police_arr[3]}
cpu_detail_police=$cpu_detail_police_t
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $cpu_police_flag_t -eq 0 ]&&[ -z "${cpu_baseInfo_police}" ];then
cpu_detail_police="\"\",,,"
cpu_baseInfo_police="【cpu${index}-$((i-2))"${cpu_police_arr[4]}${cpu_detail_nopolice_arr[((${cpu_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
cpuResult_baseInfo_police=${cpuResult_baseInfo_police}${cpu_baseInfo_police}
else
cpu_detail_police="\"\",,,"
fi
cpuResult_detail=${cpuResult_detail}${cpu_detail_police}${cpu_detail_nopolice}
done
cpuResult_detail=${cpuResult_detail}"\"\",,,cpu${index},"`awk 'NR==4{print $4}' $1`","`awk 'NR==4{print $6}' $1`","`awk 'NR==4{print $7}' $1`","`awk 'NR==4{print $5}' $1`","`awk 'NR==4{print $9}' $1`","${cpu_shiyonglv}","${cpu_averMHz}$'\n'
}
function getDiskBase {
disk_size_arr=($(awk '{print $2}' $1))
disk_used_arr=($(awk '{print $3}' $1))
disk_avai_arr=($(awk '{print $4}' $1)) # available
disk_usep_arr=($(awk '{print $5}' $1))
disk_moun_arr=($(awk '{print $6}' $1)) # mount on
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_used=`echo "scale=2;${disk_used_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_usep=${disk_usep_arr[$i]}
disk_moun=${disk_moun_arr[$i]}
diskResult_baseInfo=${diskResult_baseInfo}${sep}"【disk-$index:"${disk_moun}"】i18n_client.SystemInfo.size_n81i "${disk_size}"G, i18n_client.SystemInfo.used1_n81i "${disk_used}"G, i18n_client.SystemInfo.spaceRemain_n81i "${disk_avai}"G, i18n_client.SystemInfo.shiyonglv_n81i "${disk_usep}" ; "
done
}
function getDiskDetail {
disk_total_num=`echo "${disk_total_num}+${#disk_size_arr[@]}"|bc`
for((i=0;i<${#disk_size_arr[@]};i++));do
disk_size=`echo "scale=2;${disk_size_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'` # Gb
disk_avai=`echo "scale=2;${disk_avai_arr[$i]}/1024/1024"|bc|awk '{printf "%.2f",$0}'`
disk_detail_nopolice="disk-$index:"${disk_moun_arr[$i]}","${disk_size}","${disk_avai}","${disk_usep_arr[$i]%\%*}",0,"$'\n'
OLD_IFS=$IFS
IFS=","
disk_detail_nopolice_arr=(${disk_detail_nopolice})
IFS=$OLD_IFS
# police
if [ ! -z $disk_polices ]
then
disk_police_most_level=0
disk_police_flag_t=0 #临时变量
disk_baseInfo_police=""
for((j=0;j<${#disk_polices_arr[@]};j++));do
disk_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
disk_police_arr=(${disk_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]} ${disk_police_arr[1]} ${disk_police_arr[2]}"|bc) == 1))
then #触发告警
disk_detail_police_t=${disk_police_arr[0]}","${disk_police_arr[3]}","${disk_police_arr[2]}","
disk_police_flag=1
disk_police_flag_t=1
if ((${disk_police_arr[3]} > ${disk_police_most_level}))
then
disk_police_most_level=${disk_police_arr[3]}
disk_detail_police=$disk_detail_police_t
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $disk_police_flag_t -eq 0 ]&&[ -z "${disk_baseInfo_police}" ];then
disk_detail_police="\"\",,,"
disk_baseInfo_police="${disk_detail_nopolice_arr[0]}"${disk_police_arr[4]}${disk_detail_nopolice_arr[((${disk_police_arr[0]}-1))]}" i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
diskResult_baseInfo_police=${diskResult_baseInfo_police}${disk_baseInfo_police}
else
disk_detail_police="\"\",,,"
fi
diskResult_detail=${diskResult_detail}${disk_detail_police}${disk_detail_nopolice}
done
}
function getNetInfo {
# 处理特殊网卡信息的内容
special_base_row=`awk 'NR==1{print $0}' ${netInfo}3` # 第一行
special_base_11=`echo ${special_base_row} | awk -F '"' '{print $2}'` # 11列
special_base_11=${sep}${special_base_11#*$sep}
special_base_12=`echo $special_base_row | awk -F '"' '{print $4}'` # 12列
special_base_12=${sep}${special_base_12#*$sep}
special_base_t=${special_base_11}${special_base_12}
special_base_t=${special_base_t//$sep/\!}
OLDIFS=$IFS
IFS="\!"
special_base_t_arr=(${special_base_t})
IFS=$OLD_IFS
special_base=""
for((i=1;i<${#special_base_t_arr[@]};i++));do
special_base=${special_base}"${sep}if${index}-"${special_base_t_arr[$i]}
done
special_detail_rows=`awk 'NR>2{print}' ${netInfo}3` # details行下方所有行
special_detail_rows_arr=($special_detail_rows) # details下方所有行的数组每个元素为一行内容
#special_if_t=`echo ${special_detail_rows}|awk -F ',' '{print $4}'` # 取每行第三、四个逗号之间的网卡名
special_if_arr=() # 网卡名称数组
special_if_baseInfo="" # 初始化特殊网卡基础信息
for ((i=0;i<${#special_detail_rows_arr[@]};i++));do
special_detail_row=`echo ${special_detail_rows_arr[$i]} | awk -F ',' '{print gensub($4,"if"'$index'"-"$4,1)}'` # detail行网卡名替换为ifx-开头的名字
netResult_detail=${netResult_detail}${special_detail_row}$'\n'
special_if_baseInfo=${special_if_baseInfo}${special_base_12}${special_base_11}
special_if_arr[$i]=`echo ${special_detail_rows_arr[$i]}| awk -F ',' '{print $4}'`
done
sys_net_total_num=`echo "${sys_net_total_num}+${#net_all_if_arr[@]}"|bc`
net_total_num=`echo "${net_total_num}+${#net_avai_if_arr[@]}"|bc`
net_avai_baseInfo=""
net_disa_baseInfo=""
for((i=0;i<${#net_all_if_arr[@]};i++));do
ifName_t=${net_all_if_arr[$i]}
ifName=${ifName_t%?}
echo ${special_if_arr[0]}"--"${special_if_arr[1]}"--"${special_if_arr[2]}"--"${ifName}
if echo "${special_if_arr[@]}"|grep -w "${ifName}" &>/dev/null;then
let "net_total_num--"
let "sys_net_total_num--"
continue
fi
net_rowNum=$((${net_all_if_arr[$i]: -1}+1))
net_if_name_t=`awk 'NR=="'${net_rowNum}'"{print $1}' ${netInfo}`
net_if_name=${net_if_name_t%?}
is_avai=`echo "${net_avai_if_arr[@]}" | grep -wq "${net_all_if_arr[$i]%?}" && echo "1" || echo "0"`
if [ "1" -eq "$is_avai" ]
then
echo "#!/bin/bash"$'\n'"ethtool ${net_if_name}" > ethtool.sh
net_if_ethtoolResult=`ssh -C $value "/bin/bash" < ethtool.sh`
net_if_speed_t=`echo "${net_if_ethtoolResult}"|grep "Speed:"|awk '{print $2}'`
if [ ${#net_if_speed_t} -lt 1 ]
then
net_if_speed=0
else
net_if_speed=${net_if_speed_t:0:${#net_if_speed_t}-4}
fi
net_if_rxByte1=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}`
net_if_rxByte2=`awk 'NR=="'${net_rowNum}'"{print $2}' ${netInfo}2`
net_if_rxBps=`echo "scale=2;($net_if_rxByte2-$net_if_rxByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxPackets1=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}`
net_if_rxPackets2=`awk 'NR=="'${net_rowNum}'"{print $3}' ${netInfo}2`
net_if_rxPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_rxPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txByte1=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txByte2=`awk 'NR=="'${net_rowNum}'"{print $10}' ${netInfo}`
net_if_txBps=`echo "scale=2;($net_if_txByte2-$net_if_txByte1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_txPackets1=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}`
net_if_txPackets2=`awk 'NR=="'${net_rowNum}'"{print $11}' ${netInfo}2`
net_if_txPps_t=`echo "($net_if_rxPackets2-$net_if_rxPackets1)"|bc`
net_if_txPps=`echo "scale=2;($net_if_rxPackets2-$net_if_rxPackets1)*8/5"|bc|awk '{printf "%.2f",$0}'`
net_if_rxError1=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}`
net_if_rxError2=`awk 'NR=="'${net_rowNum}'"{print $4}' ${netInfo}2`
net_if_txError1=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}`
net_if_txError2=`awk 'NR=="'${net_rowNum}'"{print $12}' ${netInfo}2`
net_if_rxDrop1=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}`
net_if_rxDrop2=`awk 'NR=="'${net_rowNum}'"{print $5}' ${netInfo}2`
net_if_txDrop1=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}`
net_if_txDrop2=`awk 'NR=="'${net_rowNum}'"{print $13}' ${netInfo}2`
if [ $net_if_rxPps_t -gt 0 ]
then
net_if_rxErrorPerc=`echo "scale=2;($net_if_rxError2-$net_if_rxError1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_rxDropPerc=`echo "scale=2;($net_if_rxDrop2-$net_if_rxDrop1)*100/($net_if_rxPackets2-$net_if_rxPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_rxErrorPerc=0.00
net_if_rxDropPerc=0.00
fi
if [ $net_if_txPps_t -gt 0 ]
then
net_if_txErrorPerc=`echo "scale=2;($net_if_txError2-$net_if_txError1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
net_if_txDropPerc=`echo "scale=2;($net_if_txDrop2-$net_if_txDrop1)*100/($net_if_txPackets2-$net_if_txPackets1)"|bc|awk '{printf "%.2f",$0}'`
else
net_if_txErrorPerc=0.00
net_if_txDropPerc=0.00
fi
net_avai_baseInfo=${net_avai_baseInfo}${sep}"if"${index}"-"${net_if_name}" i18n_client.SystemInfo.netSpeed_n81i"${net_if_speed}"Mbps, i18n_client.SystemInfo.input_n81i"${net_if_rxBps}"bps、"${net_if_rxPps}"pps, Output"${net_if_txBps}"bps、"${net_if_txPps}"pps; "
net_detail_nopolice="if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
#netResult_detail=${netResult_detail}"\"\",,,if${index}-"${net_if_name}","${net_if_rxPackets2}","${net_if_txPackets2}","${net_if_rxByte2}","${net_if_txByte2}","${net_if_rxError2}","${net_if_txError2}","${net_if_rxDrop2}","${net_if_txDrop2}","${net_if_speed}","${net_if_rxBps}","${net_if_txBps}","${net_if_rxPps}","${net_if_txPps}","${net_if_rxErrorPerc}","${net_if_txErrorPerc}","${net_if_rxDropPerc}","${net_if_txDropPerc}$'\n'
# police
if [ ! -z $net_polices ]
then
OLD_IFS="$IFS"
IFS=","
net_detail_nopolice_arr=(${net_detail_nopolice})
IFS=$OLD_IFS
net_police_most_level=0
net_police_flag_t=0 #临时变量
net_baseInfo_police=""
for((j=0;j<${#net_polices_arr[@]};j++));do
net_detail_police_t=""
OLD_IFS="$IFS"
IFS="|"
net_police_arr=(${net_polices_arr[$j]})
IFS=$OLD_IFS
if (($(echo "${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]} ${net_police_arr[1]} ${net_police_arr[2]}"|bc) == 1))
then #触发告警
net_detail_police_t=${net_police_arr[0]}","${net_police_arr[3]}","${net_police_arr[2]}","
net_police_flag=1
net_police_flag_t=1
if ((${net_police_arr[3]} > ${net_police_most_level}))
then
net_police_most_level=${net_police_arr[3]}
net_detail_police=$net_detail_police_t
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.abnormal_n81i</br>"
fi
elif [ $net_police_flag_t -eq 0 ]&&[ -z "${net_baseInfo_police}" ];then
net_detail_police="\"\",,,"
net_baseInfo_police="${net_detail_nopolice_arr[0]}"${net_police_arr[4]}${net_detail_nopolice_arr[((${net_police_arr[0]}-1))]}"% i18n_client.GetInfoRun.normal_n81i</br>"
fi
done
netResult_baseInfo_police=${netResult_baseInfo_police}${net_baseInfo_police}
else
net_detail_police="\"\",,,"
fi
netResult_detail=${netResult_detail}${net_detail_police}${net_detail_nopolice}
else
net_disa_baseInfo=${net_disa_baseInfo}${sep}"if"${index}"-"${net_if_name}"i18n_client.SystemInfo.disable_n81i; "
fi
done
sys_net_total_num=`echo "${sys_net_total_num}+${#special_detail_rows_arr[@]}"|bc`
net_total_num=`echo "$net_total_num+${#special_detail_rows_arr[@]}"|bc`
netResult_baseInfo=${netResult_baseInfo}"${sep}if"${index}"-"${#special_detail_rows_arr[@]}"i18n_client.SystemInfo.insert_n81i: "${special_base}${net_avai_baseInfo}${net_disa_baseInfo}$'\n'
}
# main
index=1
flag=1
while [ $flag -eq 1 ]; do
key='ip'${index}
value=`eval echo '$'${key}`
if [ -z ${value} ]
then
flag=0
else
getDetail ${key} ${value}
let "index++"
fi
done
## result
# cpu
cpuResult_baseInfo=${cpuResult_baseInfo}"\""
if ((${cpu_police_flag} == 0 ))
then
cpuResult_baseInfo_police="\""${cpuResult_baseInfo}
cpu_police_flag=1
else
cpuResult_baseInfo_police="\""${cpuResult_baseInfo_police}"\""
cpu_police_flag=0
fi
echo "${cpuResult_taskInfo}""${cpu_police_flag},""\"${cpuResult_coreNum}""i18n_client.SystemInfo.core_n81i: ""${cpuResult_baseInfo}"",""${cpuResult_baseInfo_police}"$'\n'"details,""$((cpuResult_coreNum+index-1))"$'\n'"${cpuResult_detail}" > ${cpu_dataFileDir}/${date}".csv" #${cpuResult}
# mem
memResult_baseInfo=${memResult_baseInfo}"\""
if ((${mem_police_flag} == 0 ))
then
memResult_baseInfo_police=${memResult_baseInfo}
mem_police_flag=1
else
memResult_baseInfo_police="\""${memResult_baseInfo_police}"\""
mem_police_flag=0
fi
echo "${memResult_taskInfo}"${mem_police_flag}",${memResult_baseInfo}"",""${memResult_baseInfo_police}"$'\n'"details,""$((index-1))"$'\n'"${memResult_detail}" > ${mem_dataFileDir}/${date}".csv" #${memResult}
# disk
diskResult_baseInfo=${diskResult_baseInfo}"\""
if ((${disk_police_flag} == 0 ))
then
diskResult_baseInfo_police=${diskResult_baseInfo}
disk_police_flag=1
else
diskResult_baseInfo_police="\""${diskResult_baseInfo_police}"\""
disk_police_flag=0
fi
echo "${diskResult_taskInfo}"${disk_police_flag}",${diskResult_baseInfo}"",""${diskResult_baseInfo_police}"$'\n'"details,$disk_total_num"$'\n'"${diskResult_detail}" > ${disk_dataFileDir}/${date}".csv" #${diskResult}
# net
netResult_baseInfo=${netResult_baseInfo}"\""
if ((${net_police_flag} == 0 ))
then
netResult_baseInfo_police=${netResult_baseInfo}
net_police_flag=1
else
netResult_baseInfo_police="\""${netResult_baseInfo_police}"\""
net_police_flag=0
fi
echo "${netResult_taskInfo}"${net_police_flag}",${netResult_baseInfo}"",""${netResult_baseInfo_police}"$'\n'"details,$net_total_num"$'\n'"${netResult_detail}" > ${net_dataFileDir}/${date}".csv" #${netResult}
# sys
sysinfo=`cat ${sysinfoPath}`
echo "${sysResult_taskInfo}""${sysinfo}" > ${sys_dataFileDir}/${date}".csv" #${sysResult}

View File

@@ -0,0 +1,362 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# created by zhongyoub
'''
get all net card info and write to file with csv format
time: ms
'''
import time,re,os,csv
import ConfigParser
import StringIO
from datetime import datetime
global cfg_path_str
global nic_path_str
global marsio_cmd
cfg_path_str="/home/nms/nc_config/net_net/net_net.cfg"
nic_path_str="/proc/net/dev"
marsio_cmd="monit_device"
def round2(a):
return ("%.2f"%a)
class monitor_net():
def __init__(self):
self.seqId="" # seqId
self.id="" # 监测设置ID
self.cattory="" # 监测类别
self.process="" # 进程名称
self.start_time=int(round(time.time()*1000)) # 监测服务启动时间
self.delay=0 # 检测时延
self.checktime=int(round(time.time()*1000)) # 本次检测时间
self.try_times=1 # 尝试次数
self.next_time=0 # 下次监测时间 self.start_time + self.interval
self.checkState=1 # 检测状态
self.checkGap=0
self.config_path=cfg_path_str
self.nic_path=nic_path_str
'''
nic info
'''
self.nic_info={"eth_name":"", "rx_packets":0, "tx_packets":0, "rx_bytes":0, "tx_bytes":0,
"rx_errs":0, "tx_errs":0, "rx_drop":0, "tx_drops":0, "speed":10000,
"rx_bps":0, "tx_bps":0, "rx_pps":0, "tx_pps":0,
"rx_err_perc":0, "tx_err_perc":0, "rx_drop_perc":0, "tx_drop_perc":0 }
self.marsio_info={"eth_name":"", "rx_packets":0, "tx_packets":0, "rx_bytes":0, "tx_bytes":0,
"rx_errs":0, "tx_errs":0, "rx_drop":0, "tx_drops":0, "speed":10000,
"rx_bps":0, "tx_bps":0, "rx_pps":0, "tx_pps":0,
"rx_err_perc":0, "tx_err_perc":0, "rx_drop_perc":0, "tx_drop_perc":0 }
# self.vf_dict={'0':'','1':'','2':''}
self.vf_list=[]
self.marsio_list=[]
'''
read config file
'''
def read_config(self):
'''
with open(self.config_path, 'r') as f:
section_string = '[dummy_section]\n' + f.read()
'''
config=StringIO.StringIO()
config.write('[dummy_section]\n')
config.write(open(self.config_path).read())
config.seek(0,os.SEEK_SET)
cfg = ConfigParser.ConfigParser()
# cfg.readfp(section_string)
cfg.readfp(config)
pubInfo=cfg.get("dummy_section", "pubInfo")
self.seqId=pubInfo.split(",",3)[0]
self.id=pubInfo.split(",",3)[1]
self.cattory=pubInfo.split(",",3)[2]
self.process=pubInfo.split(",",3)[3]
self.delay=cfg.get("dummy_section","checkOutTime")
self.try_times=cfg.get("dummy_section","checkMaxTimes")
self.checkGap=int(cfg.get("dummy_section","checkGap"))*60*1000 # ms
self.next_time=self.start_time+self.checkGap
self.checkState=cfg.get("dummy_section","checkState")
'''
get net card info/home/nms/nc_config/net_net
'''
def get_vfnet_info(self):
net_info=open("/proc/net/dev","r")
info=net_info.readlines()
net_info.close()
# print self.marsio_list
for line in info: # find nic name like ens*f*
self.nic_info={"eth_name":"", "rx_packets":0, "tx_packets":0, "rx_bytes":0, "tx_bytes":0,
"rx_errs":0, "tx_errs":0, "rx_drop":0, "tx_drops":0, "speed":10000,
"rx_bps":0, "tx_bps":0, "rx_pps":0, "tx_pps":0,
"rx_err_perc":0, "tx_err_perc":0, "rx_drop_perc":0, "tx_drop_perc":0 }
if re.search(r'ens.f.',line):
field=line.split()
self.nic_info["eth_name"]=field[0].split(":")[0]
self.nic_info["rx_bytes"]=field[1]
self.nic_info["rx_packets"]=field[2]
self.nic_info["rx_errs"]=field[3]
self.nic_info["rx_drop"]=field[4]
self.nic_info["tx_bytes"]=field[9]
self.nic_info["tx_packets"]=field[10]
self.nic_info["tx_errs"]=field[11]
self.nic_info["tx_drop"]=field[12]
# self.vf_dict[str(i)]=self.nic_info
# print "nic_info"
# print self.nic_info
self.vf_list.append(self.nic_info)
# print self.vf_list
# print self.vf_list[str(i)]
'''
eth_name=field[0].split(":")[0]
rx_bytes=field[1]
rx_packets=field[2]
rx_errs=field[3]
rx_drop=field[4]
tx_bytes=field[9]
tx_packts=field[10]
tx_errs=field[11]
tx_drop=field[12]
return(eth_name, int(rx_bytes),int(rx_packets),int(rx_errs),int(rx_drop),int(tx_bytes),
int(tx_packts),int(tx_errs),int(tx_drop))
'''
'''
get marsio net card info by open(monit_device)
'''
def get_marsionet_info(self):
info=os.popen(marsio_cmd)
for line in info:
if re.search(r'ens.f*',line):
self.marsio_info["eth_name"]=line.split(",")[1].split(":")[1].strip()
if re.search(r'Accu',line):
self.marsio_info["rx_packets"]=line.split()[1]
self.marsio_info["rx_bytes"]=int(line.split()[2])/8 # bit to byte(float)
self.marsio_info["rx_drop"]=line.split()[9]
self.marsio_info["rx_errs"]=line.split()[4]
self.marsio_info["tx_packets"]=line.split()[6]
self.marsio_info["tx_bytes"]=int(line.split()[7])/8
self.marsio_info["tx_errs"]=line.split()[8]
self.marsio_info['tx_drop']=line.split()[10]
if re.search(r'Second',line):
self.marsio_info["rx_bps"]=line.split()[3]
rx_packets=self.marsio_info["rx_pps"]=line.split()[2]
tx_packets=self.marsio_info["tx_pps"]=line.split()[7]
self.marsio_info["tx_bps"]=line.split()[8]
rx_err_per=line.split()[5]
tx_err_per=line.split()[9]
if int(rx_packets)!=0:
self.marsio_info["rx_err_perc"]=round2(float(rx_err_per)/int(rx_packets))
else:
self.marsio_info["rx_err_perc"]=round2(0)
# print self.marsio_info["rx_err_perc"]
if int(tx_packets)!=0:
self.marsio_info["tx_err_perc"]=round2(float(tx_err_per)/int(tx_packets))
else:
self.marsio_info["tx_err_perc"]=round2(0)
# print self.marsio_info["tx_err_perc"]
rx_drop_per=line.split()[10]
tx_drop_per=line.split()[11]
if int(rx_packets)!=0:
self.marsio_info["rx_drop_perc"]=round2(float(rx_drop_per)/int(rx_packets))
else:
self.marsio_info["rx_drop_perc"]=round2(0)
# print self.marsio_info["rx_drop_perc"]
if int(tx_packets)!=0:
self.marsio_info["tx_drop_perc"]=round2(float(tx_drop_per)/int(tx_packets))
else:
self.marsio_info["tx_drop_perc"]=round2(0)
# print self.marsio_info["tx_drop_perc"]
self.marsio_list.append(self.marsio_info)
# print "marsio_info"
# print self.marsio_info
def list_append(list1, dict1):
list1.append(dict1["eth_name"])
list1.append(dict1["rx_packets"])
list1.append(dict1["tx_packets"])
list1.append(dict1["rx_bytes"])
list1.append(dict1["tx_bytes"])
list1.append(dict1["rx_errs"])
list1.append(dict1["tx_errs"])
list1.append(dict1["rx_drop"])
list1.append(dict1["tx_drop"])
list1.append(dict1["speed"])
list1.append(dict1["rx_bps"])
list1.append(dict1["tx_bps"])
list1.append(dict1["rx_pps"])
list1.append(dict1["tx_pps"])
list1.append(dict1["rx_err_perc"])
list1.append(dict1["tx_err_perc"])
list1.append(dict1["rx_drop_perc"])
list1.append(dict1["tx_drop_perc"])
def main():
monitor=monitor_net()
monitor.read_config()
monitor.chectime=int(round(time.time()*1000))
monitor.get_marsionet_info()
list3=monitor.marsio_list
monitor.get_vfnet_info()
list1=monitor.vf_list
# print "list1"
# print list1
monitor.vf_list=[]
# print monitor.vf_list
# monitor.vf_list.clear()
time.sleep(1)
monitor.get_vfnet_info()
list2=monitor.vf_list
# print "list2"
# print list2
for x, y in zip(list1,list2):
rx_bytes_pers=int(y["rx_bytes"])-int(x["rx_bytes"])
tx_bytes_pers=int(y["tx_bytes"])-int(x["tx_bytes"])
rx_packet_pers=float(y["rx_packets"])-int(x["rx_packets"])
tx_packet_pers=float(y["tx_packets"])-int(x["tx_packets"])
rx_bps=rx_bytes_pers*8
rx_pps=rx_packet_pers
tx_bps=tx_bytes_pers*8
tx_pps=tx_packet_pers
if rx_packet_pers >0:
rx_err_rate=(int(y["rx_errs"])-int(x["rx_errs"]))/rx_packet_pers
else:
rx_err_rate=0
if tx_packet_pers>0:
tx_err_rate=(int(y["tx_errs"])-int(x["tx_errs"]))/tx_packet_pers
else:
tx_err_rate=0
if rx_packet_pers>0:
rx_drop_rate=(int(y["rx_drop"])-int(x["rx_drop"]))/rx_packet_pers
else:
rx_drop_rate=0
if tx_packet_pers>0:
tx_drop_rate=(int(y["tx_drop"])-int(x["tx_drop"]))/tx_packet_pers
else:
tx_drop_rate=0
'''
y["rx_bps"]=round2(rx_bps)
y["rx_pps"]=round2(rx_pps)
y["tx_bps"]=round2(tx_bps)
y["tx_pps"]=round2(tx_pps)
'''
y["rx_err_perc"]=round2(rx_err_rate)
y["tx_err_perc"]=round2(tx_err_rate)
y["rx_drop_perc"]=round2(rx_drop_rate)
y["tx_drop_perc"]=round2(tx_drop_rate)
# print list2
# print list3
vf_num=len(monitor.vf_list)
# print monitor.vf_list
# print vf_num
marsio_num=len(list3)
csv_file=datetime.now().strftime("%Y%m%d%H%M%S")
header=[monitor.seqId,monitor.id,monitor.cattory,monitor.process,monitor.start_time,monitor.delay,
monitor.chectime,monitor.try_times,monitor.next_time,monitor.checkState]
first_str=str(vf_num)+"i18n_client.SystemInfo.insert_n81i: "
for each in list2:
first_str=first_str+"$@$"+each["eth_name"]+ \
" i18n_client.SystemInfo.netSpeed_n81i10000Mbps,"+"i18n_client.SystemInfo.input_n81i"+ \
str(each["rx_bps"])+"bps、"+str(each["rx_pps"])+"pps,"+"Output"+str(each["tx_bps"])+"bps、"+str(each["tx_pps"])+ \
"pps;"
second_str=str(marsio_num)+"i18n_client.SystemInfo.insert_n81i: "
for each in list3:
second_str=second_str+"$@$"+each["eth_name"]+ \
" i18n_client.SystemInfo.netSpeed_n81i10000Mbps,"+"i18n_client.SystemInfo.input_n81i"+ \
str(each["rx_bps"])+"bps、 "+str(each["rx_pps"])+"pps,"+"Output"+str(each["tx_bps"])+"bps、"+str(each["tx_pps"])+ \
"pps;"
four_1=['\"','','']
four_2=['\"','','']
four_3=['\"','','']
if len(list2)>1:
first_dict=list2[0]
second_dict=list2[1]
list_append(four_1,first_dict)
list_append(four_2,second_dict)
elif len(list2)==1:
first_dict=list2[0]
list_append(four_1,first_dict)
four_2=[]
else:
four_1=[]
four_2=[]
if len(list3)>0:
three_dict=list3[0]
'''
three_dict["rx_bps"]=round2(int(three_dict["rx_bps"]))
three_dict["rx_pps"]=round2(int(three_dict["rx_pps"]))
three_dict["tx_bps"]=round2(int(three_dict["tx_bps"]))
three_dict["tx_bps"]=round2(int(three_dict["tx_bps"]))
three_dict["rx_err_perc"]=round2(int(three_dict["rx_err_perc"]))
three_dict["tx_err_perc"]=round2(int(three_dict["tx_err_perc"]))
three_dict["rx_drop_perc"]=round2(int(three_dict["rx_drop_perc"]))
three_dict["tx_drop_perc"]=round2(int(three_dict["tx_drop_perc"]))
'''
list_append(four_3,three_dict)
else:
four_3=[]
'''
four_1.append(first_list["eth_name"])
four_1.append(first_list["rx_packets"])
four_1.append(first_list["tx_packets"])
four_1.append(first_list["rx_bytes"])
four_1.append(first_list["tx_bytes"])
four_1.append(first_list["rx_errs"])
four_1.append(first_list["tx_errs"])
four_1.append(first_list["rx_drop"])
four_1.append(first_list["tx_drop"])
four_1.append(first_list["speed"])
four_1.append(first_list["rx_bps"])
four_1.append(first_list["tx_bps"])
four_1.append(first_list["rx_pps"])
four_1.append(first_list["tx_pps"])
four_1.append(first_list["rx_err_perc"])
four_1.append(first_list["tx_err_perc"])
four_1.append(first_list["rx_drop_perc"])
'''
# print four_1
# print four_2
# print four_3
header.append(first_str)
header.append(second_str)
two_list=["details"]
two_list.append((vf_num+marsio_num))
with open(csv_file+".csv","w") as f:
f_writer=csv.writer(f,lineterminator='\n')
f_writer.writerow(header)
f_writer.writerow(two_list)
if len(four_1):
f_writer.writerow(four_1)
if len(four_2):
f_writer.writerow(four_2)
if len(four_3):
f_writer.writerow(four_3)
f.close()
if __name__ == '__main__':
main()
exit(0)

View File

@@ -0,0 +1,5 @@
#!/bin/bash
python /root/zhong/monitor_net.py #py脚本的路径需要手动填写
cat `ls|grep csv`
rm -f *.csv

View File

@@ -0,0 +1,29 @@
"$@$1-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1466.65MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i$@$2-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1498.72MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i$@$3-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1567.90MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i","$@$1-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1466.65MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i$@$2-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1498.72MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i$@$3-localhost.localdomain): 3.10.0-693.el7.x86_64, 8i18n_client.SystemInfo.message.core_n81i CPU, 1567.90MHz, 15.44i18n_client.SystemInfo.message.memery_n81i, 1885477224i18n_client.SystemInfo.message.disk_n81i, 4i18n_client.SystemInfo.message.netcard_n81i"
details,3
"",,,1-localhost.localdomain),"3.10.0-693.el7.x86_64",8,1466.65,15.44,63.99,1885477224,4,
"",,,2-localhost.localdomain),"3.10.0-693.el7.x86_64",8,1498.72,15.44,63.99,1885477224,4,
"",,,3-localhost.localdomain),"3.10.0-693.el7.x86_64",8,1567.90,15.44,63.99,1885477224,4,
disk,9
1:/,1884767064,
1:/boot,505580,
1:/boot/efi,204580,
2:/,1884767064,
2:/boot,505580,
2:/boot/efi,204580,
3:/,1884767064,
3:/boot,505580,
3:/boot/efi,204580,
net,12
1-enp0s31f6,Available,100,10.0.6.247,255.255.255.0,10.0.6.100,30:9c:23:4d:9c:93,
1-wlp3s0,Unavailable,0,0.0.0.0,0.0.0.0,0,0,0,0,f8:28:19:d4:13:db,
1-virbr0-nic,Unavailable,10,0.0.0.0,0.0.0.0,0,0,0,0,52:54:00:37:52:32,
1-virbr0,Available,0,192.168.122.1,255.255.255.0,10.0.6.100,52:54:00:37:52:32,
2-enp0s31f6,Available,100,10.0.6.247,255.255.255.0,10.0.6.100,30:9c:23:4d:9c:93,
2-wlp3s0,Unavailable,0,0.0.0.0,0.0.0.0,0,0,0,0,f8:28:19:d4:13:db,
2-virbr0-nic,Unavailable,10,0.0.0.0,0.0.0.0,0,0,0,0,52:54:00:37:52:32,
2-virbr0,Available,0,192.168.122.1,255.255.255.0,10.0.6.100,52:54:00:37:52:32,
3-enp0s31f6,Available,100,10.0.6.247,255.255.255.0,10.0.6.100,30:9c:23:4d:9c:93,
3-wlp3s0,Unavailable,0,0.0.0.0,0.0.0.0,0,0,0,0,f8:28:19:d4:13:db,
3-virbr0-nic,Unavailable,10,0.0.0.0,0.0.0.0,0,0,0,0,52:54:00:37:52:32,
3-virbr0,Available,0,192.168.122.1,255.255.255.0,10.0.6.100,52:54:00:37:52:32,