GithubHelp home page GithubHelp logo

superhj1987 / awesome-scripts Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oldratlee/useful-scripts

439.0 48.0 149.0 8.81 MB

useful scripts for Linux op

License: Apache License 2.0

Shell 4.88% Python 94.91% Makefile 0.03% Java 0.18%
ops devops shell java linux

awesome-scripts's Introduction

awesome-scripts License

GitHub stars GitHub forks

本项目fork自https://github.com/oldratlee/useful-scripts/,现已经用于公司运维环境中,基于原项目所做更新如下:

  • 自安装脚本的修改:self-installer.sh
  • Linux守护进程模板: tpl/run-cmd-tpl
  • 增加脚本统一入口:opscripts
  • 集成开源java运维工具脚本:housemd、greys、sjk、jtop等
  • 部分脚本的编写

运行/安装环境

  • Linux
  • git1.7+

安装

三种方法

  • curl -s "https://raw.githubusercontent.com/superhj1987/awesome-scripts/master/self-installer.sh" | bash -s
  • git/svn checkout the source and make install
  • git/svn checkout the source and set bin to the System Path to use the common usage shells

此外,可以下载和运行单个文件,以show-busy-java-threads为例。

  • 直接运行:
curl -sLk 'https://raw.githubusercontent.com/superhj1987/awesome-scripts/master/java/bin/show-busy-java-threads' | bash
  • 下载单个文件
wget --no-check-certificate https://raw.githubusercontent.com/superhj1987/awesome-scripts/master/java/bin/show-busy-java-threads
	
chmod +x show-busy-java-threads

./show-busy-java-threads

卸载

opscripts uninstall

使用

  • opscripts

show system command

  • opscripts list

show command list

  • opscripts update

update opscripts

命令列表及文档

  1. show-busy-java-threads

    用于快速排查JavaCPU性能问题(top us值过高),自动查出运行的Java进程中消耗CPU多的线程,并打印出其线程栈,从而确定导致性能问题的方法调用。

  2. show-duplicate-java-classes

    找出jar文件和class目录中的重复类。用于排查Java类冲突问题。

  3. find-in-jars

    在目录下所有jar文件里,查找类或资源文件。

  4. housemd

    housemd [pid] [java_home]

    使用housemd对java程序进行运行时跟踪,支持的操作有:

  5. jargrep

    jargrep "text" [path or jarfile]

    在jar包中查找文本,可查找常量字符串、类引用。

  6. findcycle

    findcycle [path]

    查找当前工程中是否存在循环引用(目前仅支持maven工程,默认为当前路径)

  7. jvm

    jvm [pid]

    执行jvm debug工具,包含对java栈、堆、线程、gc等状态的查看,支持的功能有:

    ========线程相关=======
    1 : 查看占用cpu最高的线程情况
    2 : 打印所有线程
    3 : 打印线程数
    4 : 按线程状态统计线程数
    ========GC相关=======
    5 : 垃圾收集统计(包含原因)可以指定间隔时间及执行次数,默认1秒, 10次
    6 : 显示堆中各代的空间可以指定间隔时间及执行次数,默认1秒,5次
    7 : 垃圾收集统计。可以指定间隔时间及执行次数,默认1秒, 10次
    8 : 打印perm区内存情况*会使程序暂停响应*
    9 : 查看directbuffer情况
    ========堆对象相关=======
    10 : dump heap到文件*会使程序暂停响应*默认保存到`pwd`/dump.bin,可指定其它路径
    11 : 触发full gc。*会使程序暂停响应*
    12 : 打印jvm heap统计*会使程序暂停响应*
    13 : 打印jvm heap中top20的对象。*会使程序暂停响应*参数:1:按实例数量排序,2:按内存占用排序,默认为1
    14 : 触发full gc后打印jvm heap中top20的对象。*会使程序暂停响应*参数:1:按实例数量排序,2:按内存占用排序,默认为1
    15 : 输出所有类装载器在perm里产生的对象。可以指定间隔时间及执行次数
    ========其它=======
    16 : 打印finalzer队列情况
    17 : 显示classloader统计
    18 : 显示jit编译统计
    19 : 死锁检测
    20 : 等待X秒,默认为1
    q : exit
    

    进入jvm工具后可以输入序号执行对应命令
    可以一次执行多个命令,用分号";"分隔,如:1;3;4;5;6
    每个命令可以带参数,用冒号":"分隔,同一命令的参数之间用逗号分隔,如:
    Enter command queue:1;5:1000,100;10:/data1/output.bin

  8. greys

    greys [pid][@ip:port]

    使用greys对java程序进行运行时跟踪(不传参数,需要先greys -C pid,再greys)。支持的操作有:

    • 查看加载类,方法信息
    • 查看JVM当前基础信息
    • 方法执行监控(调用量,失败率,响应时间等)
    • 方法执行数据观测、记录与回放(参数,返回结果,异常信息等)
    • 方法调用追踪渲染
    • 详细信息请参考: https://github.com/oldmanpushcart/greys-anatomy/wiki
  9. sjk

    sjk [cmd] [arguments]

    sjk --commands

    sjk --help [cmd]

    使用sjk对Java诊断、性能排查、优化工具

    • ttop:监控指定jvm进程的各个线程的cpu使用情况
    • jps: 强化版
    • hh: jmap -histo强化版
    • gc: 实时报告垃圾回收信息
    • mx: 操作MBean
    • 更多信息请参考: https://github.com/aragozin/jvm-tools
  10. vjmap

    vjmap -all [pid] > /tmp/histo.log

    vjmap -old [pid] > /tmp/histo-old.lo

    vjmap -sur [pid] > /tmp/histo-sur.log

    使用唯品会的vjmap(思路来自于阿里巴巴的TBJMap)查看堆内存的分代占用信息,加强版jmap

    注意:vjmap在执行过程中,会完全停止应用一段时间,必须摘流量执行!!!!

    更多信息请参考: https://github.com/vipshop/vjtools/tree/master/vjmap

  11. vjdump

    vjdump [pid]

    vjdump --liveheap [pid]

    使用唯品会的vjdump一次性快速dump现场信息,包括:

    • JVM启动参数及命令行参数: jinfo -flags [pid]
    • thread dump数据:jstack -l [pid]
    • sjk ttop JVM概况及繁忙线程:sjk ttop -n 1 -ri 3 -p [pid]
    • jmap histo 堆对象统计数据:jmap -histo [pid] & jmap -histo:live [pid]
    • GC日志(如果JVM有设定GC日志输出)
    • heap dump数据(需指定--liveheap开启):jmap -dump:live,format=b,file=[DUMP_FILE] [pid]

    更多信息请参考: https://github.com/vipshop/vjtools/tree/master/vjdump

  12. vjmxcli

    vjmxcli - [host:port] java.lang:type=Memory HeapMemoryUsage

    vjmxcli - [pid] gcutil [interval]

    使用唯品会的vjmxcli获取MBean属性值以及在jstat无法使用时模拟jstat -gcutil。开启jmx时可以使用主机:端口号;未开启jmx则使用pid。

    更多信息请参考: https://github.com/vipshop/vjtools/tree/master/vjmxcli

  1. c

    原样命令行输出,并拷贝标准输出到系统剪贴板,省去CTRL+C操作,优化命令行与其它应用之间的操作流。

  2. colines

    彩色cat出文件行,方便人眼区分不同的行。

  3. a2l

    按行彩色输出参数,方便人眼查看。

  4. ap & rp

    批量转换文件路径为绝对路径/相对路径,会自动跟踪链接并规范化路径。

  5. echo-args

    输出脚本收到的参数,在控制台运行时,把参数值括起的括号显示成 红色,方便人眼查看。用于调试脚本参数输入。

  6. console-text-color-themes

    显示Terminator的全部文字彩色组合的效果及其打印方式。

  7. tcp-connection-state-counter

    统计各个TCP连接状态的个数。用于方便排查系统连接负荷问题。

  8. parseOpts

    命令行选项解析库,加强支持选项有多个值(即数组)。

  9. xpl and xpf

    在命令行中快速完成 在文件浏览器中 打开/选中 指定的文件或文件夹的操作,优化命令行与其它应用之间的操作流。

  10. show-cpu-and-memory

    显示当前cpu和内存使用状况,包括全局和各个进程的。

  11. monitor-host

    监控当前的内存、cpu、io以及网络状况,写入相应的log文件,建议使用crontab,定时调用此脚本。

  12. check-vm

    检查当前linux是否是在虚拟机上,包括openvz/xen、pv/uml、VmWare。

  13. get-pip

    安装pip, 将pip程序封装在了文件中,可以避免网络安装pip过慢。

  14. redis

    redis ip1[:port1][,ip2[:port2]] [port] "command"

    批量执行redis命令(需要redis-cli)

  15. send

    send filename [port]

    使用nc发送文件(默认8888端口),接收方可以通过浏览器下载

  16. hex

    hex [[0x]number[b]]

    计算数字的10进制、16进制及2进制文本,输入参数默认为10进制,可选16进制(0x)及二进制(b)。

  17. swap

    sudo swap [-s [-r]] [-g GREP_ARG]

    查询当前服务器各个进程占用swap的情况。 -s 表示对swap占用量进行排序(升序) -r 表示对swap占用量进行排序(降序),使用-r的前提是-s参数开启。 -g grep命令的封装,用于查找特定类型的进程。比如我想查找带有java的进程,可以使用sudo swap -g java

    使用该功能需要sudo权限

  18. tpl/run-cmd-tpl.sh

    linux下后台执行守护程序的模板shell脚本,修改文件中几个选项的值为需要执行的程序即可使用。

目前VCS的脚本都是svn分支相关的操作。使用更现代的Git吧! 💥

因为不推荐使用svn,这里不再列出有哪些脚本了,如果你有兴趣可以点上面链接去看。

awesome-scripts's People

Contributors

ivanzhangwb avatar khotyn avatar liuyangc3 avatar melin avatar oldratlee avatar silentforce avatar superhj1987 avatar tg123 avatar toolchainx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

awesome-scripts's Issues

最近 show-busy-java-threads.sh 和 find-in-jars.sh 加强了很多,可以考虑合到你的仓库里来

Hi @superhj1987 @lirenzuo

上面的修改是 对原来的使用方式是 兼容 加强的。

PS:

tcp-connection-state-counter.sh 支持Mac了。

其它的加强,看仓库的提交日志吧~

sjk execute error

[root@test opt]# opscripts vjdump --liveheap 18859
==========Thanks to https://github.com/vipshop/vjtools==========
The pid is 18859
2018-12-05 12:57:11 vjdump begin. command interval is 1s.
2018-12-05 12:57:11 Begin to process jstack.
2018-12-05 12:57:11 Finish to process jstack.
/opt/awesome-scripts/java/bin/sjk
2018-12-05 12:57:12 Begin to process sjk ttop.
It will take 3 seconds, please wait.
process top error, now exit.

[root@test opt]# /opt/awesome-scripts/java/bin/sjk ttop -n 1 -ri 3 -p 18859
Site: https://github.com/aragozin/jvm-tools
-n/lib/tools.jar not found!

show-busy-java-threads可以升级一下(终于支持Top的方式来获取CPU了)

@superhj1987 终于支持Top的方式来获取CPU了, #23 这个Issue放了5年…… 😂
# https://github.com/oldratlee/useful-scripts/blob/master/show-busy-java-threads

Change Log

  • New Features
    1. use top command to get percent of thread cpu usage 🎩 #67 #23
      you can use -P, --use-ps option so as to use ps command to find busy thead(cpu usage) instead of top command.
    2. support -S, --jstack-file-dir option to specify the dir for storing jstack output files, and keep files. 🛐
      default store jstack output files at tmp dir, and auto remove after run.
      use this option to keep files so as to review jstack output later.
    3. support -d, --top-delay option to specifies the delay between top samples. 😋
      get thread cpu percentage during this delay interval.
    4. support unlimited use name width(use ps wide output) 🍻
    5. support options -s to specify jstack path, it's convenient when run by sudo
    6. support full options of jstack, like -m/-l 😱
    7. support jstack options -F, force dump 😱
    8. support options -a to append info to log file, so as to review later 😋
  • Bug Fix
    1. fix wrong user bug, when run by sudo -u user_foo
    2. should re-jstack when next update
    3. option parse fail should exit
  • Improvements
    1. check os support, report os unsupported info and exit
    2. improve show-busy-java-threads help format 📚
    3. improve output color 🌈
    4. improve docs
  • Code Cleanup
    1. use ARITHMETIC EVALUATION explicitly instead of -gt etc 🔢
    2. use fatal function to simplify exit logic
    3. main function style 💅
    4. reorder functions
    5. fix typo

更多Change Log参见(From version 1.0.0 to 1.4.0):
https://github.com/oldratlee/useful-scripts/releases

帮助信息

$ show-busy-java-threads -h
Usage: show-busy-java-threads [OPTION]... [delay [count]]
Find out the highest cpu consumed threads of java, and print the stack of these threads.

Example:
  show-busy-java-threads       # show busy java threads info
  show-busy-java-threads 1     # update every 1 second, (stop by eg: CTRL+C)
  show-busy-java-threads 3 10  # update every 3 seconds, update 10 times

Output control:
  -p, --pid <java pid>      find out the highest cpu consumed threads from the specified java process,
                            default from all java process.
  -c, --count <num>         set the thread count to show, default is 5.
  -a, --append-file <file>  specifies the file to append output as log.
  -S, --jstack-file-dir <path>  specifies the directory for storing jstack output files, and keep files.
                            default store jstack output files at tmp dir, and auto remove after run.
                            use this option to keep files so as to review jstack later.
  delay                     the delay between updates in seconds.
  count                     the number of updates.
                            delay/count arguments imitates the style of vmstat command.

jstack control:
  -s, --jstack-path <path>  specifies the path of jstack command.
  -F, --force               set jstack to force a thread dump.
                            use when jstack <pid> does not respond (process is hung).
  -m, --mix-native-frames   set jstack to print both java and native frames (mixed mode).
  -l, --lock-info           set jstack with long listing. Prints additional information about locks.

cpu usage calculation control:
  -d, --top-delay           specifies the delay between top samples, default is 0.5 (second).
                            get thread cpu percentage during this delay interval.
                            more info see top -d option. eg: -d 1 (1 second).
  -P, --use-ps              use ps command to find busy thread(cpu usage) instead of top command,
                            default use top command, because cpu usage of ps command is expressed as
                            the percentage of time spent running during the entire lifetime of a process,
                            this is not ideal.

Miscellaneous:
  -h, --help                display this help and exit.

更多详见文档:
https://github.com/oldratlee/useful-scripts/blob/master/docs/java.md#beer-show-busy-java-threads

opscripts list error

[root@test opt]# opscripts list
Available commands:
============== bin ==============
/opt/awesome-scripts/opscripts-common.sh: line 24: continue: only meaningful in a for', while', or `until' loop

=========== java/bin ============
/opt/awesome-scripts/opscripts-common.sh: line 24: continue: only meaningful in a for', while', or `until' loop

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.