文章目录
man 中文
apt-get install manpages-zh
echo "alias cman='man -M /usr/share/man/zh_CN' " >>.bash_profile
cman vmstat
时间单位
1秒等于1000毫秒
存储单位
byte 字节
一个字节 8 比特
1 byte = 8 bit
1KB=1024B=1024 字节
1MB=1024KB=1024×1024 字节
1GB=1024MB=1024×1024×1024 字节
1TB=1024GB=1024×1024×1024×1024 字节
67108864 字节=67108864/1024/1024=64 MB
iostat
iostat -d -x -k 1
macos 查看指定磁盘io
iostat -d disk2 3
wrk
git clone https://github.com/wg/wrk.git
apt-get install build-essential unzip -y
cd wrk
make
cp wrk /usr/local/bin/
wrk -c 1000 -t 2 http://192.168.1.182/
iperf3
服务端 不区分 tcp or udp
iperf3 -s -i 1 -p 10000
客户端
tcp
iperf3 -c 192.168.1.183 -b 1G -t 15 -P 2 -p 10000
udp
iperf3 -c 192.168.1.183 -b 1G -t 15 -P 2 -p 10000 -u
pktgen
modprobe pktgen
root@ubuntu-192-168-1-182:~# cat pktgen.sh
#!/bin/bash
function pgset() {
local result
echo $1 > $PGDEV
result=`cat $PGDEV | fgrep "Result: OK:"`
if [ "$result" = "" ]; then
cat $PGDEV | fgrep Result:
fi
}
# 为0号线程绑定ens3网卡
PGDEV=/proc/net/pktgen/kpktgend_0
pgset "rem_device_all" # 清空网卡绑定
pgset "add_device ens3" # 添加ens3网卡
# 配置ens3网卡的测试选项
PGDEV=/proc/net/pktgen/ens3
pgset "count 1000000" # 总发包数量
pgset "delay 5000" # 不同包之间的发送延迟(单位纳秒)
pgset "clone_skb 0" # SKB包复制
pgset "pkt_size 64" # 网络包大小
pgset "dst 192.168.1.183" # 目的IP
pgset "dst_mac 52:54:00:3b:88:73" # 目的MAC
# 启动测试
PGDEV=/proc/net/pktgen/pgctrl
pgset "start"
cat /proc/net/pktgen/ens3
bash pktgen.sh
cat /proc/net/pktgen/ens3
numactl
numactl --hardware
bcc-tools
cat /etc/apt/sources.list.d/iovisor.list
deb http://repo.iovisor.org/apt/xenial xenial main
apt-get update
apt-get install -y bcc-tools libbcc-examples linux-headers-$(uname -r)
/usr/share/bcc/tools/
export PATH=$PATH:/usr/share/bcc/tools
pidof
pidof sshd
bindfs
mkdir /tmp/foo
PID=$(docker inspect --format {{.State.Pid}} phpfpm)
bindfs /proc/$PID/root /tmp/foo
perf report --symfs /tmp/foo
# 使用完成后 解除绑定
umount /tmp/foo/
sar
sar -n DEV 1
-n 网络
DEV 接口
1 刷新间隔
sar -n ALL 1
-n { keyword [,...] | ALL }
Report network statistics.
Possible keywords are DEV, EDEV, FC, ICMP, EICMP, ICMP6, EICMP6, IP, EIP, IP6, EIP6, NFS, NFSD, SOCK, SOCK6,
SOFT, TCP, ETCP, UDP and UDP6.
With the DEV keyword, statistics from the network devices are reported.
块设备io 情况
sar -d
sar -p -d 更直观显示
hping3
hping3 -S -p 80 -i u1000 192.168.1.182
目标端口80
-i u1000 (100 packets for second)
-S 设置tcp协议 SYN
pstree
centos
yum -y install psmisc
显示指定进程的父进程
pstree -aps 8244
proc 文件系统
man proc
watch -d cat /proc/interrupts
sysbench
10个现场运行5分钟
sysbench --threads=10 --max-time=300 threads run
vmstat
IO
bi: Blocks received from a block device (blocks/s).
每秒从块设备接收到的块数,单位:块/秒 也就是读块设备。
bo: Blocks sent to a block device (blocks/s).
每秒发送到块设备的块数,单位:块/秒 也就是写块设备。
The first report produced gives averages since the last reboot. Additional reports give information on a sampling
period of length delay. The process and memory reports are instantaneous in either case.
第一个显示内容指出了计算机自上次重启至今的平均使用情况。 后面的每一行信息是按 延时 定期地显示系统的各部分信息。 进程信
息和内存信息都是即时产生的。
-S 以指定单位输出
vmstat: -S requires k, K, m or M (default is KiB)
vmstat -Sm
使输出内容按列上下对齐
vmstat -SM | column -t
间隔5秒输出数据
vmstat 5
System
in: The number of interrupts per second, including the clock. 每秒中断次数
cs: The number of context switches per second.每秒上下文切换次数
Procs
r: The number of runnable processes (running or waiting for run time). 运行和等待运行的进程数(就绪队列,如果超过cpu个数 可能会有问题)
b: The number of processes in uninterruptible sleep.处于不可中断睡眠状态的进程数
stress
模拟cpu 压力
打满一个cpu 持续时间600秒 即 10分钟
stress --cpu 1 --timeout 600
模拟io压力 -i
man stress
-i, --io N
spawn N workers spinning on sync()
用1 个 rync 线程 模拟io 压力
stress -i 1 --timeout 600
stress-ng
apt-get install stress-ng -y
-d N, --hdd N
start N workers continually writing, reading and removing temporary files. The default mode is to stress test
sequential writes and reads. With the --aggressive option enabled without any --hdd-opts options the hdd
stressor will work through all the --hdd-opt options one by one to cover a range of I/O options.
开始N个工作线程不断地写入、读取和删除临时文件。默认模式是压力测试
顺序写入和读取。如果启用了--aggressive选项而没有任何--hdd选项,则选择hdd选项
stressor将逐个处理所有--hdd选项,以涵盖一系列I/O选项。
mpstat
man mpstat
mpstat - Report processors related statistics.
查看所有cpu核心的 统计信息 间隔1s输出一次信息
mpstat -P ALL 1
间隔5秒输出一组数据 共21组
mpstat -P ALL 5 20
pidstat
man pidstat
Report statistics for Linux tasks
以pid 的视角查看系统信息
查看cpu 不加 -u 默认查看也是cpu 信息
pidstat -u
pidstat 2 5
Display five reports of CPU statistics for every active task in the system at two second intervals.
每隔两秒显示系统中每个活动任务的五个CPU统计报告。
共6组数据
pidstat -u 5 2
间隔5秒 显示2组数据 一共显示三组数据
-d 显示 io 信息
pidstat -d
-d Report I/O statistics (kernels 2.6.20 and later only). The following values may be displayed:
pidstat -d -p pid
-w 查看每个进程的上下文切换情况
-w Report task switching activity (kernels 2.6.23 and later only). The following values may be displayed:
UID
The real user identification number of the task being monitored.
USER
The name of the real user owning the task being monitored.
PID
The identification number of the task being monitored.
cswch/s
Total number of voluntary context switches the task made per second. A voluntary context switch occurs
when a task blocks because it requires a resource that is unavailable.
表示每秒自愿上下文切换(voluntary context switches)的次数
nvcswch/s
Total number of non voluntary context switches the task made per second. A involuntary context switch
takes place when a task executes for the duration of its time slice and then is forced to relinquish the
processor.
表示每秒非自愿上下文切换(non voluntary context switches)的次数。
Command
The command name of the task.
-t 查看线程相关信息
pidstat -ut
pidstat -wt
pidstat -p pid
perf
apt install linux-tools-common -y
root@yd:~# uname -r
4.15.0-162-generic
apt-get install linux-cloud-tools-4.15.0-162-generic linux-tools-4.15.0-162-generic -y
perf top -g
perf top -g -p pid
指定pid
perf record -g
perf report -g graph,0.1
ab
ab -c 10 -n 10000 http://192.168.1.187:8080/
并发为10 总数为 10000
opensnoop
https://raw.githubusercontent.com/brendangregg/perf-tools/master/opensnoop
opensnoop
netstat
查看与本机有连接的ip
netstat -ntu
lsof
查看一个端口被哪个进程占用
sudo lsof -i:22
nice
调高sshd 进程nice值
ps -efl | grep sshd
4 S root 4062 1 0 80 0 - 26426 poll_s 05:43 ? 00:00:00 sshd: root@pts/3
4 S root 4510 1 0 80 0 - 18077 poll_s 05:50 ? 00:00:00 /usr/sbin/sshd -D
当前sshd niec 值是0
vim /lib/systemd/system/ssh.service
#ExecStart=/usr/sbin/sshd -D $SSHD_OPTS
ExecStart=/usr/bin/nice -n -2 /usr/sbin/sshd -D $SSHD_OPTS
systemctl daemon-reload
systemctl restart sshd
root@ubuntu-192-168-1-182:~# ps -efl | grep sshd
4 S root 4062 1 0 80 0 - 26426 poll_s 05:43 ? 00:00:00 sshd: root@pts/3
4 S root 4564 1 0 78 -2 - 18077 poll_s 05:53 ? 00:00:00 /usr/sbin/sshd -D
调整为-2
dstat
dstat 2 5
间隔2秒输出5组数据 一共6组数据
strace
strace -p pid