• 结合zabbix统计/proc/meminfo文件中的内容


    vim memory_status.sh

    #!/bin/bash   #脚本解释器说明
    MemTotal(){
            awk '/^MemTotal/{print $2}' /proc/meminfo    #打印/proc/meminfo文件中以MemTotal开头行的以空格分割的第二列元素的值,单位为kb
    } 
    $
    1 #第一个位置参数,位置参数的值为相应函数名,则会调用相应函数

    :wq!

    chmod +x memory_status.sh

    执行命令:

    ./memory_status.sh MemTotal   获取 /proc/meminfo 文件中 MemTotal 字段的值

    全部内容

    #!/bin/bash
    MemTotal(){
        awk '/^MemTotal/{print $2}' /proc/meminfo
    }
    
    MemFree(){
            awk '/^MemFree/{print $2}' /proc/meminfo  
    }
        
    
    MemAvailable(){
            awk '/^MemAvailable/{print $2}' /proc/meminfo  
    }
        
    
    Buffers(){
            awk '/^Buffers/{print $2}' /proc/meminfo  
    }
        
    
    Cached(){
            awk '/^Cached/{print $2}' /proc/meminfo  
    }
        
    
    SwapCached(){
            awk '/^SwapCached/{print $2}' /proc/meminfo  
    }
        
    
    Active(){
            awk '/^Active/{print $2}' /proc/meminfo  
    }
        
    
    Inactive(){
            awk '/^Inactive/{print $2}' /proc/meminfo  
    }
        
    
    #Active(anon)(){
    #        awk '/^Active(anon)/{print $2}' /proc/meminfo  
    #}
    #    
    #
    #Inactive(anon)(){
    #        awk '/^Inactive(anon)/{print $2}' /proc/meminfo  
    #}
    #    
    #
    #Active(file)(){
    #        awk '/^Active(file)/{print $2}' /proc/meminfo  
    #}
    #    
    #
    #Inactive(file)(){
    #        awk '/^Inactive(file)/{print $2}' /proc/meminfo  
    #}
        
    
    Unevictable(){
            awk '/^Unevictable/{print $2}' /proc/meminfo  
    }
        
    
    Mlocked(){
            awk '/^Mlocked/{print $2}' /proc/meminfo  
    }
        
    
    SwapTotal(){
            awk '/^SwapTotal/{print $2}' /proc/meminfo  
    }
        
    
    SwapFree(){
            awk '/^SwapFree/{print $2}' /proc/meminfo  
    }
        
    
    Dirty(){
            awk '/^Dirty/{print $2}' /proc/meminfo  
    }
        
    
    Writeback(){
            awk '/^Writeback/{print $2}' /proc/meminfo  
    }
        
    
    AnonPages(){
            awk '/^AnonPages/{print $2}' /proc/meminfo  
    }
        
    
    Mapped(){
            awk '/^Mapped/{print $2}' /proc/meminfo  
    }
        
    
    Shmem(){
            awk '/^Shmem/{print $2}' /proc/meminfo  
    }
        
    
    Slab(){
            awk '/^Slab/{print $2}' /proc/meminfo  
    }
        
    
    SReclaimable(){
            awk '/^SReclaimable/{print $2}' /proc/meminfo  
    }
        
    
    SUnreclaim(){
            awk '/^SUnreclaim/{print $2}' /proc/meminfo  
    }
        
    
    KernelStack(){
            awk '/^KernelStack/{print $2}' /proc/meminfo  
    }
        
    
    PageTables(){
            awk '/^PageTables/{print $2}' /proc/meminfo  
    }
        
    
    NFS_Unstable(){
            awk '/^NFS_Unstable/{print $2}' /proc/meminfo  
    }
        
    
    Bounce(){
            awk '/^Bounce/{print $2}' /proc/meminfo  
    }
        
    
    WritebackTmp(){
            awk '/^WritebackTmp/{print $2}' /proc/meminfo  
    }
        
    
    CommitLimit(){
            awk '/^CommitLimit/{print $2}' /proc/meminfo  
    }
        
    
    Committed_AS(){
            awk '/^Committed_AS/{print $2}' /proc/meminfo  
    }
        
    
    VmallocTotal(){
            awk '/^VmallocTotal/{print $2}' /proc/meminfo  
    }
        
    
    VmallocUsed(){
            awk '/^VmallocUsed/{print $2}' /proc/meminfo  
    }
        
    
    VmallocChunk(){
            awk '/^VmallocChunk/{print $2}' /proc/meminfo  
    }
        
    
    HardwareCorrupted(){
            awk '/^HardwareCorrupted/{print $2}' /proc/meminfo  
    }
        
    
    AnonHugePages(){
            awk '/^AnonHugePages/{print $2}' /proc/meminfo  
    }
        
    
    CmaTotal(){
            awk '/^CmaTotal/{print $2}' /proc/meminfo  
    }
        
    
    CmaFree(){
            awk '/^CmaFree/{print $2}' /proc/meminfo  
    }
        
    
    HugePages_Total(){
            awk '/^HugePages_Total/{print $2}' /proc/meminfo  
    }
        
    
    HugePages_Free(){
            awk '/^HugePages_Free/{print $2}' /proc/meminfo  
    }
        
    
    HugePages_Rsvd(){
            awk '/^HugePages_Rsvd/{print $2}' /proc/meminfo  
    }
        
    
    HugePages_Surp(){
            awk '/^HugePages_Surp/{print $2}' /proc/meminfo  
    }
        
    
    Hugepagesize(){
            awk '/^Hugepagesize/{print $2}' /proc/meminfo  
    }
        
    
    DirectMap4k(){
            awk '/^DirectMap4k/{print $2}' /proc/meminfo  
    }
        
    
    DirectMap2M(){
            awk '/^DirectMap2M/{print $2}' /proc/meminfo  
    }
        
    $1
  • 相关阅读:
    ElasticSearch-生命周期管理
    Alpha 冲刺五
    Alpha 冲刺四
    Alpha 冲刺三
    Alpha 冲刺二
    Alpha 冲刺一
    测试随笔
    校友录
    项目需求分析(淘校)
    团队选题报告(淘校)
  • 原文地址:https://www.cnblogs.com/jingzaixin/p/12552171.html
Copyright © 2020-2023  润新知