[项目] server.scripts.cpu_sub.py(LOAMAW v1.0)

import subprocess

def script_cpu_core(cpu_server_name):
    cpu_core_out = subprocess.check_output('ansible -m shell -a \'cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l\' %s | tail -1'%cpu_server_name, shell=True)
    return(cpu_core_out)

def script_cpu_qty(qty_server_name):
    cpu_qty_out = subprocess.check_output('ansible -m shell -a \'cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l\' %s | tail -1'%qty_server_name, shell=True)
    return(cpu_qty_out)

def script_cpu_usage(cpu_usage_server_name):
    cpu_usage_out = subprocess.check_output('ansible -m shell -a \'top -bn 1\' %s | grep \'Cpu\' | awk -F\',\' \'{print $1 }\' | awk \'{print $2}\''%cpu_usage_server_name, shell=True)
    return(cpu_usage_out)

def script_cpu_idleness(cpu_idleness_server_name):
    cpu_idleness_out = subprocess.check_output('ansible -m shell -a \'top -bn 1\' %s | grep \'Cpu\' | awk -F\',\' \'{print $4 }\' | awk \'{print $1}\''%cpu_idleness_server_name, shell=True)
    return(cpu_idleness_out)