zoukankan      html  css  js  c++  java
  • 04 一键查看服务器资源利用率

    #!/bin/bash
    export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    function cpu() {
        util=`vmstat | awk 'NR==3 {print (100-$15) "%"}'`
        iowait=`vmstat | awk 'NR==3 {print $16 "%"}'`
        echo "CPU - 使用率: $util , 等待磁盘IO响应使用率: $iowait"
    }
    
    function memory() {
        total=`free -m | awk 'NR==2 {printf "%.1f", $2/1024}'`
        used=`free -m | awk 'NR==2 {printf "%.1f", $3/1024}'`
        available=`free -m | awk 'NR==2 {printf "%.1f", ($2-$3)/1024}'`
        echo "内存 - 总大小: ${total}G , 使用: ${used}G , 剩余: ${available}G"
    }
    
    function disk() {
        fs=$(df -h | awk '/^/dev/ {print $1}')
        for p in $fs; do
            mounted=$(df -h | awk '$1=="'$p'" {print $NF}')
            size=$(df -h | awk '$1=="'$p'" {print $2}')
            used=$(df -h | awk '$1=="'$p'" {print $3}')
            used_percent=$(df -h | awk '$1=="'$p'" {print $5}')
            echo "硬盘 - 挂载点: $mounted , 总大小: $size , 使用: $used , 使用率: $used_percent"
        done
    }
    
    function tcp_status() {
        summary=$(ss -antp | awk 'NR>1 {status[$1]++}END{for(i in status) printf i ":" status[i] " , "}')
        echo "TCP连接状态 - $summary"
    }
    
    echo "-------------------------------------------CPU----------------------------------------------"
    cpu
    echo "-------------------------------------------MEMORY-------------------------------------------"
    memory
    echo "-------------------------------------------DISK---------------------------------------------"
    disk
    echo "-------------------------------------------TCP_STATUS---------------------------------------"
    tcp_status
  • 相关阅读:
    HDU 1556 差分,前缀和
    Full permutation
    PAT B1029
    字串简介
    阵列(3)
    完形填空
    关于c的比较
    19 阵列的复制
    switch述句
    阵列变数(2)
  • 原文地址:https://www.cnblogs.com/LiuChang-blog/p/14697930.html
Copyright © 2011-2022 走看看