Shell scripts monitor Linux system nodes and service CPU memory performance

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.