#!/bin/bash
# author: Chiweiming
# version: v1
# date: 2024-03-28
<<COMMAND
監控系統負載,如果系統負載超過 10,記錄系統狀態資訊
1)系統負載命令使用 uptime 看,過去 1 分鐘的平均負載
2)系統狀態使用如下工具標記:top、vmstat、ss
3)要求每隔 20s 監控一次
4)系統狀態資訊需要儲存到指定目錄下,保留 1 個月,檔名建議帶有 date +%s 字尾或者字首
COMMAND
[[ -d /tmp/logs ]] || mkdir -p /tmp/logs
while true
do
load=$(uptime | awk -F 'average: ' '{print $2}'| awk -F ',' '{print $1}' | awk -F '.' '{print $1}')
if [[ ${load} -gt 10 ]]; then
top -bn1 | head -n 100 > /tmp/logs/top.$(date +%s)
vmstat 1 10 > /tmp/logs/vmstat.$(date + %s)
ss -an > /tmp/logs/ss.$(date +%s)
sleep 20
find /tmp/logs \( -name "top*" -o -name "vmstat*" -o -name "ss*" \) -mtime +30 | xargs rm -f
fi
done
shell practice 06
相關文章
- shell practice 03
- shell practice 04
- shell practice 05
- shell practice 07
- Practice
- airflow practiceAI
- scientifically practice DP
- Practice| 流程控制
- 《前端運維》一、Linux基礎--06Shell流程控制前端運維Linux
- Vegetables need more practice.
- 06_SHELL程式設計之CASE語句+函式+正則程式設計函式
- Linux_day06_01_Shell指令碼程式設計_Bash基礎Linux指令碼程式設計
- yolov5s ncnn practiceYOLOCNN
- [#181024][PAT Practice] A+B FormatORM
- Oracle 12.2 RAC on Linux Best Practice DocumentationOracleLinux
- 2024/06/06
- SAP S4HANA LTMC Practice - the first shot!
- 1003 我要通過!| PAT (Basic Level) Practice
- 06
- Operating Systems: Principles and Practice 2nd ed. Edition
- The practice of high-performance graph computing system Plato in Nebula GraphORM
- PAT (Advanced Level) Practice 1149 Dangerous Goods Packaging (25分)Go
- Practice – iOS 專案持續整合實踐(一)iOS
- Practice - iOS 專案持續整合實踐(一)iOS
- 【2024-06-06】認清上進
- 科研日記4【2024-06-06】
- Shell:子shell概念
- 學習進度條2024-06-06
- 每日一個 Golang Packages 06/06 os FileGolangPackage
- WWDC19 06-06 Thursday Session ListSession
- PAT (Basic Level) Practice (中文)-1009-說反話 (20分)
- SDNU_ACM_ICPC_2021_Winter_Practice_4th [個人賽]ACM
- 06進階
- Day......06
- 2024/06/03
- 2024/06/09
- 2024/06/14
- 2024/06/13