forked from FSlyne/NCIRL
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deplib
126 lines (103 loc) · 2.25 KB
/
deplib
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/bash
if [ isApacheRunning ] ; then
echo Apache process is Running
else
echo Apache process is not Running
fi
if [ isMysqlRunning ] ; then
echo Mysql process is Running
else
echo Mysql process is not Running
fi
if [ isLocalIPalive ] ; then
echo Local IP address is alive
else
echo Local IP address is not alive
fi
if [ isApacheListening ] ; then
echo Apache is Listening
else
echo Apache is not Listening
fi
if [ isMysqlListening ] ; then
echo Mysql TCP port is Listening
else
echo Mysql TCP port is not Listening
fi
if [ isMysqlRemoteUp ] ; then
echo Remote Mysql TCP port is up
else
echo Remote Mysql TCP port is down
fi
if [ isApacheRemoteUp ] ; then
echo Remote Apache TCP port is up
else
echo Remote Apache TCP port is down
fi
function isApacheRunning {
return isRunning apache2
}
function isMysqlRunning {
return isRunning mysqld
}
function isLocalIPalive {
return isRunning localhost
}
function isApacheListening {
return isTCPlisten 80
}
function isMysqlListening {
return isTCPlisten 3306
}
function isMysqlRemoteUp {
return isTCPremoteOpen localhost 3306
}
function isApacheRemoteUp {
return isTCPremoteOpen localhost 80
}
function isRunning {
PROCESS_NUM=$(ps -ef | grep "$1" | grep -v "grep" | wc -l)
if [ $PROCESS_NUM -gt 0 ] ; then
return 1
else
return 0
fi
}
function isIPalive {
PINGCOUNT=$(ping -c 1 "$1" | grep "1 received" | wc -l)
if [ $PINGCOUNT -gt 0 ] ; then
return 1
else
return 0
fi
}
function isTCPlisten {
TCPCOUNT=$(netstat -tupln | grep tcp | grep "$1" | wc -l)
if [ $TCPCOUNT -gt 0 ] ; then
return 1
else
return 0
fi
}
function isUDPlisten {
UDPCOUNT=$(netstat -tupln | grep udp | grep "$1" | wc -l)
if [ $UDPCOUNT -gt 0 ] ; then
return 1
else
return 0
fi
}
function isTCPremoteOpen {
timeout 1 bash -c "echo >/dev/tcp/$1/$2" && return 1 || return 0
}
function getCPU {
app_name=$1
cpu_limit="5000"
app_pid=`ps aux | grep $app_name | grep -v grep | awk {'print $2'}`
app_cpu=`ps aux | grep $app_name | grep -v grep | awk {'print $3*100'}`
if [[ $app_cpu -gt $cpu_limit ]]; then
return 0
else
return 1
fi
}