In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Implementation code 1:
This method is suitable for statistics of unified names, such as httpd,ngins or php-fpm, etc.
#! / usr/bin/python#coding:utf8from subprocess import Popen, PIPEimport os#. If you need to count httpd, you can change nginx to httpd. Other service statistics are the same, but some of them cannot be implemented. For example, oraclenginxpid = Popen (["pidof", "nginx"], stdout=PIPE) nginxpid = nginxpid.stdout.read () .split () memsum = 0for i in nginxpid: pidfile = os.path.join ("/ proc/", str (I) "status") with open (pidfile) as f: for mem in f: if mem.startswith ("VmRSS"): pidmem = int (mem.split () [1]) memsum + = pidmemprint ("d% s"% (memsum, "KB"))
Implementation code 2:
This method is suitable for a user to do memory usage statistics. The final result is that all the memory information used by a user, the script usage method, and the user name to be counted are added to the script when executing the script.
#! / usr/bin/python#coding:utf8 "" this script requires the system to install smem software Installation method: yum-y install smem "" from subprocess import Popen, PIPEimport sysallmeminfo = Popen (["smem", "- u"] Stdout=PIPE) allmeminfo = allmeminfo.stdout.read () .split ("\ n") for i in allmeminfo: if i.startswith (sys.argv [1]): meminfo = i.split () print ("Process Name:" + meminfo [0]) print ("Total Process:" + meminfo [1]) print ("Physics Memroy Use:" + meminfo [5] + "KB")
The implementation results are as follows:
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.