暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Linux OS 系统信息采集列表

digoal 2016-01-26
346

作者

digoal

日期

2016-01-26

标签

PostgreSQL , Linux , 统计信息


背景

bug或可以改进的点

crontab 取的数据不对,只取了ROOT用户的。

dmesg,processes和messages没有取到数据。

numainfo 取的信息不够,只取了编译开关,没有取当前是否使用NUMA,以及NUMA的统计信息。

release 取的路径不正确。

ulimit 取的信息不正确。

分类诊断和规则

cpu

信息来源

诊断和规则

cpuinfo

信息来源

cat /proc/cpuinfo

诊断和规则

判断当前CPU是否处于省电模式(如果cpu MHz比model name的频率小很多,处于省电模式)。

cpu MHz : 2294.227 model name : Intel(R) Xeon(R) CPU E5-2630 0 @ 2.30GHz

建议

cpu的信息建议从lscpu获取,可以更方便的拿到主机使用了几路CPU,每路的物理核数,线程数,总的线程数,是否使用NUMA。

例如

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 24 On-line CPU(s) list: 0-23 Thread(s) per core: 2 Core(s) per socket: 6 CPU socket(s): 2 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 45 Stepping: 7 CPU MHz: 2299.943 BogoMIPS: 4599.38 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 15360K NUMA node0 CPU(s): 0-23

crontab

信息来源

要获取所有用户定义的crontab,遍历 /var/spool/cron 目录下的所有文件,文件名即OS用户名。

要获取系统调度的CRONTAB,遍历/etc/cron.d

要获取crontab的历史调度情况,遍历/var/log/cron

诊断和规则

建议

disk

信息来源

df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 95849872 13525956 77523916 15% / tmpfs 49582476 70988 49511488 1% /dev/shm /dev/sda1 247460 102284 132676 44% /boot /dev/sda5 9968300 531648 8936656 6% /tmp /dev/sda6 9968300 579128 8889176 7% /home /dev/sda11 1632256332 215913356 1416342976 14% /u02 /dev/mapper/cachedev 4098339548 487444860 3405784932 13% /u01

诊断和规则

设置告警阈值,剩余空间,剩余空间百分比。

建议

dmesg

信息来源

dmesg

诊断和规则

查看内核ring buffer中的信息,判断是否出现例如oom,块设备读写错误,进程segment fault等。

iostat

信息来源

iostat -x Linux 2.6.32-220.23.2.ali878.el6.x8664 (rds096023.cloud.cm9) 01/22/2016 _x86_64 (24 CPU) Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util sdb 20.03 132.71 17.45 47.40 1137.02 1592.98 42.10 0.06 0.93 0.57 3.73 sda 0.02 358.05 4.12 399.16 486.40 9879.38 25.70 0.05 0.12 0.10 3.91 fioa 0.02 0.01 165.97 93.37 5311.74 2934.96 31.80 0.05 0.20 0.07 1.84 dm-0 0.00 0.00 200.33 234.34 6348.39 3327.63 22.26 0.05 0.10 0.13 5.51

诊断和规则

首先要

rrqm/s 平均每秒读请求队列长度,太大,说明读请求有堵塞排队现象 wrqm/s 平均每秒写请求队列长度,太大,说明写请求有堵塞排队现象 r/s 当前正在处理的每秒读请求数 w/s 当前正在处理的每秒写请求数 rsec/s 当前正在处理的每秒读扇区数,除以2转换为KB/s wsec/s 当前正在处理的每秒写扇区数,除以2转换为KB/s avgrq-sz 平均每次IO请求(含读写)的扇区数,除以2转换为KB/s avgqu-sz 等待队列中平均每次IO请求(含读写)的扇区数,除以2转换为KB/s await 平均每次IO请求的响应时间,毫秒。(包括IO请求从队列等待到处理结束) svctm 平均每次IO的处理时间,未来不再提供这个值,没有参考价值,请参考await。 %util 块设备的IO综合利用率,可以观察IO是否繁忙,100%表示最繁忙。但是同时请参考await获得IO的响应时间,如果响应时间合理,不必太在意。

主要需要关注的指标 rrqm/s, wrqm/s, await, %util

阈值根据磁盘能力设定

建议

ipcsinfo

信息来源

```
ipcs
------ Shared Memory Segments --------
key shmid owner perms bytes nattch status

------ Semaphore Arrays --------
key semid owner perms nsems
0x00000000 0 root 600 1
0x00000000 32769 root 600 1

------ Message Queues --------
key msqid owner perms used-bytes messages
```

诊断和规则

Shared Memory Segments 已分配的共享内存段 Semaphore Arrays 已分配的信号量

被杀死的进程,如果已分配的共享内存和信号量没有回收,需要使用ipcrm进行回收。

建议

关闭swap

尽量使用hugepage

使用vm.overcommit_memory = 2

从meminfo查看还可以申请的内存大小

CommitLimit: 177897912 kB 可分配 Committed_AS: 72921896 kB 已分配

load

信息来源

uptime 18.54 18.28 20.93 16/7966 33097

诊断和规则

1,5,15 分钟平均负载

表示系统的繁忙程度,建议不要超过主机线程数的3倍。

根据线程数设置阈值。

建议

memory

信息来源

"SwapFree":"7738812","Cached":"13032632","MemTotal":"99164952","MemFree":"30489936","SwapTotal":"7999952","Buffers":"802668"

诊断和规则

SwapTotal - SwapFree 表示已使用的交换分区 Cached 表示已使用OS缓存 MemFree 表示未使用的内存空间

设置swap使用的告警阈值

设置剩余可分配内存的告警阈值

设置脏页告警阈值

建议

通过/proc/meminfo查看更多信息

CommitLimit: 177897912 kB 总可分配的内存(包含SWAP) Committed_AS: 38234788 kB 已分配的内存 Dirty: 1296 kB 脏页

如果内存很大,建议调整后台刷脏页调度。

vm.dirty_background_bytes = 102400000 vm.dirty_ratio = 80 vm.dirty_writeback_centisecs = 50 vm.dirty_expire_centisecs = 6000

message

信息来源

/var/log/messages

诊断和规则

使用sysloger的进程或系统进程的日志输出位置。

一般不建议程序将日志输出到syslog

建议

netinfo, network

信息来源

ifconfig RX packets:163899100279 errors:0 dropped:112 overruns:0 frame:0 TX packets:259329251222 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:30604044742291 (27.8 TiB) TX bytes:122019695323373 (110.9 TiB)

诊断和规则

统计每个端口收发的包,字节数

如果使用了BOND,可以观察数据分发是否均衡

设置网络收发平衡阈值。

建议

numainfo

信息来源

CONFIG_NUMA=y CONFIG_AMD_NUMA=y CONFIG_X86_64_ACPI_NUMA=y CONFIG_ACPI_NUMA=y

诊断和规则

如果应用程序使用NUMA会有性能问题,可以在内核中关闭NUMA ,同时设置内核参数:

vm.zone_reclaim_mode = 0

建议

观察numastat

$numastat node0 numa_hit 39094993830 numa_miss 0 numa_foreign 0 interleave_hit 114006 local_node 39094993830 other_node 0

建议设置numa_miss和numa_foreign告警阈值, 减少跨节点访问内存。

pciinfo

信息来源

诊断和规则

一定要诊断的话,可以收集对应的Kernel driver in use

需要一份driver列表,找到映射关系不正常的设备。

以前遇到过某些设备使用了不正确的driver导致性能问题。需要在/etc/modprobe.d/blacklist.conf 中禁用某些驱动,并重新生成initramfs。

建议

processes

信息来源

诊断和规则

统计每个用户的进程数

统计每个用户的进程状态统计

```
ps -efwaux

D Uninterruptible sleep (usually IO)
R Running or runnable (on run queue)
S Interruptible sleep (waiting for an event to complete)
T Stopped, either by a job control signal or because it is being traced.
W paging (not valid since the 2.6.xx kernel)
X dead (should never be seen)
Z Defunct ("zombie") process, terminated but not reaped by its parent.

For BSD formats and when the stat keyword is used, additional characters may be displayed:
< high-priority (not nice to other users)
N low-priority (nice to other users)
L has pages locked into memory (for real-time and custom IO)
s is a session leader
l is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
+ is in the foreground process group
```

统计D,Z状态进程数,设置阈值。

建议

$pstree init─┬─DragoonAgent─┬─DragoonAgent │ ├─2[DragoonAgent───10[{DragoonAgent}]] │ ├─DragoonAgent───7[{DragoonAgent}] │ └─DragoonAgent───2[{DragoonAgent}] ├─agetty ├─atd ├─crond ├─irqbalance ├─2[iscsid] ├─iscsiuio───3[{iscsiuio}] ├─mcelog ├─6[mingetty] ├─nmon ├─ntpd ├─3[postgres───7[postgres]] ├─4[postgres─┬─5[postgres]] │ └─postgres───5[postgres]] ├─4[postgres─┬─postgres] │ └─postgres───6[postgres]] ├─postgres───5[postgres] ├─2[postgres───6[postgres]] ├─rpcbind ├─screen───4[bash] ├─screen───bash ├─3[ssh] ├─sshd─┬─sshd───sshd───bash │ ├─sshd───sshd───bash───psql │ ├─sshd───sshd───bash───sudo───bash │ └─sshd───sshd─┬─bash───sudo───bash───su───bash │ ├─bash │ └─bash───pstree ├─supervisord.py───python2.7 ├─svscanboot─┬─readproctitle │ └─svscan ├─syslog-ng───syslog-ng ├─udevd───2[udevd] └─7*[vmstat]

release

信息来源

诊断和规则

release 的版本

建议

ulimitinfo

信息来源

core file size (blocks, -c) unlimited data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 1544108 max locked memory (kbytes, -l) unlimited max memory size (kbytes, -m) unlimited open files (-n) 131072 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 131072 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

诊断和规则

如果因为资源限制导致了一些进程的资源使用受限,可以不重启进程修改进程的limits

Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 10485760 unlimited bytes Max core file size unlimited unlimited bytes Max resident set unlimited unlimited bytes Max processes 131072 131072 processes Max open files 131072 131072 files Max locked memory unlimited unlimited bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 1544108 1544108 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us

建议

uname

信息来源

诊断和规则

当前使用的内核版本

建议

uptime

信息来源

诊断和规则

系统已运行时间,正在连接的用户数,1,5,15分钟负载

建议

vmstat

信息来源

procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 77826272 157792 114564800 0 0 87 126 0 0 1 0 99 0 0

诊断和规则

当前处于等待CPU时间片的进程数,不可中断的sleep状态的进程数

Procs r: The number of processes waiting for run time. b: The number of processes in uninterruptible sleep.

内存使用情况

Memory swpd: the amount of virtual memory used. free: the amount of idle memory. buff: the amount of memory used as buffers. cache: the amount of memory used as cache. inact: the amount of inactive memory. (-a option) active: the amount of active memory. (-a option)

交换分区使用情况,如果频繁,建议禁用SWAP,修改内存分配策略和OOM上限。

Swap si: Amount of memory swapped in from disk (/s). so: Amount of memory swapped to disk (/s).

块设备读写请求统计

IO bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s).

中断和上下文切换统计

System in: The number of interrupts per second, including the clock. cs: The number of context switches per second.

CPU占比统计, 分析用户进程和系统进程,IO等待的耗时占比

CPU These are percentages of total CPU time. us: Time spent running non-kernel code. (user time, including nice time) sy: Time spent running kernel code. (system time) id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

建议

其他可用收集的信息建议

进程树

获取已启动的进程结构

meminfo

获取内存状态

sysctl

获取已修改的内核参数

cgroup

获取分组的io,net,mem,cpu资源开销情况

块设备拓扑

使用lsblk可以查看块设备关系

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 1.3T 0 disk ├─sda1 8:1 0 255M 0 part /boot ├─sda2 8:2 0 50G 0 part / ├─sda3 8:3 0 2G 0 part ├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 1.3T 0 part /home sdb 8:16 0 3.1T 0 disk └─sdb1 8:17 0 3.1T 0 part /disk1 sdc 8:32 0 10G 0 disk

块设备健康状态

使用smartctl或RAID卡提供的工具,查看块设备的寿命,读写错误情况。

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论