-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
cminfo.sh
executable file
·787 lines (708 loc) · 32.6 KB
/
cminfo.sh
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
#!/bin/bash
#####################################################
# set locale temporarily to english
# due to some non-english locale issues
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
#####################################################
# quick info overview for centminmod.com installs
#####################################################
DT=$(date +"%d%m%y-%H%M%S")
CENTMINLOGDIR='/root/centminlogs'
#####################################################
MYCNF='/etc/my.cnf'
USER='root'
PASS=''
MYSQLHOST='localhost'
#####################################################
FORCE_IPVFOUR='y' # curl/wget commands through script force IPv4
CURL_TIMEOUTS=' --max-time 5 --connect-timeout 5'
CURRENTIP=$(echo $SSH_CLIENT | awk '{print $1}')
VIRTUALCORES=$(grep -c ^processor /proc/cpuinfo)
PHYSICALCPUS=$(grep 'physical id' /proc/cpuinfo | sort -u | wc -l)
CPUCORES=$(grep 'cpu cores' /proc/cpuinfo | head -n 1 | cut -d: -f2)
CPUSPEED=$(awk -F: '/cpu MHz/{print $2}' /proc/cpuinfo | sort | uniq -c)
CPUMODEL=$(awk -F: '/model name/{print $2}' /proc/cpuinfo | sort | uniq -c)
CPUCACHE=$(awk -F: '/cache size/{print $2}' /proc/cpuinfo | sort | uniq -c)
CENTOSVER=$(awk '{ print $3 }' /etc/redhat-release)
if [ "$CENTOSVER" == 'release' ]; then
CENTOSVER=$(awk '{ print $4 }' /etc/redhat-release | cut -d . -f1,2)
if [[ "$(cat /etc/redhat-release | awk '{ print $4 }' | cut -d . -f1)" = '7' ]]; then
CENTOS_SEVEN='7'
fi
fi
# Check for Redhat Enterprise Linux 7.x
if [ "$CENTOSVER" == 'Enterprise' ]; then
CENTOSVER=$(awk '{ print $7 }' /etc/redhat-release)
if [[ "$(awk '{ print $1,$2 }' /etc/redhat-release)" = 'Red Hat' && "$(awk '{ print $7 }' /etc/redhat-release | cut -d . -f1)" = '7' ]]; then
CENTOS_SEVEN='7'
REDHAT_SEVEN='y'
fi
fi
if [[ -f /etc/system-release && "$(awk '{print $1,$2,$3}' /etc/system-release)" = 'Amazon Linux AMI' ]]; then
CENTOS_SIX='6'
fi
if [ ! -f /usr/sbin/virt-what ]; then
yum -y -q install virt-what
fi
if [ ! -f /usr/sbin/lshw ]; then
yum -y -q install lshw
fi
if [ ! -f /usr/bin/tree ]; then
yum -y -q install tree
fi
if [ ! -f /usr/bin/smem ]; then
yum -y -q install smem
fi
if [ -z $PASS ]; then
MYSQLADMINOPT="-h $MYSQLHOST"
else
MYSQLADMINOPT="-u$USER -p$PASS -h $MYSQLHOST"
fi
#####################################################
if [[ -z "$SYSTYPE" ]]; then
SYSTYPE='not virtualized'
fi
if [ -z ${CPUCORES} ]; then
CPUCORES='1'
fi
if [ -z ${PHYSICALCPUS} ]; then
PHYSICALCPUS='1'
fi
CPUCORES=$((${CPUCORES} * ${PHYSICALCPUS}));
if [ ${CPUCORES} -gt 0 -a ${CPUCORES} -lt ${VIRTUALCORES} ]; then
HT=yes;
else HT=no;
fi
if [ -f /etc/centminmod/custom_config.inc ]; then
source /etc/centminmod/custom_config.inc
fi
if [[ "$FORCE_IPVFOUR" != [yY] ]]; then
ipv_forceopt=""
else
ipv_forceopt='4'
fi
cmservice() {
servicename=$1
action=$2
if [[ "$CENTOS_SEVEN" != '7' ]] && [[ "${servicename}" = 'haveged' || "${servicename}" = 'pure-ftpd' || "${servicename}" = 'mysql' || "${servicename}" = 'php-fpm' || "${servicename}" = 'nginx' || "${servicename}" = 'memcached' || "${servicename}" = 'nsd' || "${servicename}" = 'csf' || "${servicename}" = 'lfd' ]]; then
echo "service ${servicename} $action"
if [[ "$CMSDEBUG" = [nN] ]]; then
service "${servicename}" "$action"
fi
else
if [[ "${servicename}" = 'php-fpm' || "${servicename}" = 'nginx' ]]; then
echo "service ${servicename} $action"
if [[ "$CMSDEBUG" = [nN] ]]; then
service "${servicename}" "$action"
fi
elif [[ "${servicename}" = 'mysql' || "${servicename}" = 'mysqld' ]]; then
servicename='mariadb'
echo "systemctl $action ${servicename}.service"
if [[ "$CMSDEBUG" = [nN] ]]; then
systemctl "$action" "${servicename}.service"
fi
fi
fi
}
#####################################################
top_info() {
SYSTYPE=$(virt-what | head -n1)
CENTMINMOD_INFOVER=$(head -n1 /etc/centminmod-release)
CCACHE_INFOVER=$(ccache -V | head -n1)
NGINX_INFOVER=$(nginx -v 2>&1 | awk -F "/" '{print $2}' | head -n1)
PHP_INFOVER=$(php -v 2>&1 | head -n1 | cut -d "(" -f1 | awk '{print $2}')
MARIADB_INFOVER=$(rpm -qa | grep -i MariaDB-server | head -n1 | cut -d '-' -f3)
MEMCACHEDSERVER_INFOVER=$(/usr/local/bin/memcached -h | head -n1 | awk '{print $2}')
CSF_INFOVER=$(csf -v | head -n1 | awk '{print $2}')
SIEGE_INFOVER=$(siege -V 2>&1 | head -n1 | awk '{print $2}')
APC_INFOVER=$(php --ri apc | awk '/Version/ {print $3}' | head -n1)
OPCACHE_INFOVER=$(php -v 2>&1 | grep OPcache | awk '{print $4}' | sed 's/,//')
if [[ "$(which nsd >/dev/null 2>&1; echo $?)" -eq '0' ]]; then
NSD_INFOVER=$(nsd -v 2>&1 | head -n1 | awk '{print $3}')
else
NSD_INFOVER=" - "
fi
# only assign variables if mysql is running
if [[ "$(ps -o comm -C mysqld >/dev/null 2>&1; echo $?)" = '0' ]]; then
DATABSELIST=$(mysql $MYSQLADMINOPT -e 'show databases;' | grep -Ev '(Database|information_schema|performance_schema)')
MYSQLUPTIME=$(mysqladmin $MYSQLADMINOPT ext | awk '/Uptime|Uptime_since_flush_status/ { print $4 }' | head -n1)
MYSQLUPTIMEFORMAT=$(mysqladmin $MYSQLADMINOPT ver | awk '/Uptime/ { print $2, $3, $4, $5, $6, $7, $8, $9 }')
MYSQLSTART=$(mysql $MYSQLADMINOPT -e "SELECT FROM_UNIXTIME(UNIX_TIMESTAMP() - variable_value) AS server_start FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE variable_name='Uptime';" | egrep -Ev '+--|server_start')
fi
PAGESPEEDSTATUS=$(grep 'pagespeed unplugged' /usr/local/nginx/conf/pagespeed.conf)
if [[ -z "$PAGESPEEDSTATUS" ]]; then
PS=ON
else
PS=OFF
fi
if [ -f /usr/local/sbin/maldet ]; then
MALDET_INFOVER=$(/usr/local/sbin/maldet -v | head -n1 | awk '{print $4}')
fi
if [ -f /usr/bin/clamscan ]; then
CLAMAV_INFOVER=$(clamscan -V | head -n1 | awk -F "/" '{print $1}' | awk '{print $2}')
fi
echo "------------------------------------------------------------------"
echo " Centmin Mod Top Info:"
echo "------------------------------------------------------------------"
echo " Server Location Info"
# echo
curl -${ipv_forceopt}s${CURL_TIMEOUTS} https://ipinfo.io/geo 2>&1 | sed -e 's|[{}]||' -e 's/\(^"\|"\)//g' -e 's|,||' | egrep -v 'ip:|phone|postal|loc|readme'
echo " ASN: $(curl -${ipv_forceopt}s${CURL_TIMEOUTS} https://ipinfo.io/org 2>&1)"
echo
echo " Processors" "physical = ${PHYSICALCPUS}, cores = ${CPUCORES}, virtual = ${VIRTUALCORES}, hyperthreading = ${HT}"
echo
echo "$CPUSPEED"
echo "$CPUMODEL"
echo "$CPUCACHE"
echo ""
if [[ "$CENTOS_SEVEN" = '7' ]]; then
echo -ne " System Up Since: \t"; uptime -s
echo -ne " System Uptime: \t"; uptime -p
else
echo -ne " System Uptime: \t"; uptime | awk '{print $2, $3, $4, $5}'
fi
if [[ "$(ps -o comm -C mysqld >/dev/null 2>&1; echo $?)" = '0' ]]; then
echo -e " MySQL Server Started \t$MYSQLSTART"
echo -e " MySQL Uptime: \t\t$MYSQLUPTIMEFORMAT"
echo -e " MySQL Uptime (secs): \t$MYSQLUPTIME"
else
echo -e " MySQL Server Started \tnot running"
echo -e " MySQL Uptime: \t\tnot running"
echo -e " MySQL Uptime (secs): \tnot running"
fi
echo -e " Server Type: \t\t$SYSTYPE"
echo -e " CentOS Version: \t$CENTOSVER"
echo -e " Centmin Mod: \t\t$CENTMINMOD_INFOVER"
echo -e " Nginx PageSpeed: \t$PS"
echo -e " Nginx Version: \t$NGINX_INFOVER"
echo -e " PHP-FPM Version: \t$PHP_INFOVER"
echo -e " MariaDB Version: \t$MARIADB_INFOVER"
echo -e " CSF Firewall: \t\t$CSF_INFOVER"
echo -e " Memcached Server: \t$MEMCACHEDSERVER_INFOVER"
echo -e " NSD Version: \t\t$NSD_INFOVER"
echo -e " Siege Version: \t$SIEGE_INFOVER"
if [ -f /usr/local/sbin/maldet ]; then
echo -e " Maldet Version: \t$MALDET_INFOVER"
else
echo -e " Maldet Version: \tnot installed"
fi
if [ -f /usr/bin/clamscan ]; then
echo -e " ClamAV Version: \t$CLAMAV_INFOVER"
else
echo -e " ClamAV Version: \tnot installed"
fi
if [[ "$(rpm -qa elasticsearch)" ]]; then
ESEXIST=y
ELASTICSEARCH_INFOVER=$(rpm -qa elasticsearch | awk -F "-" '{print $2}')
echo -e " ElasticSearch: \t$ELASTICSEARCH_INFOVER"
else
echo -e " ElasticSearch: \tnot installed"
fi
echo
echo "------------------------------------------------------------------"
echo "free -mtl"
free -mtl
echo
echo "------------------------------------------------------------------"
echo "top 10 processes using swap (VmSwap)"
echo
find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSwap"] && process["VmSwap"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSwap"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -rh | cut -d " " -f2- | head -n10
echo
echo "------------------------------------------------------------------"
echo "top 10 processes' virtual memory size (VmSize/VSZ)"
echo "RSS vs VSZ https://stackoverflow.com/a/21049737/272648"
echo "RSS https://en.wikipedia.org/wiki/Resident_set_size"
# echo "VSZ https://en.wikipedia.org/wiki/Virtual_memory"
echo
find /proc -maxdepth 2 -path "/proc/[0-9]*/status" -readable -exec awk -v FS=":" '{process[$1]=$2;sub(/^[ \t]+/,"",process[$1]);} END {if(process["VmSize"] && process["VmSize"] != "0 kB") printf "%10s %-30s %20s\n",process["Pid"],process["Name"],process["VmSize"]}' '{}' \; | awk '{print $(NF-1),$0}' | sort -rh | cut -d " " -f2- | head -n10
echo
if [ -f /usr/bin/smem ]; then
echo "------------------------------------------------------------------"
echo "smem process memory info (sorted by RSS)"
echo "PSS https://en.wikipedia.org/wiki/Proportional_set_size"
echo "USS https://en.wikipedia.org/wiki/Unique_set_size"
echo
smem -rt -s rss
echo
fi
echo "------------------------------------------------------------------"
echo "df -hT"
df -hT
if [[ -f /usr/local/nginx/conf/conf.d/virtual.conf && -f /usr/local/nginx/conf/phpstatus.conf && "$(grep '^#include /usr/local/nginx/conf/phpstatus.conf' /usr/local/nginx/conf/conf.d/virtual.conf)" ]]; then
sed -i 's|^#include /usr/local/nginx/conf/phpstatus.conf;|include /usr/local/nginx/conf/phpstatus.conf;|' /usr/local/nginx/conf/conf.d/virtual.conf
nprestart >/dev/null 2>&1
fi
if [[ -f /usr/local/nginx/conf/conf.d/virtual.conf && "$(grep '^include /usr/local/nginx/conf/phpstatus.conf' /usr/local/nginx/conf/conf.d/virtual.conf)" && -f /usr/bin/fpmstats ]]; then
echo
echo "------------------------------------------------------------------"
echo "php-fpm stats"
echo
fpmstats
elif [[ -f /usr/local/nginx/conf/conf.d/virtual.conf && "$(grep '^include /usr/local/nginx/conf/phpstatus.conf' /usr/local/nginx/conf/conf.d/virtual.conf)" && ! -f /usr/bin/fpmstats ]]; then
echo
echo "------------------------------------------------------------------"
echo "php-fpm stats"
echo
curl -s "localhost/phpstatus"
fi
echo
echo "------------------------------------------------------------------"
echo "Filter sar -q for times cpu load avg (1min) hit/exceeded cpu threads max"
loadavg=$(printf "%0.2f" $(nproc))
sarfilteredone=$(sar -q | sed -e "s|$(hostname)|hostname|g" | grep -v runq-sz | awk -v lvg=$loadavg '{if ($5>=lvg) print $0}' | egrep -v 'Linux|Average')
echo
echo "${sarfilteredone:-no times found that >= $loadavg}"
echo
echo "------------------------------------------------------------------"
echo "Filter sar -q for times cpu load avg (5min) hit/exceeded cpu threads max"
loadavg=$(printf "%0.2f" $(nproc))
sarfilteredfive=$(sar -q | sed -e "s|$(hostname)|hostname|g" | grep -v runq-sz | awk -v lvg=$loadavg '{if ($6>=lvg) print $0}' | egrep -v 'Linux|Average')
echo
echo "${sarfilteredfive:-no times found that >= $loadavg}"
echo
echo "------------------------------------------------------------------"
echo "sar -q | sed -e \"s|\$(hostname)|hostname|g\""
sar -q | sed -e "s|$(hostname)|hostname|g"
echo
echo "------------------------------------------------------------------"
echo "sar -r | sed -e \"s|\$(hostname)|hostname|g\""
sar -r | sed -e "s|$(hostname)|hostname|g"
echo
echo "------------------------------------------------------------------"
echo "sar -u | sed -e \"s|\$(hostname)|hostname|g\""
sar -u | sed -e "s|$(hostname)|hostname|g"
echo
echo "------------------------------------------------------------------"
if [ -d /usr/lib/systemd ]; then
echo "top -bHn1 -w200"
top -bHn1 -w200
else
echo "top -bHn1"
top -bHn1
fi
echo
echo "------------------------------------------------------------------"
echo "iotop -bton1 -P"
iotop -bton1 -P
echo
# ensure mysql server is running before triggering mysqlreport output
if [[ "$(cmservice mysql status >/dev/null 2>&1; echo $?)" -eq '0' && -f /root/mysqlreport ]]; then
echo "------------------------------------------------------------------"
echo "mysqlreport"
/root/mysqlreport 2>/dev/null
echo
fi
if [[ "$PT_SUMMARY_REPORT" = [Yy] ]]; then
if [[ "$(uname -m)" = 'x86_64' && ! -f /usr/bin/pt-summary ]]; then
# 64bit OS only
yum -q -y install percona-toolkit --enablerepo=percona-release-x86_64
fi
if [[ "$(cmservice mysql status >/dev/null 2>&1; echo $?)" -eq '0' && -f /usr/bin/pt-summary ]]; then
echo "------------------------------------------------------------------"
/usr/bin/pt-summary 2>/dev/null | sed -e 's|Percona Toolkit ||g'
echo
fi
fi
echo "------------------------------------------------------------------"
echo "pidstat -durh 1 10 | sed -e \"s|\$(hostname)|hostname|g\""
pidstat -durh 1 10 | sed -e "s|$(hostname)|hostname|g"
echo "------------------------------------------------------------------"
echo "Stats saved at: ${CENTMINLOGDIR}/cminfo-top-${DT}.log"
echo "------------------------------------------------------------------"
echo
}
netstat_info() {
sshclient=$(echo $SSH_CLIENT | awk '{print $1}')
nic=$(ifconfig -s 2>&1 | egrep -v '^Iface|^lo|^gre' | awk '{print $1}')
bandwidth_avg=$(sar -n DEV 1 1)
bandwidth_inout=$(echo "$nic" | while read i; do echo "$bandwidth_avg" | grep 'Average:' | awk -v tnic="$i" '$0~tnic{print tnic, "In: ",$5,"Out:",$6}'; done | column -t)
packets_inout=$(echo "$nic" | while read i; do echo "$bandwidth_avg" | grep 'Average:' | awk -v tnic="$i" '$0~tnic{print tnic, "In: ",$3,"Out:",$3}'; done | column -t)
netstat_http=$(netstat -an | fgrep ':80 ')
netstat_https=$(netstat -an | fgrep ':443 ')
netstat_outbound=$(netstat -plant | egrep -v 'and|servers|Address' | awk '{print $5,$6,$7}' | grep -v ':\*' | grep -v '127.0.0.1' | sed -e "s|$sshclient|ssh-client-ip|g" | sort | uniq -c | sort -rn | head -n10 | column -t)
netstat_ips=$(netstat -tn)
netstat_ipstop=$(echo "$netstat_ips" | egrep -v 'servers|Address' | awk '{print $5}' | rev | cut -d: -f2- | rev | sort | uniq -c | sort -rn | head -n10)
netstat_ipstopf=$(echo "$netstat_ipstop" | awk '{"getent hosts " $2 | getline getent_hosts_str; split(getent_hosts_str, getent_hosts_arr, " "); print $1, $2, getent_hosts_arr[2], $3}' | sed -e "s|$sshclient|ssh-client-ip|g" | column -t)
tt_states_http=$(echo "$netstat_http" | awk '{print $6}' | sort | uniq -c | sort -n)
tt_states_https=$(echo "$netstat_https" | awk '{print $6}' | sort | uniq -c | sort -n)
uniq_states_http=$(echo "$netstat_http" | fgrep -v "0.0.0.0" | awk '{print $6}' | sort | uniq -c | sort -n)
uniq_states_https=$(echo "$netstat_https" | fgrep -v "0.0.0.0" | awk '{print $6}' | sort | uniq -c | sort -n)
ttconn_http=$(echo "$tt_states_http" | awk '{sum += $1} END {print sum;}')
ttconn_https=$(echo "$tt_states_https" | awk '{sum += $1} END {print sum;}')
uniqconn_http=$(echo "$uniq_states_http" | awk '{sum += $1} END {print sum;}')
uniqconn_https=$(echo "$uniq_states_https" | awk '{sum += $1} END {print sum;}')
econn_http=$(echo "$tt_states_http" | awk '/ESTABLISHED/ {print $1}')
econn_https=$(echo "$tt_states_https" | awk '/ESTABLISHED/ {print $1}')
wconn_http=$(echo "$tt_states_http" | awk '/TIME_WAIT/ {print $1}')
wconn_https=$(echo "$tt_states_https" | awk '/TIME_WAIT/ {print $1}')
echo "------------------------------------------------------------------"
echo " Centmin Mod Netstat Info:"
echo "------------------------------------------------------------------"
echo -e "\nNetwork Bandwidth In/Out (KB/s):"
echo "$bandwidth_inout"
echo -e "\nNetwork Packets In/Out (pps):"
echo "$packets_inout"
echo -e "\nTotal Connections For:"
echo "Port 80: $ttconn_http"
echo "Port 443: $ttconn_http"
echo -e "\nUnique IP Connections For:"
echo "Port 80: $uniqconn_http"
echo "Port 443: $uniqconn_http"
echo -e "\nEstablished Connections For:"
echo "Port 80: ${econn_http:-0}"
echo "Port 443: ${econn_https:-0}"
echo -e "\nTIME_WAIT Connections For:"
echo "Port 80: ${wconn_http:-0}"
echo "Port 443: ${wconn_https:-0}"
echo -e "\nTop IP Address Connections:"
echo "$netstat_ipstopf"
echo -e "\nTop Outbound Connections:"
echo "$netstat_outbound"
if [ -f /etc/csf/csf.deny ]; then
echo -e "\nTop CSF Firewall Denied Country Codes:"
csfdeny_country=$(grep -oP '(?<=\()[^\)]+' /etc/csf/csf.deny | awk -F "/" 'length($1)<=2 {print $1}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_country"
echo -e "\nTop CSF Firewall Denied Country Codes + Reverse Lookups:"
csfdeny_iplookups=$(grep -oP '(?<=\()[^\)]+' /etc/csf/csf.deny | grep -wv sshd | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_iplookups"
echo -e "\nTop CSF Firewall Denied Distributed sshd Attacks:"
csfdeny_sshdlookups=$(grep 'distributed sshd attacks' /etc/csf/csf.deny | grep -oP '(?<=\()[^\)]+' | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_sshdlookups"
echo -e "\nTop CSF Firewall Denied Distributed sshd Attacks Target Usernames:"
csfdeny_attackusernames=$(grep 'distributed sshd attacks' /etc/csf/csf.deny | grep -oP '(?<=\[)[^\]]+' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_attackusernames"
echo -e "\nTop CSF Firewall Failed SSH Logins:"
csfdeny_sshlogins=$(grep 'Failed SSH login from' /etc/csf/csf.deny | grep -oP '(?<=\()[^\)]+' | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_sshlogins"
echo -e "\nLast 24hrs Top CSF Firewall Denied Country Codes:"
csfdeny_country=$(grep "$(date -d "1 day ago" +"%a %b %-d")" /etc/csf/csf.deny | grep -oP '(?<=\()[^\)]+' | awk -F "/" 'length($1)<=2 {print $1}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_country"
echo -e "\nLast 24hrs Top CSF Firewall Denied Country Codes + Reverse Lookups:"
csfdeny_iplookups=$(grep "$(date -d "1 day ago" +"%a %b %-d")" /etc/csf/csf.deny | grep -oP '(?<=\()[^\)]+' | grep -wv sshd | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_iplookups"
echo -e "\nLast 24hrs Top CSF Firewall Denied Distributed sshd Attacks:"
csfdeny_sshdlookups=$(grep 'distributed sshd attacks' /etc/csf/csf.deny | grep "$(date -d "1 day ago" +"%a %b %-d")" | grep -oP '(?<=\()[^\)]+' | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_sshdlookups"
echo -e "\nLast 24hrs Top CSF Firewall Failed SSH Logins:"
csfdeny_sshlogins=$(grep 'Failed SSH login from' /etc/csf/csf.deny | grep "$(date -d "1 day ago" +"%a %b %-d")" | grep -oP '(?<=\()[^\)]+' | awk -F "/" 'length($1)<=2 {print $1,$2,$3}' | sort | uniq -c | sort -rn | head -n10 | column -t)
echo "$csfdeny_sshlogins"
# STARTD=$(date -d "1440 mins ago" +"%a %b %-d %H:%M")
# ENDD=$(date +"%a %b %-d %H:%M")
fi
}
list_logs() {
echo
echo "List all /root/centminlogs in data ascending order"
ls -lhrt /root/centminlogs
}
setupdate() {
cat > "/usr/bin/cminfo_updater"<<EOF
#!/bin/bash
rm -rf /usr/bin/cminfo
CMINFOLINK='https://raw.githubusercontent.com/centminmod/centminmod/master/tools/cminfo.sh'
# fallback mirror
curl -${ipv_forceopt}Is --connect-timeout 5 --max-time 5 \$CMINFOLINK | grep 'HTTP\/' | grep '200' >/dev/null 2>&1
CMINFO_CURLCHECK=\$?
if [[ "\$CMINFO_CURLCHECK" != '0' ]]; then
CMINFOLINK='https://gitlab.com/centminmod-github-mirror/centminmod/raw/master/tools/cminfo.sh'
fi
wget -q --no-check-certificate -O /usr/bin/cminfo "\$CMINFOLINK"
chmod 0700 /usr/bin/cminfo
EOF
chmod 0700 /usr/bin/cminfo_updater
# echo "cminfo configured"
}
if [ ! -x /usr/bin/cminfo ]; then
chmod 0700 /usr/bin/cminfo
fi
if [ ! -f /usr/bin/cminfo_updater ]; then
setupdate
else
setupdate
fi
if [ ! -f /usr/bin/crontab ]; then
yum -q -y install cronie
fi
# insert itself into cronjob for auto updates
if [[ -z "$(crontab -l 2>&1 | grep cminfo_updater)" ]]; then
crontab -l > cronjoblist
mkdir -p /etc/centminmod/cronjobs
cp cronjoblist /etc/centminmod/cronjobs/cronjoblist-before-cminfo-setup.txt
echo "*/4 * * * * /usr/bin/cminfo_updater 2>/dev/null" >> cronjoblist
cp cronjoblist /etc/centminmod/cronjobs/cronjoblist-after-cminfo-setup.txt
crontab cronjoblist
rm -rf cronjoblist
crontab -l
fi
infooutput() {
VHOSTS=$(ls /home/nginx/domains | egrep -v 'demodomain.com.conf')
VHOSTSCONF=$(ls /usr/local/nginx/conf/conf.d | egrep -vw '^ssl.conf' | uniq)
#####################################################
SYSTYPE=$(virt-what | head -n1)
CENTMINMOD_INFOVER=$(head -n1 /etc/centminmod-release)
CCACHE_INFOVER=$(ccache -V | head -n1)
NGINX_INFOVER=$(nginx -v 2>&1 | awk -F "/" '{print $2}' | head -n1)
PHP_INFOVER=$(php -v 2>&1 | head -n1 | cut -d "(" -f1 | awk '{print $2}')
MARIADB_INFOVER=$(rpm -qa | grep -i MariaDB-server | head -n1 | cut -d '-' -f3)
MEMCACHEDSERVER_INFOVER=$(/usr/local/bin/memcached -h | head -n1 | awk '{print $2}')
CSF_INFOVER=$(csf -v | head -n1 | awk '{print $2}')
SIEGE_INFOVER=$(siege -V 2>&1 | head -n1 | awk '{print $2}')
APC_INFOVER=$(php --ri apc | awk '/Version/ {print $3}' | head -n1)
OPCACHE_INFOVER=$(php -v 2>&1 | grep OPcache | awk '{print $4}' | sed 's/,//')
if [[ "$(which nsd >/dev/null 2>&1; echo $?)" -eq '0' ]]; then
NSD_INFOVER=$(nsd -v 2>&1 | head -n1 | awk '{print $3}')
else
NSD_INFOVER=" - "
fi
# only assign variables if mysql is running
if [[ "$(ps -o comm -C mysqld >/dev/null 2>&1; echo $?)" = '0' ]]; then
DATABSELIST=$(mysql $MYSQLADMINOPT -e 'show databases;' | grep -Ev '(Database|information_schema|performance_schema)')
MYSQLUPTIME=$(mysqladmin $MYSQLADMINOPT ext | awk '/Uptime|Uptime_since_flush_status/ { print $4 }' | head -n1)
MYSQLUPTIMEFORMAT=$(mysqladmin $MYSQLADMINOPT ver | awk '/Uptime/ { print $2, $3, $4, $5, $6, $7, $8, $9 }')
MYSQLSTART=$(mysql $MYSQLADMINOPT -e "SELECT FROM_UNIXTIME(UNIX_TIMESTAMP() - variable_value) AS server_start FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE variable_name='Uptime';" | egrep -Ev '+--|server_start')
fi
PAGESPEEDSTATUS=$(grep 'pagespeed unplugged' /usr/local/nginx/conf/pagespeed.conf)
if [[ -z "$PAGESPEEDSTATUS" ]]; then
PS=ON
else
PS=OFF
fi
if [ -f /usr/local/sbin/maldet ]; then
MALDET_INFOVER=$(/usr/local/sbin/maldet -v | head -n1 | awk '{print $4}')
fi
if [ -f /usr/bin/clamscan ]; then
CLAMAV_INFOVER=$(clamscan -V | head -n1 | awk -F "/" '{print $1}' | awk '{print $2}')
fi
echo "------------------------------------------------------------------"
echo " Centmin Mod Quick Info:"
echo "------------------------------------------------------------------"
echo "Server Location Info"
# echo
curl -${ipv_forceopt}s${CURL_TIMEOUTS} https://ipinfo.io/geo 2>&1 | sed -e 's|[{}]||' -e 's/\(^"\|"\)//g' -e 's|,||' | egrep -v 'phone|postal|loc'
echo
echo "Processors" "physical = ${PHYSICALCPUS}, cores = ${CPUCORES}, virtual = ${VIRTUALCORES}, hyperthreading = ${HT}"
echo
echo "$CPUSPEED"
echo "$CPUMODEL"
echo "$CPUCACHE"
echo ""
if [[ "$CENTOS_SEVEN" = '7' ]]; then
echo -ne " System Up Since: \t"; uptime -s
echo -ne " System Uptime: \t"; uptime -p
else
echo -ne " System Uptime: \t"; uptime | awk '{print $2, $3, $4, $5}'
fi
if [[ "$(ps -o comm -C mysqld >/dev/null 2>&1; echo $?)" = '0' ]]; then
echo -e " MySQL Server Started \t$MYSQLSTART"
echo -e " MySQL Uptime: \t\t$MYSQLUPTIMEFORMAT"
echo -e " MySQL Uptime (secs): \t$MYSQLUPTIME"
else
echo -e " MySQL Server Started \tnot running"
echo -e " MySQL Uptime: \t\tnot running"
echo -e " MySQL Uptime (secs): \tnot running"
fi
echo -e " Server Type: \t\t$SYSTYPE"
echo -e " CentOS Version: \t$CENTOSVER"
echo -e " Centmin Mod: \t\t$CENTMINMOD_INFOVER"
echo -e " Nginx PageSpeed: \t$PS"
echo -e " Nginx Version: \t$NGINX_INFOVER"
echo -e " PHP-FPM Version: \t$PHP_INFOVER"
echo -e " MariaDB Version: \t$MARIADB_INFOVER"
echo -e " CSF Firewall: \t\t$CSF_INFOVER"
echo -e " Memcached Server: \t$MEMCACHEDSERVER_INFOVER"
echo -e " NSD Version: \t\t$NSD_INFOVER"
echo -e " Siege Version: \t$SIEGE_INFOVER"
if [ -f /usr/local/sbin/maldet ]; then
echo -e " Maldet Version: \t$MALDET_INFOVER"
else
echo -e " Maldet Version: \tnot installed"
fi
if [ -f /usr/bin/clamscan ]; then
echo -e " ClamAV Version: \t$CLAMAV_INFOVER"
else
echo -e " ClamAV Version: \tnot installed"
fi
if [[ "$(rpm -qa elasticsearch)" ]]; then
ESEXIST=y
ELASTICSEARCH_INFOVER=$(rpm -qa elasticsearch | awk -F "-" '{print $2}')
echo -e " ElasticSearch: \t$ELASTICSEARCH_INFOVER"
else
echo -e " ElasticSearch: \tnot installed"
fi
echo "------------------------------------------------------------------"
echo
echo "------------------------------------------------------------------"
echo " Site Nginx Vhost Accounts:"
echo "------------------------------------------------------------------"
echo
for d in $VHOSTS; do
echo -n "* $d: ";
tree -dl --noreport -L 1 "/home/nginx/domains/${d}"
done
echo "------------------------------------------------------------------"
echo
echo "------------------------------------------------------------------"
echo " Site Nginx Vhost Config Files:"
echo "------------------------------------------------------------------"
echo
for c in $VHOSTSCONF; do
echo "* /usr/local/nginx/conf/conf.d/$c";
done
if [[ -z "$(cmservice mysql status | grep not)" ]]; then
echo
echo "------------------------------------------------------------------"
echo " MySQL Databases:"
echo "------------------------------------------------------------------"
echo
for db in $DATABSELIST; do
DBIDXSIZE=$(mysql $MYSQLADMINOPT -e "SELECT CONCAT(ROUND(SUM(index_length)/(1024*1024), 2), ' MB') AS 'Total Index Size' FROM information_schema.TABLES WHERE table_schema LIKE '$db';" | egrep -Ev '(+-|Total Index Size)')
DBDATASIZE=$(mysql $MYSQLADMINOPT -e "SELECT CONCAT(ROUND(SUM(data_length)/(1024*1024), 2), ' MB') AS 'Total Data Size'
FROM information_schema.TABLES WHERE table_schema LIKE '$db';" | egrep -Ev '(+-|Total Data Size)')
if [ "$DBIDXSIZE" == 'NULL' ]; then
DBIDXSIZE='0.00 MB'
fi
if [ "$DBDATASIZE" == 'NULL' ]; then
DBDATASIZE='0.00 MB'
fi
echo -e "* $db\t[idx: $DBIDXSIZE data: $DBDATASIZE]";
done
fi
echo
echo "------------------------------------------------------------------"
echo " System User Ids >81:"
echo "------------------------------------------------------------------"
echo
awk -F':' '{ if($3 >= 81) print $0 }' /etc/passwd
if [ -f /usr/bin/pure-pw ]; then
echo
echo "------------------------------------------------------------------"
echo " Pure-FTP Virtual FTP Info:"
echo "------------------------------------------------------------------"
echo
pure-pw list
echo
for u in $(pure-pw list | awk '{print $1}'); do
echo "-------------------------------------"
echo "Virtual FTP user: $u";
echo "password displayed is encrypted";
pure-pw show $u;
done
echo
fi
echo
echo "------------------------------------------------------------------"
echo " Nginx Configuration:"
echo "------------------------------------------------------------------"
echo
nginx -V
echo
echo "------------------------------------------------------------------"
echo " Nginx Settings:"
echo "------------------------------------------------------------------"
echo
egrep '(^user|^worker_processes|^worker_priority|^worker_rlimit_nofile|^timer_resolution|^pcre_jit|^worker_connections|^accept_mutex|^multi_accept|^accept_mutex_delay|map_hash|server_names_hash|variables_hash|tcp_|^limit_|sendfile|server_tokens|keepalive_|lingering_|gzip|client_|connection_pool_size|directio|large_client|types_hash|server_names_hash|open_file|open_log|^include|^#include)' /usr/local/nginx/conf/nginx.conf | egrep -v 'gzip_ratio'
echo
echo "------------------------------------------------------------------"
echo " PHP-FPM Configuration:"
echo "------------------------------------------------------------------"
echo
php -i | grep configure
echo
echo "------------------------------------------------------------------"
echo " PHP-FPM Settings /usr/local/etc/php-fpm.conf:"
echo "------------------------------------------------------------------"
echo
egrep '(^log_level|^pid|^error_log|^user|^group|^listen|^pm|^rlimit|^slowlog|^ping.|^php_admin)' /usr/local/etc/php-fpm.conf
echo
echo "------------------------------------------------------------------"
echo " PHP-FPM Extensions Loaded:"
echo "------------------------------------------------------------------"
echo
php -m
echo
}
debug_menuexit() {
echo
echo "------------------------------------------------------------------"
echo "Debugging centmin.sh menu option 24 exit routine starting"
echo "Please wait until complete..."
echo "------------------------------------------------------------------"
cd /usr/local/src/centminmod
echo 24 | bash -x centmin.sh 2>&1 | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }' 2>&1 > /root/centminlogs/debug-menuexit.txt && echo "Full debug log saved at /root/centminlogs/debug-menuexit.txt"
sed -i "s|$(hostname)|hostname|g" /root/centminlogs/debug-menuexit.txt
echo
echo "Inspect Yum Check Times In debug-menuexit.txt log"
echo
grep -A5 'checking for YUM updates' /root/centminlogs/debug-menuexit.txt
yumstart_time="$(date -d "$(awk '/+ echo \x27 checking for YUM updates/ {print $1,$2}' /root/centminlogs/debug-menuexit.txt)" +%s)"
yumend_time="$(date -d "$(awk '/ UPDATE_CHECK=/ {print $1,$2}' /root/centminlogs/debug-menuexit.txt)" +%s)"
yumcheck_time=$(echo "$yumend_time - $yumstart_time" | bc)
yumcheck_time=$(printf "%0.2f\n" $yumcheck_time)
echo
echo "Yum Check Duration: $yumcheck_time seconds"
echo
echo "------------------------------------------------------------------"
echo "Debugging centmin.sh menu option 24 exit routine completed"
echo "------------------------------------------------------------------"
}
version_log() {
if [ -f /etc/centminmod-versionlog ]; then
echo
echo -e "1st:\n$(head -n1 /etc/centminmod-versionlog)"; echo ".."; echo -e "last 10:\n$(tail -10 /etc/centminmod-versionlog)"
echo
else
echo
echo "error: /etc/centminmod-versionlog is missing"
fi
}
check_version() {
latest_incre=$(curl -4sL https://github.com/centminmod/centminmod/raw/123.09beta01/centmin.sh | awk -F "=" '/SCRIPT_INCREMENTVER=/ {print $2}' | sed -e "s|'||g")
cur_incre=$(awk -F '.b' '{print $3}' /etc/centminmod-release)
latest="123.09beta01.b${latest_incre}"
current="123.09beta01.b${cur_incre}"
if [[ "$cur_incre" -eq "$latest_incre" ]]; then
echo "centminmod latest version $current detected"
exit 0
else
echo "your centminmod version $current is older than latest $latest"
exit 1
fi
}
#########
if [[ -z "$1" ]]; then
infooutput
fi
case "$1" in
info)
infooutput
;;
update)
setupdate
;;
netstat)
netstat_info
;;
top)
{
top_info
} 2>&1 | tee "${CENTMINLOGDIR}/cminfo-top-${DT}.log"
;;
listlogs)
list_logs
;;
debug-menuexit)
debug_menuexit
;;
versions)
version_log
;;
checkver)
check_version
;;
*)
echo "$0 {info|update|netstat|top|listlogs|debug-menuexit|versions|checkver}"
;;
esac