一、
一般项目基本完成的时候,后期运维工作的重点就是及时的,合理的频率巡检了,巡检的目的主要是及时发现各种各样的问题
那么,自己编写shell脚本是大部分人的第一选择,这里有个比较麻烦的地方,shell脚本可能巡检的指标不够全面,以及shell脚本难以编写的问题
🆗,这里我推荐大家使用xsos这个软件来简化巡检的工作,很多巡检工作可以使用此工具代替了
二、
xsos的下载地址
https://codeload.github.com/ryran/xsos/tar.gz/refs/tags/v0.7.33
下载完毕后,解压,将xsos这个可执行文件移动到/usr/local/bin/目录下并赋予执行权限即可使用,此软件无需任何依赖,无需任何动态链接库,可以直接使用,非常nice的,主要因为它是其实是一个写的非常长的shell脚本!!!!!!!!!!!!!!!!(有4000多行)
[root@centos7 xsos-0.7.33]# ldd /usr/local/bin/xsos not a dynamic executable
[root@centos7 xsos-0.7.33]# file /usr/local/bin/xsos
/usr/local/bin/xsos: Bourne-Again shell script, UTF-8 Unicode text executable, with very long lines
三、
此软件下载只能在github,其它地方没有发现,需要指出的是,此软件和sosreport这个软件比较类似,是可以基于sosreport命令运行所产生的文件来工作的,当然,xsos单独也是可以工作的
单独运行此软件:
1、获取系统的信息和内存信息
xsos --os --mem
输出如下:
OSHostname: centos7Distro: [redhat-release] CentOS Linux release 7.7.1908 (Core)[centos-release] CentOS Linux release 7.7.1908 (Core)[os-release] CentOS Linux 7 (Core) 7 (Core)RHN: (missing)RHSM: (missing)YUM: 2 enabled plugins: fastestmirror, langpacksRunlevel: N 3 (default multi-user)SELinux: disabled (default disabled)Arch: mach=x86_64 cpu=x86_64 platform=x86_64Kernel:Booted kernel: 3.10.0-1062.el7.x86_64GRUB default: 3.10.0-1062.el7.x86_64 Build version:Linux version 3.10.0-1062.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Wed Aug 7 18:08:02 UTC 2019Booted kernel cmdline:root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rhgb quiet LANG=en_US.UTF-8GRUB default kernel cmdline: root=/dev/mapper/centos-root ro rd.lvm.lv=centos/root rhgb quiet LANG=en_US.UTF-8Taint-check: 0 (kernel untainted)- - - - - - - - - - - - - - - - - - -Sys time: Thu Oct 24 22:28:00 CST 2024Boot time: Thu Oct 24 16:22:10 CST 2024 (epoch: 1729758130)Time Zone: Asia/ShanghaiUptime: 6:05, 2 usersLoadAvg: [4 CPU] 0.07 (2%), 0.07 (2%), 0.06 (2%)/proc/stat:procs_running: 1 procs_blocked: 0 processes [Since boot]: 19286cpu [Utilization since boot]:us 0%, ni 0%, sys 0%, idle 100%, iowait 0%, irq 0%, sftirq 0%, steal 0%MEMORYStats graphed as percent of MemTotal:MemUsed ▊▊▊▊▊▊▊▊▊......................................... 17.3%Buffers .................................................. 0.2%Cached ▊▊▊▊▊............................................. 10.7%HugePages .................................................. 0.0%Dirty .................................................. 0.0%RAM:3.9 GiB total ram0.7 GiB (17%) used0.2 GiB (6%) used excluding Buffers/Cached0 GiB (0%) dirtyHugePages:No ram pre-allocated to HugePagesTHP:0.01 GiB allocated to THP LowMem/Slab/PageTables/Shmem:0.11 GiB (3%) of total ram used for Slab0 GiB (0%) of total ram used for PageTables0.01 GiB (0%) of total ram used for ShmemSwap:No system swap space configured
2、
获取系统的cpu,主板以及网络相关信息
xsos --cpu --lspci --net
输出如下:
[root@centos7 xsos-0.7.33]# xsos --cpu --lspci --net
CPU4 logical processors (4 CPU cores)2 13th Gen Intel Core i7-13700KF (flags: aes,constant_tsc,ht,lm,nx,pae,rdrand,vmx) └─2 threads / 2 cores eachLSPCINet:(1) Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)Storage:(1) VMware SATA AHCI controllerVGA:VMware SVGA II AdapterETHTOOLInterface Status:ens33 0000:02:01.0 link=up rx ring 32/512 drv pcnet32 v1.35 / fw UNKNOWNInterface Errors:[None]SOFTIRQBacklog max is sufficient (Current value: net.core.netdev_max_backlog = 1000)Budget is not sufficient, consider reviewing budget tunable. (Current value: net.core.netdev_budget = 300)(see https://access.redhat.com/solutions/1241943)NETDEVInterface RxMiBytes RxPackets RxErrs RxDrop RxFifo RxComp RxFrame RxMultCast========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 11 11 k 11 (0%) 6 (0%) 0 0 0 0 - - - - - - - - - - - - - - - - -Interface TxMiBytes TxPackets TxErrs TxDrop TxFifo TxComp TxColls TxCarrier ========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 1 5 k 0 0 0 0 0 0 SOCKSTATsockets: used 189TCP: inuse 4 orphan 0 tw 0 alloc 6 mem 5UDP: inuse 0 mem 0UDPLITE: inuse 0RAW: inuse 0FRAG: inuse 0 memory 0IP4Interface Master IF MAC Address MTU State IPv4 Address========= ========= ================= ====== ===== ==================lo - - 65536 up 127.0.0.1/8ens33 - 00:0c:29:90:91:4e 1500 up 192.168.123.17/24SS CHECKSessions:lost reord_seen back_log retrans_total rq tq sock_drop app_limited dsack_dups %CPU %MEM Proto User Local Command Peer ---- ---------- -------- ------------- -- -- --------- ----------- ---------- ---- ----- ---- ----- ---- ---- ------- FIREWALLServices enabled:No firewall services enabled.Rules loaded:No rules loaded.
IFCFGServices enabled:FILE TYPE DEVICE NAME HWADDR ONBOOT DEFROUTE GATEWAY NM_CONTROLLED BOND/TEAM MASTER BRIDGE ETHTOOL PHYSDEV PEERDNS ZONE MTUifcfg-ens33 Ethernet ens33 ens33 - yes yes 192.168.123.2 - - - - - - - - - ifcfg-lo - lo loopback - yes - - - - - - - - - - -
NET STATSTcp.EstabResets: 2TcpExt.DelayedACKs: 40TcpExt.TCPLossProbeRecovery: 3TcpExt.TCPLossProbes: 3TcpExt.TCPLossUndo: 1TcpExt.TCPTimeouts: 1
3、
常用方式
Content options:-a, --all show everything-b, --bios show info from dmidecode-o, --os show hostname, distro, SELinux, kernel info, uptime, etc-k, --kdump inspect kdump configuration-c, --cpu show info from /proc/cpuinfo-m, --mem show info from /proc/meminfo-d, --disks show info from /proc/partitions + dm-multipath synopsis-t, --mpath show info from dm-multipath-l, --lspci show info from lspci-e, --ethtool show info from ethtool-r, --softirq show info from /proc/net/softnet_stat-n, --netdev show info from /proc/net/dev-g, --bonding show info from /proc/net/bonding-i, --ip show info from ip addr (BASH v4+ required)--net alias for: --lspci --ethtool --softirq --netdev --bonding --ip-s, --sysctl show important kernel sysctls-p, --ps inspect running processes via psDisplay options:--scrub-ip remove IP addresses & hostnames from output--scrub-mac remove HW MAC addresses from outputsee XSOS_SCRUB_IP_HN & XSOS_SCRUB_MACADDR env vars-6, --ipv6 parse ip addr output for IPv6 addresses instead of IPv4-q, --wwid=ID restrict dm-multipath output to a particular mpath device,where ID is a wwid, friendly name, or LUN identifier-u, --unit=P change byte display for /proc/meminfo & /proc/net/dev,where P is "b" for byte, or else "k", "m", "g", or "t"-v, --verbose=NUM specify ps verbosity level (0-4, default: 1)-w, --width=NUM change fold-width, in columns (positive number, e.g., 80)"0" disables wrapping, "w" autodetects width (default)-x, --nocolor disable output colorization-y, --less send output to `less -SR`-z, --more send output to `more`Special options (BASH v4+ required):--B=FILE read from FILE containing `dmidecode` dump--C=FILE read from FILE containing /proc/cpuinfo dump--M=FILE read from FILE containing /proc/meminfo dump--D=FILE read from FILE containing /proc/partitions dump--T=FILE read from FILE containing `multipath -v4 -ll` dump--L=FILE read from FILE containing `lspci` dump--R=FILE read from FILE containing /proc/net/softnet_stat dump--N=FILE read from FILE containing /proc/net/dev dump--G=FILE read from FILE containing /proc/net/bonding/xxx dump--I=FILE read from FILE containing `ip addr` dump--P=FILE read from FILE containing `ps aux` dump
例如,简单的查看网络流量情况:
[root@centos7 xsos-0.7.33]# xsos -n
NETDEVInterface RxMiBytes RxPackets RxErrs RxDrop RxFifo RxComp RxFrame RxMultCast========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 11 11 k 11 (0%) 6 (0%) 0 0 0 0 - - - - - - - - - - - - - - - - -Interface TxMiBytes TxPackets TxErrs TxDrop TxFifo TxComp TxColls TxCarrier ========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 1 5 k 0 0 0 0 0 0 SOCKSTATsockets: used 189TCP: inuse 4 orphan 0 tw 0 alloc 6 mem 4UDP: inuse 0 mem 0UDPLITE: inuse 0RAW: inuse 0FRAG: inuse 0 memory 0
简单的查看biso信息:
[root@centos7 xsos-0.7.33]# xsos -b
DMIDECODEBIOS:Vend: Phoenix Technologies LTDVers: 6.00Date: 11/12/2020BIOS Rev: 4.6FW Rev: 0.0System:Mfr: VMware, Inc.Prod: VMware Virtual PlatformVers: NoneSer: VMware-56 4d ea a7 9a 71 34 2d-80 fa b4 13 75 90 91 4eUUID: a7ea4d56-719a-2d34-80fa-b4137590914eCPU:4 of 4 CPU sockets populated, 2 cores/0 threads per CPU8 total cores, 0 total threadsMfr: GenuineIntelFam: UnknownFreq: 3433 MHzVers: 13th Gen Intel(R) Core(TM) i7-13700KFMemory:Total: 4096 MiB (4 GiB)DIMMs: 1 of 192 populatedMaxCapacity: 5120 MiB (5 GiB / 0.00 TiB)
xsos --bios --ip --lspci --ethtool --net --ps 此命令等于xsos -bilenp
xsos --disks --mem --unit=m
输出如下:
[root@centos7 xsos-0.7.33]# xsos --disks --mem --unit=m
MEMORYStats graphed as percent of MemTotal:MemUsed ▊▊▊▊▊▊▊▊▊......................................... 17.3%Buffers .................................................. 0.2%Cached ▊▊▊▊▊............................................. 10.8%HugePages .................................................. 0.0%Dirty .................................................. 0.0%RAM:3950 MiB total ram682 MiB (17.3%) used248 MiB (6.3%) used excluding Buffers/Cached0 MiB (0%) dirtyHugePages:No ram pre-allocated to HugePagesTHP:6 MiB allocated to THP LowMem/Slab/PageTables/Shmem:112 MiB (2.8%) of total ram used for Slab4 MiB (0.1%) of total ram used for PageTables9 MiB (0.2%) of total ram used for ShmemSwap:No system swap space configuredSTORAGEWhole Disks from /proc/partitions:1 disks, totaling 100 GiB (0.10 TiB)- - - - - - - - - - - - - - - - - - - - -Disk Size in GiB---- -----------sda 100Disk layout from lsblk:NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 100G 0 disk ├─sda1 8:1 0 1G 0 part /boot└─sda2 8:2 0 80G 0 part └─centos-root 253:0 0 80G 0 lvm /sr0 11:0 1 4.4G 0 rom /mntFilesystem usage from df:Filesystem 1K-blocks Used Available Use% Mounted on/dev/mapper/centos-root 83845120 1666404 82178716 2% //dev/sr0 4554702 4554702 0 100% /mnt/dev/sda1 1038336 139156 899180 14% /boot
查看网络详情:
xsos --net --unit k
LSPCINet:(1) Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] (rev 10)Storage:(1) VMware SATA AHCI controllerVGA:VMware SVGA II AdapterETHTOOLInterface Status:ens33 0000:02:01.0 link=up rx ring 32/512 drv pcnet32 v1.35 / fw UNKNOWNInterface Errors:[None]SOFTIRQBacklog max is sufficient (Current value: net.core.netdev_max_backlog = 1000)Budget is not sufficient, consider reviewing budget tunable. (Current value: net.core.netdev_budget = 300)(see https://access.redhat.com/solutions/1241943)NETDEVInterface RxKiBytes RxPackets RxErrs RxDrop RxFifo RxComp RxFrame RxMultCast========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 11788 11296 11 (0%) 6 (0%) 0 0 0 0 - - - - - - - - - - - - - - - - -Interface TxKiBytes TxPackets TxErrs TxDrop TxFifo TxComp TxColls TxCarrier ========= ========= ========= ====== ====== ====== ====== ======= ==========ens33 801 5720 0 0 0 0 0 0 SOCKSTATsockets: used 189TCP: inuse 4 orphan 0 tw 0 alloc 6 mem 3UDP: inuse 0 mem 0UDPLITE: inuse 0RAW: inuse 0FRAG: inuse 0 memory 0IP4Interface Master IF MAC Address MTU State IPv4 Address========= ========= ================= ====== ===== ==================lo - - 65536 up 127.0.0.1/8ens33 - 00:0c:29:90:91:4e 1500 up 192.168.123.17/24SS CHECKSessions:lost reord_seen back_log retrans_total rq tq sock_drop app_limited dsack_dups %CPU %MEM Proto User Local Command Peer ---- ---------- -------- ------------- -- -- --------- ----------- ---------- ---- ----- ---- ----- ---- ---- ------- FIREWALLServices enabled:No firewall services enabled.Rules loaded:No rules loaded.
IFCFGServices enabled:FILE TYPE DEVICE NAME HWADDR ONBOOT DEFROUTE GATEWAY NM_CONTROLLED BOND/TEAM MASTER BRIDGE ETHTOOL PHYSDEV PEERDNS ZONE MTUifcfg-ens33 Ethernet ens33 ens33 - yes yes 192.168.123.2 - - - - - - - - - ifcfg-lo - lo loopback - yes - - - - - - - - - - -
NET STATSTcp.EstabResets: 2TcpExt.DelayedACKs: 53TcpExt.TCPLossProbeRecovery: 3TcpExt.TCPLossProbes: 3TcpExt.TCPLossUndo: 1TcpExt.TCPTimeouts: 1
总之,以上参数可以自由搭配组合得出自己喜欢的一个输出内容,从而得到一个自己所期望的巡检结果
该工具还是非常非常nice的哦~~~