linux查询tcp异常,linux服务器内存cpu 流量tcp异常信息记录python脚本
#!/usr/bin/python
#coding:utf-8
import commands
import os
import re
import datetime
#if mem util > 30 echo to mem_file_report and cpu util
mem_info = commands.getstatusoutput(‘top -b|head -n30|tail -n24‘)
info = mem_info[1].split(‘\n‘)
count = 0
num = 0
for i in info:
if count == 0:
global header
header = i
if count >= 1:
i_list = i.split()
num_mem = i_list[9].split(‘.‘)[0]
num_cpu = i_list[8].split(‘.‘)[0]
if int(num_mem) >= 40 or int(num_cpu) >= 50:
with open(‘/opt/scripts/mem_cpu_tcp_check.log‘,‘a‘) as f:
result = "%s %s"%(datetime.datetime.now(),i)
f.write(result + ‘\n‘)
num+=1
if count >= 23 and num >= 1:
with open(‘/opt/scripts/mem_cpu_tcp_check.log‘,‘a‘) as f:
result1 = "%s %s"%(datetime.datetime.now(),header)
f.write(‘\n‘ + result1 + ‘\n‘ + ‘=========================================================‘ + ‘\n‘)
count+=1
#tcp 连接信息详情
tcp_num = commands.getstatusoutput("netstat -antupl|grep ESTABLISHED|wc -l")
#print tcp_num[1]
tcp_info = commands.getstatusoutput("netstat -antupl|grep ESTABLISHED")
if int(tcp_num[1]) >= 100:
with open(‘/opt/scripts/tcp_check.log‘,‘a‘) as f:
f.write(‘\n‘ + "============================================================" + ‘\n‘ + str(datetime.datetime.now()) + ‘\n‘ + tcp_info[1])
interface liuliang warning
liuliang = commands.getstatusoutput("iftop -i eth0 -N -P -t -L 50 -s 10")
#liuliang_list = liuliang[1].split(‘\n‘)
#print liuliang[1]
#for i in liuliang_list:
new_num = i.split()[4]
new_num1 = re.findall(r‘\d+‘,new_num)[0]
print new_num1
if int(new_num1) == 0:
liuliang_list.remove(i)
#print ‘\n‘.join(liuliang_list)
receive = liuliang[1].split(‘\n‘)[-7].split()[5]
send = liuliang[1].split(‘\n‘)[-6].split()[5]
#print liuliang[1].split(‘\n‘)[-7].split()[5]
#print liuliang[1].split(‘\n‘)[-6].split()[5]
receive_type = re.findall("Kb|Mb|Gb",receive)[0]
send_type = re.findall("Kb|Mb|Gb",send)[0]
#print re.findall(r‘\d+‘,receive)
#print re.findall(r‘\d+‘,send)
receive_num = re.findall(r‘\d+‘,receive)[0]
send_num = re.findall(r‘\d+‘,send)[0]
if receive_type == "Mb" and send_type == "Mb":
if int(receive_num) >= 40 and int(send_num) >= 40:
with open(‘/opt/scripts/iftop.log‘,‘a‘) as f:
result1 = "%s %s"%(datetime.datetime.now(),header)
time_now = str(datetime.datetime.now())
f.write(‘\n‘ + ‘=========================================================‘ + ‘\n‘ + time_now + ‘\n‘ + liuliang[1])
if receive_type == "Gb" and send_type == "Gb":with open(‘/opt/scripts/iftop.log‘,‘a‘) as f:result1 = "%s %s"%(datetime.datetime.now(),header)time_now = str(datetime.datetime.now())f.write(‘\n‘ + ‘=========================================================‘ + ‘\n‘ + time_now + ‘\n‘ + liuliang[1])
linux查询tcp异常,linux服务器内存cpu 流量tcp异常信息记录python脚本相关推荐
- linux命令查询端口号,linux查询端口号(linux查看端口的命令)
linux查询端口号(linux查看端口的命令) 2020-07-24 11:55:46 共10个回答 1.打开任务管理器(在桌面最下面的"任务栏"右击鼠标).2.在任务管理器界面 ...
- 【Linux 性能优化】利用perf和CPU使用率定位异常函数
博主未授权任何人或组织机构转载博主任何原创文章,感谢各位对原创的支持! 博主链接 文章目录 CPU 使用率 进程运行情况查询 使用工具查看CPU使用率 定位导致CPU 使用率过高的函数 perf to ...
- 内存占用少的linux桌面,不同桌面环境占用内存/CPU对比
不同桌面环境占用内存/CPU对比 May 31, 2016 Technology 对比xfce4, lxde, gnome, mate等桌面环境占用内存/CPU对比 先决条件 使用vagrant的镜像 ...
- linux 查询日志 去重,linux命令(12)uniq去重
实例详细说明linux下去除重复行命令uniq 一,uniq干什么用的 文本中的重复行,基本上不是我们所要的,所以就要去除掉.linux下有其他命令可以去除重复行,但是我觉得uniq还是比较方便的一个 ...
- 电脑linux查询配置参数,linux,windows keepalive参数的查看与设置
---------------------------------------------------------------------------------------------------- ...
- 腾讯云轻量8核16G18M服务器带宽CPU流量性能测评
腾讯云轻量应用服务器8核16G18M带宽,18M公网带宽下载速度峰值可达2304KB/秒,折合2.25M/s,系统盘为270GB SSD盘,3500GB月流量,折合每天116GB流量.腾讯云百科分享腾 ...
- 腾讯云2核2G4M轻量服务器带宽CPU流量系统盘性能测评
腾讯云轻量2核2G4M服务器自带4M公网带宽,下载速度可达512KB/秒,100%CPU性能,系统盘为50GB SSD盘,300GB月流量,折合每天10G流量,地域节点可选上海/广州/北京.腾讯云百科 ...
- Jmeter分布式压测-windows(master控制机)多个linux(slaves负载机)监测服务器资源(cpu、内存等)
为什么进行jmeter分布式压测? 一.干货解释原因: **原因一:**一台压力机的 Jmeter 默认最大支持 1000 左右的并发用户数(线程数),再大的话,容易造成卡顿.无响应等情况,这是受限于 ...
- linux查询内存条个数,linux下查看内存条数及每根内存大小的实现方法(推荐)
在linux系统中,查看内存条个数,及每根内存的大小,可以使用dmidecode命令. 如下: #dmidecode | grep -A16 "Memory Device$" 输出 ...
最新文章
- Java项目:健身俱乐部管理系统(java+SSM+Mysql+Jsp)
- Too many levels of symbolic links
- 数据结构与算法:二分查找
- poj2739(尺取法+质数筛)
- js null ,null没有typeof返回值为undefine 即 null没有返回类型的
- 深入理解分布式技术 - 探究缓存穿透、缓存击穿、缓存雪崩解决方案
- 类的成员函数与内联以及静态成员
- TensorFlow(4)-TFRecord
- C#常用类 改配置文件
- 《越狱》完结 米帅迷应小心纹身网站挂马
- 网络协议笔记-数据链路层
- asterisk积累命令
- 做好开源项目 需要坚持
- Vue集成微信开发趟坑:公众号以及JSSDK相关
- Dxg——Keil 单片机 开发笔记整理分类合集【所有的相关记录,都整理在此】
- 公众号网页能调用银联支付么_支付宝新一代刷脸支付硬件发布,自带“轮子”,三天就能开发小程序...
- MSAgent 详细解说(上)
- c语言程序设计在未来前景,转型背景下C程序设计课程的实施方案
- 内部UML培训文件,欢迎大家批评指正
- u盘安装grub linux,U盘安装的引导搞错了
热门文章
- Qt QtCreator 所有版本官方下载地址
- vue+axios请求时设置request header请求头(带上token)
- ASP.NET MVC中使用Autofac实现简单依赖注入
- TCP/ITX协议面试总结
- 梦幻群侠传5帮派修炼_梦幻西游:2020年十大更新回顾 法连不秒空和连续战斗修复...
- android 渠道打包工具,Android渠道打包技术小结
- vue 日期格式化返回指定个数月份_12、vue中日期格式化转换的函数
- apmserv 5.2.6 升级php,APMServ5.2.6 升级PHP版本 到高版本 5.3,5.4
- 火狐怎么放大页面?火狐浏览器页面放大技巧
- 修改el-popover和el-select样式