-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathread_info
More file actions
executable file
·79 lines (71 loc) · 2.18 KB
/
Copy pathread_info
File metadata and controls
executable file
·79 lines (71 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
#author : firefoxbug
#
#nohup /bin/bash /usr/local/awstats/tools/read_info.sh > /var/log/read_info.log 2>&1 &
OPENCDN_CONF_FILE="/usr/local/opencdn/conf/opencdn.conf"
OPENCDN_PIPE_PATH="/usr/local/opencdn/pipe"
sys_fifo="${OPENCDN_PIPE_PATH}/sys_info.pipe"
if [ ! -p "$sys_fifo" ];then
mkfifo $sys_fifo
service syslog-ng restart
fi
exec 7<>$sys_fifo
#mysql initial
function mysql_initial()
{
DB_PassWord=`cat $OPENCDN_CONF_FILE | grep "DB_PassWord" | awk -F = '{print $2}'`
#database initial
DB_HOST="127.0.0.1"
DB_USER="root"
DB_PASSWD="$DB_PassWord"
PORT="3306"
DB_NAME="cdn_info"
TABLENAME="node_info"
select_sql="select * from ${TABLENAME}"
}
function add_node_mysql()
{
insert_sql="insert into ${TABLENAME} values(\
\"$1\",\"on\",\
\"${ip[0]}\",\"${netmask[0]}\",\
\"${ip[1]}\",\"${netmask[1]}\",\
\"$System_release\",\"$Kernel_release\",\
\"$Frequency\",\"$CPU_cores\",\
\"${Mem_total}M\",\
\"${Swap_total}M\",\
\"${Disk_total}M\",\
\"0%\",\"0%\",\
\"${onboot[0]}\",\"${send_last[0]}\",\"${recv_last[0]}\",\"${send_total_rate[0]}\",\"${recv_total_rate[0]}\",\
\"${onboot[1]}\",\"${send_last[1]}\",\"${recv_last[1]}\",\"${send_total_rate[1]}\",\"${recv_total_rate[1]}\",\
\"${Mem_used}M\",\"${Mem_free}M\",\"$Mem_per\",\
\"${Swap_used}M\",\"${Swap_free}M\",\"$Swap_per\",\
\"${Disk_used}M\",\"${Disk_free}M\",\"$Disk_per\",\
\"${cache}\"\
)"
mysql -h${DB_HOST} -P${PORT} -u${DB_USER} -p${DB_PASSWD} -D${DB_NAME} -e "${insert_sql};"
}
node_num=0
# mysql initial
mysql_initial
# read configure file of opencdn
# read_conf
while :
do
read -u7 LINE
IP=`echo "$LINE" | awk '{print $1}'`
# echo "$IP"
if [ -z "${IP}" ]
then
continue
fi
is_node_exist=`mysql -h${DB_HOST} -P${PORT} -u${DB_USER} -p${DB_PASSWD} -D${DB_NAME} -e "${select_sql} where NodeIP=\"${IP}\";"`
if [ ! -z "$is_node_exist" ]
then
mysql_cmd=`echo "$LINE" | sed "s/^${IP} //"`
if [ -z "`echo $mysql_cmd | grep ^update`" ]
then
mysql_cmd="update "${mysql_cmd}
fi
mysql -h${DB_HOST} -P${PORT} -u${DB_USER} -p${DB_PASSWD} -D${DB_NAME} -e "${mysql_cmd} where NodeIP=\"${IP}\";"
fi
done