基于python的Linux系统指定进程性能监控思路详解-创新互联

监控Linux服务器的工具、组件和程序网上有很多,但是一台服务器上会有很多进程同时运行,特别是做性能测试的时候,可能一台服务器上部署多个服务,如果只监控整个服务器的CPU和内存,当某个服务出现性能问题时,并不能有效准确的定位出(当然通过其他工具也可以实现),因此,很有必要只监控指定的进程。需求明确了,于是动手撸了一个性能监控脚本。

创新互联公司专注于唐县网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供唐县营销型网站建设,唐县网站制作、唐县网页设计、唐县网站官网定制、微信平台小程序开发服务,打造唐县网络公司原创品牌,更为您提供唐县网站排名全网营销落地服务。一、整体思路

1、为了方便的启动监控和停止监控,在想查看监控结果的时候随时查看监控结果,用flask开启了一个服务,通过发送get请求可以随时启停监控和查看监控结果。
2、针对控制是否监控cpu、内存、IO,开启多线程监控。
3、为了减少对其他组件的依赖,将监控结果写到日志中。
4、为了方便查看监控结果,直接将结果以html方式返回。

二、配置文件

config.py

IP = '127.0.0.1'
PORT = '5555'
LEVEL = 'INFO' # log level
BACKUP_COUNT = 9 # log backup counter
LOG_PATH = 'logs' # log path
INTERVAL = 1 # interval, run command interval.
SLEEPTIME = 3 # interval, when stopping monitor, polling to start monitor when satisfying condition.
ERROR_TIMES = 5 # times, number of running command. When equal, automatically stopped monitor.
IS_JVM_ALERT = True # Whether to alert when the frequency of Full GC is too high.
IS_MONITOR_SYSTEM = True # Whether to monitor system's CPU and Memory.
IS_MEM_ALERT = True # Whether to alert when memory is too low. Alert by sending email.
MIN_MEM = 2  # Minxium memory, uint: G
# 0: don't clear cache, 1: clear page caches, 2: clear dentries and inodes caches, 3: include 1 and 2;
# echo 1 >/proc/sys/vm/drop_caches
ECHO = 0
SMTP_SERVER = 'smtp.sina.com' # SMTP server
SENDER_NAME = '张三'  # sender name
SENDER_EMAIL = 'zhangsan@qq.com' # sender's email
PASSWORD = 'UjBWYVJFZE9RbFpIV1QwOVBUMDlQUT09' # email password, base64 encode.
RECEIVER_NAME = 'baidu_all' # receiver name
RECEIVER_EMAIL = ['zhangsan@qq.com', 'zhangsi@qq.com'] # receiver's email
DISK = 'device1' # Which disk your application runs
START_TIME = 'startTime.txt' # Store the time of start monitoring.
FGC_TIMES = 'FullGC.txt' # Store the time of every FullGC time.
# html
HTML = '<html><body>{}</body><html>'
ERROR = '<p >{}</p>'
HEADER = '<div id="header"><h3 align="center">Performance Monitor (pid={})</h3></div>'
ANALYSIS = '<div id="container" >{}</div>'

标题名称:基于python的Linux系统指定进程性能监控思路详解-创新互联
分享URL:https://www.cdcxhl.com/article36/dsdppg.html

成都网站建设公司_创新互联,为您提供手机网站建设企业网站制作自适应网站微信公众号关键词优化App开发

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设