常用命令总结

0

查看当前Java进程

jps

查看Java线程快照

jstack pid

查看Java内存快照

jmap -histo:live pid

内存快照时间统计

cat file |grep cpu=|grep -Po '(cpu=\d+\.\d+ms)'|grep -Po '(\d+\.\d+)'|awk '{sum += $1}END{print sum}'

关闭JIT

-Djava.compiler=NONE

提交Sonar

mvn sonar:sonar -D "sonar.projectKey=snail" -D "sonar.host.url=http://localhost:9000" -D "sonar.login=token"

消息分类统计

cat snail.log.*|grep -a 处理piece消息|grep TCP|wc -l;cat snail.log.*|grep -a 处理piece消息|grep UTP|wc -l;cat snail.log.*|grep -a 发送piece消息|grep TCP|wc -l;cat snail.log.*|grep -a 发送piece消息|grep UTP|wc -l;

异常分类统计

cat snail.log.* | grep -a Exception | sort | uniq -c | sort

批量查询替换

# sed
sed -i "s/查找内容/替换内容/g" `grep -rl "查找内容" ./`
# vi
# 单行
:s/old/new/g
# 整个文件
:%s/old/new/g

统计日志输出

cat debug.log | grep ' DEBUG ' | awk '{print $5}' | sort | uniq -c | sort

获取进程PID

ps -aux | grep "process name" | grep -v grep | awk '{print $2}'

Linux系统日志

# 查看垃圾文件大小
journalctl --disk-usage
# 保留最近一周日志
journalctl --vacuum-time=1w
# 保留512MB日志
journalctl --vacuum-size=512M

正则表达式提取文本

egrep " (t_\w+) " *.xml -o|sort |uniq -c
grep -E " (t_\w+) " *.xml -o|sort |uniq -c

TAR压缩指定时间文件

tar czvf backtup.tar.gz --newer  "2012-12-12 00:00:00" backup/ 

jstack

按照cpu排序

cat jstack.log | grep cpu | awk -F "\"" '{cpu=$3; name=$2; match(cpu, /cpu=(.*)ms.*/, arr); print arr[1] " " name}'|sort -nk 1