zoukankan      html  css  js  c++  java
  • PLAYBOOK 命令统计资源利用率 输出本地文件 flask展示

    使用 Ansible 统计服务器资源利用率:

    3 条 shell 脚本实现统计:

    CPU 利用率统计

    top -bn1 | grep load | awk '{printf "CPU Load: %.2f ", $(NF-2)}'

    内存利用率统计:

    free -m | awk 'NR==2{printf "Memory Usage: %s/%sMB (%.2f%%) ", $3,$2,$3*100/$2 }'

    磁盘利用率统计(列出每块磁盘利用率):

    df -h -t ext2 -t ext4 | grep -vE '^Filesystem|tmpfs|cdrom' awk '{ print "Disk Usage:"" " $1 " " $3"/"$2" ""("$5")"}'
    ---
    - name: test
      hosts: localhost
      tasks:
        - name: disk_detail
    shell: df -h -t ext2 -t ext4 | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print "Disk Usage:"" " $1 " " $3"/"$2" ""("$5")"}'
    register: disk_detail
        - name: cpu_detail
    shell: top -bn1 | grep load | awk '{printf "CPU Load %.2f
    ", $(NF-2)}'
    register: cpu_detail
        - name: memory_detail
    shell: free -m | awk 'NR==2{printf "Memory Usage %s/%sMB (%.2f%%)
    ", $3,$2,$3*100/$2 }'
    register: memory_detail
        - name: resultcopy:content: ><p>{{ansible_facts.default_ipv4.address}}</p><p>{{disk_detail.stdout_lines}}</p><p>{{cpu_detail.stdout_lines}}</p><p>{{memory_detail.stdout_lines}}</p><p>-------------------------------------</p>dest: /root/flask/static/content.html

    PLAYBOOK 文件编写 将资源利用率输出到 falsk static文件夹内 

    from flask import Flask
    import os
    from flask import make_response
    from flask import render_template
    
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        APP_ROOT = os.path.dirname(os.path.abspath(__file__))   # refers to application_top
        APP_STATIC = os.path.join(APP_ROOT, 'static')
        with open(os.path.join(APP_STATIC, 'content.html')) as f:response = f.read()
        return response
    
    
    if __name__ == '__main__':
        app.run(debug=True,host='10.130.130.80',port=5003)

    简单的flask小项目 可供访问

  • 相关阅读:
    hdu 1548 升降梯
    hdu 2544 hdu 1874 poj 2387 Dijkstra 模板题
    hdu 4463 有一条边必须加上 (2012杭州区域赛K题)
    poj 1679 判断MST是不是唯一的 (次小生成树)
    poj 1751 输出MST中新加入的边
    poj 2349 求MST中第S大的权值
    HDU 4389 X mod f(x) (数位DP)
    HDU 5908 Abelian Period (暴力)
    HDU 5907 Find Q (水题)
    HDU 4514 湫湫系列故事――设计风景线 (树形DP)
  • 原文地址:https://www.cnblogs.com/oscarli/p/13181594.html
Copyright © 2011-2022 走看看