开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (1)
master
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (1)
master
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (1)
master
msydWork
/
linuxTop.py
msydWork
/
linuxTop.py
linuxTop.py 4.65 KB
一键复制 编辑 原始数据 按行查看 历史
Gavan 提交于 2020年11月25日 16:40 +08:00 . 1
# -!- coding: utf-8 -!-
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
#作者:cacho_37967865
#博客:https://blog.csdn.net/sinat_37967865
#文件:linuxTop.py
#日期:2019年05月20日
#备注:发起性能测试前,top -b -d 1 > /data/top500.txt将性能信息重定向文件,然后发起性能测试;最后将文件的内容整理后存入到数据库。
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
import re
import pymysql
db = pymysql.connect(
host="localhost",
user="root",
password="123456",
port=3306,
use_unicode=True,
charset="utf8",
database="cacho")
cursor = db.cursor()
def createTable():
sql1 = 'drop table if exists linux_top;'
sql2 = 'create table linux_top(top_time VARCHAR(32),binfa_num int,average1 float,average5 float,average15 float,us_cpu VARCHAR(15),' \
'sy_cpu VARCHAR(15),wa_cpu VARCHAR(15),ni_cpu VARCHAR(15),id_cpu VARCHAR(15),hi_cpu VARCHAR(15),si_cpu VARCHAR(15),' \
'st_cpu VARCHAR(15),men_total VARCHAR(25),men_used VARCHAR(20),men_free VARCHAR(20),men_buffers VARCHAR(20),PRIMARY KEY (top_time));'
cursor.execute(sql1)
cursor.execute(sql2)
db.commit()
def insert_data(top_time,binfa_num,average1,average5,average15,us_cpu,sy_cpu,wa_cpu,ni_cpu,id_cpu,hi_cpu,si_cpu,st_cpu,men_total,men_used,men_free,men_buffers):
sql = "insert into linux_top(top_time,binfa_num,average1,average5,average15,us_cpu,sy_cpu,wa_cpu,ni_cpu,id_cpu,hi_cpu,si_cpu,st_cpu,men_total,men_used,men_free,men_buffers) " \
"values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" \
% (top_time,binfa_num,average1,average5,average15,us_cpu,sy_cpu,wa_cpu,ni_cpu,id_cpu,hi_cpu,si_cpu,st_cpu,men_total,men_used,men_free,men_buffers)
try:
cursor.execute(sql)
except Exception as e:
# 发生错误时回滚
db.rollback()
print(str(e))
else:
db.commit() # 事务提交
def get_auditTime(file,date):
logs = open(file, 'r' ,encoding= 'utf8')
load = []
try:
for line in logs.readlines():
line = line.rstrip()
if line[0:3] == 'top':
top_time = date + line[6:14]
#load_average = line[-16:]
average1 = line[-16:-12]
average5 = line[-10:-6]
average15 = line[-4:]
print(average1,average5,average15)
row = []
row.append(top_time)
row.append(average1)
row.append(average5)
row.append(average15)
elif line[0:6] == 'Cpu(s)':
line = line.replace('Cpu(s): ','')
us_cpu = re.findall(r'(\d.*)us',line)[0]
sy_cpu = re.findall(r'us, *(\d.*)sy',line)[0]
wa_cpu = re.findall(r'id, *(\d.*)wa', line)[0]
ni_cpu = re.findall(r'sy, *(\d.*)ni',line)[0]
id_cpu = re.findall(r'ni, *(\d.*)id', line)[0]
hi_cpu = re.findall(r'wa, *(\d.*)hi', line)[0]
si_cpu = re.findall(r'hi, *(\d.*)si', line)[0]
st_cpu = re.findall(r'si, *(\d.*)st', line)[0]
row.append(us_cpu)
row.append(sy_cpu)
row.append(wa_cpu)
row.append(ni_cpu)
row.append(id_cpu)
row.append(hi_cpu)
row.append(si_cpu)
row.append(st_cpu)
#print(line)
#print(us_cpu,'-->'+sy_cpu,'-->'+ni_cpu,'-->'+id_cpu,'-->'+wa_cpu,'-->'+hi_cpu,'-->'+si_cpu,'-->'+st_cpu)
elif line[0:4] == 'Mem:':
#print(line)
men_total = re.findall(r' *(\d.*)total',line)[0]
men_used = re.findall(r'total, *(\d.*)used', line)[0]
men_free = re.findall(r'used, *(\d.*)free', line)[0]
men_buffers = re.findall(r'free, *(\d.*)buffers', line)[0]
row.append(men_total)
row.append(men_used)
row.append(men_free)
row.append(men_buffers)
#print(men_total, men_used, men_free, men_buffers)
#print(row)
load.append(row)
finally:
logs.close()
return load
if __name__ == '__main__':
createTable()
top_info = get_auditTime('E:\zenglingwei\\top.txt','2019-08-13 ')
for info in top_info:
insert_data(info[0], 3385, float(info[1]), float(info[2]), float(info[3]), info[4], info[5], info[6], info[7], info[8],
info[9],info[10], info[11], info[12], info[13],info[14],info[15])
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

测试工作中接口和性能测试代码
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Cacho/msydWork.git
git@gitee.com:Cacho/msydWork.git
Cacho
msydWork
PythonProject-msydWork
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /