2016年6月23日 星期四

[Linux] Monitor Linux系統的各種資源狀態


  • 計算網路卡的流量
    #cat /sys/class/net/$nic_dev/statistics/$file

    $file :
    rx_bytes : 目前已接收的bytes
    tx_bytes : 目前已傳輸的bytes
    rx_packets : 目前已接收的packets
    tx_packets : 目前已傳輸的packets

  • 計算網路卡的流量 - Script
    #!/bin/sh

    INTERVAL=1

    nic=$1

    while true
    do
        R1=`cat /sys/class/net/$nic/statistics/rx_bytes`
        T1=`cat /sys/class/net/$nic/statistics/tx_bytes`
        sleep $INTERVAL
        R2=`cat /sys/class/net/$nic/statistics/rx_bytes`
        T2=`cat /sys/class/net/$nic/statistics/tx_bytes`

        RKBPS=$((($R2 - $R1) / 1024))
        TKBPS=$((($T2 - $T1) / 1024))

        echo "TX $nic: $TKBPS kB/s RX $nic: $RKBPS kB/s"
     
    done

  • 計算IO的讀寫量
    #cat /proc/PID/io

    欄位:
    rchar: number of bytes the process read, using any read-like system call (from files, pipes, tty...).
    wchar: number of bytes the process wrote using any write-like system call.
    syscr: number of read-like system call invocations that the process performed.
    syscr: number of write-like system call invocations that the process performed.
    read_bytes: number of bytes the process directly read from disk.
    write_bytes: number of bytes the process originally dirtied in the page-cache (assuming they will go to disk later).
    cancelled_write_bytes: number of bytes the process "un-dirtied" - e.g. using an "ftruncate" call that truncated pages from the page-cache.

沒有留言:

張貼留言