上传文件至 脚本

This commit is contained in:
wxin 2025-04-22 09:59:34 +08:00
parent 8aa2d3c127
commit 82cbb5d06d
5 changed files with 85 additions and 0 deletions

19
脚本/cpu_monitor.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
case "$1" in
idle)
awk '/^cpu / {idle=$5; total=idle+$2+$3+$4+$6+$7+$8; printf "%d\n", (idle*100)/total}' /proc/stat
;;
load1)
awk '{print $1}' /proc/loadavg
;;
load5)
awk '{print $2}' /proc/loadavg
;;
usage)
echo "100 - $(top -bn1 | grep "Cpu(s)" | awk '{print $8}' | cut -d. -f1)" |bc
;;
*)
echo "Usage: $0 {idle|load1|load5|usage}"
exit 1
;;
esac

15
脚本/disk_monitor.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
case "$1" in
usage)
df -h | grep "$2" | awk '{print $5}' | tr -d '%'
;;
iops_read)
iostat -d -k | grep "$2" | awk '{print $4}'
;;
iops_write)
iostat -d -k | grep "$2" | awk '{print $5}'
;;
*)
echo "Usage: $0 {usage <mount_point>|iops_read <device>|iops_write <device>}"
;;
esac

19
脚本/memory_monitor.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
case "$1" in
free)
free -m | awk '/Mem/{print $4}'
;;
total)
free -m | awk '/Mem/{print $2}'
;;
used)
free -m | awk '/Mem/{print $3}'
;;
swap)
free -m | awk '/Swap/{print $3}'
;;
*)
echo "Usage: $0 {free|total|used|swap}"
exit 1
;;
esac

15
脚本/network_monitor.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
interface="$1"
metric="$2"
case "$metric" in
rx)
cat /proc/net/dev | grep "$interface" | awk '{print $2}'
;;
tx)
cat /proc/net/dev | grep "$interface" | awk '{print $10}'
;;
*)
echo "Usage: $0 <interface> {rx|tx}"
exit 1
;;
esac

17
脚本/process_monitor.sh Normal file
View File

@ -0,0 +1,17 @@
#!/bin/bash
process_name="$1"
metric="$2"
case "$metric" in
count)
ps aux | grep -v grep | grep -c "$process_name"
;;
cpu)
ps aux | grep -v grep | grep "$process_name" | awk '{sum += $3} END {print sum}'
;;
mem)
ps aux | grep -v grep | grep "$process_name" | awk '{sum += $4} END {print sum}'
;;
*)
echo "Usage: $0 <process_name> {count|cpu|mem}"
;;
esac