Shell scripts monitor Linux system nodes and service CPU memory performance
1. Obtain information
#! /Bin/bash # Description: # enter the top information into a file # Author: lone boat # version: 1.0 # Creation Time: 03: 04: 28 PATH =/bin: /sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Binexport PATHp = 'pwd' Day = 'date + "% Y % m % d" 'host = 'hostname' for (I = 0; I <1440; I = I + 1) do echo "Date 'date +" % Y-% m-% d % H: % M: % S "'" >>$ p/$Day-top.txt top c-bn1 >>$ p/$Day-top.txt sleep 1 done
2. filter information
#! /Bin/bash # Description: # Author: Standalone # version: 1.0 # Creation Time: 04: 08: 52 PATH =/bin:/sbin:/usr/bin: /usr/sbin:/usr/local/bin:/usr/local/sbin :~ /Binexport PATHp = 'pwd' Day = 'date + "% Y % m % d" 'host = 'hostname' mkdir-p $ p/$ HOST-$ DayPT = $ p /$ HOST-$ Daycd $ PTcat $ p/$1 | grep-v grep | grep "^ Date"> $ PT/time-0000day.txt cat $ p/$1 | grep-v grep | grep "^ Cpu (s): ">>$ PT/cpu-1_day.txt cat $ p/$1 | grep-v grep | grep" ^ Mem: ">>$ PT/mem-domainday.txt cat $ p/$1 | grep-v grep | grep" ^ Swap: ">>$ PT/cache-domainday.txt while read linedo cat $ p/$1 | grep-v grep | grep" $ line ">>>$ PT/$line-domainday.txt done <$ p/service.txt # here service.txt is the service name stored by row cd $ p
3. Sort data
For example, you can use Excel to sort out memory usage. Here, you can place the obtained time and memory information in Excel and separate the memory columns with Excel, you can create a memory usage trend chart using the time and memory size columns. Similarly, you can also create CPU, cached, and CPU and memory trend charts for various microservices.