In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.