基于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 = '{}' ERROR = '{}
' HEADER = '' ANALYSIS = 'Performance Monitor (pid={})
{}'
文章标题:基于python的Linux系统指定进程性能监控思路详解-创新互联
本文URL:http://scgulin.cn/article/dsdppg.html