基于python的Linux系統(tǒng)指定進(jìn)程性能監(jiān)控思路詳解-創(chuàng)新互聯(lián)

監(jiān)控Linux服務(wù)器的工具、組件和程序網(wǎng)上有很多,但是一臺(tái)服務(wù)器上會(huì)有很多進(jìn)程同時(shí)運(yùn)行,特別是做性能測(cè)試的時(shí)候,可能一臺(tái)服務(wù)器上部署多個(gè)服務(wù),如果只監(jiān)控整個(gè)服務(wù)器的CPU和內(nèi)存,當(dāng)某個(gè)服務(wù)出現(xiàn)性能問題時(shí),并不能有效準(zhǔn)確的定位出(當(dāng)然通過(guò)其他工具也可以實(shí)現(xiàn)),因此,很有必要只監(jiān)控指定的進(jìn)程。需求明確了,于是動(dòng)手?jǐn)]了一個(gè)性能監(jiān)控腳本。

創(chuàng)新互聯(lián)公司專注于唐縣網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供唐縣營(yíng)銷型網(wǎng)站建設(shè),唐縣網(wǎng)站制作、唐縣網(wǎng)頁(yè)設(shè)計(jì)、唐縣網(wǎng)站官網(wǎng)定制、微信平臺(tái)小程序開發(fā)服務(wù),打造唐縣網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供唐縣網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。一、整體思路

1、為了方便的啟動(dòng)監(jiān)控和停止監(jiān)控,在想查看監(jiān)控結(jié)果的時(shí)候隨時(shí)查看監(jiān)控結(jié)果,用flask開啟了一個(gè)服務(wù),通過(guò)發(fā)送get請(qǐng)求可以隨時(shí)啟停監(jiān)控和查看監(jiān)控結(jié)果。
2、針對(duì)控制是否監(jiān)控cpu、內(nèi)存、IO,開啟多線程監(jiān)控。
3、為了減少對(duì)其他組件的依賴,將監(jiān)控結(jié)果寫到日志中。
4、為了方便查看監(jiān)控結(jié)果,直接將結(jié)果以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>'

標(biāo)題名稱:基于python的Linux系統(tǒng)指定進(jìn)程性能監(jiān)控思路詳解-創(chuàng)新互聯(lián)
分享URL:http://bm7419.com/article36/dsdppg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作自適應(yīng)網(wǎng)站、微信公眾號(hào)關(guān)鍵詞優(yōu)化、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)