码迷,mamicode.com
首页 > 系统相关 > 详细

获取linux性能数据

时间:2017-06-02 09:58:35      阅读:319      评论:0      收藏:0      [点我收藏+]

标签:map   read   rom   send   socket   UI   mobile   config   __init__   

import re
import os
import sys
import json
import socket
from urllib import request,parse
import urllib
from subprocess import PIPE,Popen
class SendData:
def __init__(self,IpAddr,serverHost,serverPort=8000):
"""


"""
self.result={"system":"linux","Ip":IpAddr}
self.host=serverHost
self.port=serverPort
self.url="http://%s:%s/api/savedata" %(self.host,self.port)
print(self.url)
self.headers={"User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Mobile Safari/537.36"}

def getInfo(self,command):
"""


"""
with os.popen(command) as f:
com=f.read()
return com
def All_Command(self):
commands=[
"hostname",
"ifconfig |awk -F‘ ‘ ‘/HWaddr/{print $5}‘",
"cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c",
"free -m | awk ‘{print $4}‘| sed -n ‘2p‘",
"df -h | awk ‘{print $4}‘|sed -n ‘2p‘",
"uname -r"
]
result=list(map(self.getInfo,commands))
return result

def my_dict(self):
dicts=self.All_Command()
self.result["Host"]=dicts[0].strip()
self.result["Mac"]=dicts[1].strip()
self.result["Cpu"]=dicts[2].strip()
self.result["Mem"]=dicts[3].strip()
self.result["Disk"]=dicts[4].strip()
self.result["Name"]=dicts[5].strip()

return self.result

def sendData(self):
data=parse.urlencode(self.result).encode(‘utf-8‘)
req=request.Request(self.url,headers=self.headers,data=data)
page=request.urlopen(req).read()
return page

 


s=SendData("192.168.1.23","192.168.1.102")
print(s.sendData())

获取linux性能数据

标签:map   read   rom   send   socket   UI   mobile   config   __init__   

原文地址:http://www.cnblogs.com/yingdiblog/p/6931583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!