-
Notifications
You must be signed in to change notification settings - Fork 5
/
first60s
executable file
·117 lines (98 loc) · 2.19 KB
/
first60s
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
#!/bin/bash
# linux performance analysis tool
# usage: first60s
# used in the first 60 seconds after login to a server with a performance issue
# inspired by http://techblog.netflix.com/2015/11/linux-performance-analysis-in-60s.html
# created by zhouwei on 2016-6-22
print_line() {
echo ""
echo "=================================================================================="
echo ""
}
# install sysstat if necessary
if ! which iostat || ! which sar ; then
if which yum ; then
yum -y install sysstat
fi
fi >&/dev/null
# stats start
outfile="perf_stats_$(date '+%Y-%m-%d_%H:%M:%S')"
exec 3>&1
exec 1>$outfile
# print file header
echo "linux performance analysis statistics"
echo "date: $(date '+%Y-%m-%d %H:%M:%S')"
print_line
# don't need, comment it with here document
cat > /dev/null << !EOF!
# ps aux, if java process exists
if ps aux | grep -v grep | grep java >/dev/null ; then
echo "ps aux - java:"
ps aux | head -1
ps aux | grep -v grep | grep java
if [ "$(ps aux | grep -v grep | grep java | wc -l)" = "1" ]; then
top -b -n 1 -H -p $(pgrep -f java)
fi
print_line
fi
!EOF!
# uptime
echo "uptime:"
uptime
print_line
# dmesg and /var/log/messages
echo "dmesg:"
dmesg | tail -20
if [ -f /var/log/messages ]; then
echo ""
echo "/var/log/messages:"
tail -20 /var/log/messages
fi
print_line
# memory and disk usages
echo "memory usage:"
free -m
echo ""
echo "disk usage:"
df -h
print_line
# top
echo "top:"
top -b -n 1
print_line
# netstat
echo "netstat - sockets stats:"
netstat -ant | awk '/^tcp/ {s[$NF]++} END{for(i in s) print i, s[i]}' OFS="\t"
print_line
# set count seconds
count=10
# vmstat
echo "vmstat 1 ${count}:"
vmstat 1 ${count}
print_line
# pidstat
echo "pidstat 1 ${count}:"
pidstat 1 ${count}
print_line
# mpstat
echo "mpstat -P ALL 1 ${count}:"
mpstat -P ALL 1 ${count}
print_line
# iostat
echo "iostat -xz 1 ${count}:"
iostat -xz 1 ${count}
print_line
# sar -n DEV
echo "sar -n DEV 1 ${count}:"
sar -n DEV 1 ${count}
print_line
# sar -n TCP, ETCP
echo "sar -n TCP,ETCP 1 ${count}:"
sar -n TCP,ETCP 1 ${count}
print_line
# the end
exec 1>&3
exec 3>&-
echo "performance statistics finished!"
echo "outfile: $(pwd)/$outfile"
exit 0