ÔõÑùÔÚLinuxÉϼà¿ØϵͳÐÔÄÜ
ÔõÑùÔÚlinuxÉϼà¿ØϵͳÐÔÄÜ
ÔÚLinuxϵͳÖУ¬¼à¿ØϵͳÐÔÄÜÊǺÜÊÇÖ÷ÒªµÄ£¬Ëü¿ÉÒÔ×ÊÖúÎÒÃÇÏàʶϵͳµÄ¸ºÔØ¡¢×ÊÔ´ÏûºÄÇéÐÎÒÔ¼°Ó¦ÓóÌÐòµÄÔËÐÐ״̬¡£±¾ÎĽ«ÏÈÈݼ¸ÖÖ³£Óõļà¿Ø¹¤¾ßºÍÒªÁ죬²¢Ìṩ´úÂëʾÀý¡£
topÏÂÁî
topÏÂÁîÊÇ×î³£¼ûºÍ×î»ù±¾µÄLinuxϵͳ¼à¿Ø¹¤¾ßÖ®Ò»£¬Ëü¿ÉÒÔʵʱÏÔʾÔËÐÐÖеÄÀú³ÌºÍϵͳ×ÊԴʹÓÃÇéÐΡ£ÒÔÏÂÊÇtopÏÂÁîµÄ»ù±¾Ó÷¨£º
top
µÇ¼ºó¸´ÖÆ
ÔÚtopÏÂÁîµÄÊä³öÖУ¬Äã¿ÉÒÔ¿´µ½ÖîÈçCPUʹÓÃÂÊ¡¢ÄÚ´æʹÓÃÂÊ¡¢Àú³ÌÊýÄ¿¡¢Àú³ÌIDµÈÐÅÏ¢¡£°´Ï¼üÅÌÉϵġ°q¡±¼ü¿ÉÒÔÍ˳ötopÏÂÁî¡£
htopÏÂÁî
htopÏÂÁîÊÇtopÏÂÁîµÄÒ»¸öˢа汾£¬ÌṩÁËÔ½·¢ÑŹۺͽ»»¥Ê½µÄ½çÃæ¡£ËüÖ§³Ö¶àÖÖ²Ù×÷£¬Èç°´¼üÅÌÉϵÄF¼ü¿ÉÒÔÅÅÐòÀú³Ì£¬°´¼üÅÌÉϵÄH¼ü¿ÉÒÔÏÔʾÀú³ÌÊ÷µÈ¡£ÒÔÏÂÊÇhtopÏÂÁîµÄÓ÷¨£º
htop
µÇ¼ºó¸´ÖÆ
htopµÄ½çÃæÔ½·¢ÓѺ㬿ÉÒÔͨ¹ý¼ýÍ·¼üÉÏÏÂÒƶ¯£¬¿ÉÒÔʹÓÃF1-F10¼üÀ´Ö´Ðвî±ðµÄ²Ù×÷¡£
vmstatÏÂÁî
vmstatÏÂÁîÓÃÓÚ±¨¸æÐéÄâÄÚ´æͳ¼ÆÐÅÏ¢ºÍϵͳÐÔÄÜ¡£Ëü¿ÉÒÔÏÔʾ¹ØÓÚÀú³Ì¡¢ÄÚ´æ¡¢½»Á÷ºÍCPUµÄÖÖÖÖͳ¼ÆÊý¾Ý¡£ÒÔÏÂÊÇvmstatÏÂÁîµÄÓ÷¨£º
vmstat 1
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁÿ¸ô1ÃëÏÔʾһ´ÎϵͳÐÔÄÜÐÅÏ¢¡£
iostatÏÂÁî
iostatÏÂÁîÓÃÓÚ±¨¸æCPUʹÓÃÂʺÍ×°±¸Ê¹ÓÃÂÊ¡£ËüÌṩÁËÓйØ×°±¸µÄ¶ÁдÊý¾Ý¡¢Æ½¾ùÆÚ´ýʱ¼äÒÔ¼°Ã¿ÃëµÄI/OÇëÇóÊýµÈÐÅÏ¢¡£ÒÔÏÂÊÇiostatÏÂÁîµÄÓ÷¨£º
iostat -d -x
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁÏÔʾ´ÅÅÌʹÓÃÇéÐεÄÏêϸÐÅÏ¢£¬°üÀ¨Ã¿¸ö×°±¸µÄ¶ÁдËÙÂÊ¡¢´ø¿íÇå¾²¾ùÏìӦʱ¼ä¡£
sarÏÂÁî
sarÏÂÁîÓÃÓÚÍøÂç¡¢±¨¸æϵͳÔ˶¯µÄÐÅÏ¢¡£Ëü¿ÉÒÔÌṩÓëCPU¡¢ÄÚ´æ¡¢I/OºÍÍøÂçÏà¹ØµÄÏêϸͳ¼ÆÊý¾Ý¡£ÒÔÏÂÊÇsarÏÂÁîµÄÓ÷¨£º
sar -u 1 10
µÇ¼ºó¸´ÖÆ
ÉÏÊöÏÂÁÿ¸ô1ÃëÏÔʾһ´ÎCPUʹÓÃÇéÐεÄ10¸öÑù±¾¡£
ÒÔÉÏÊǼ¸ÖÖ³£ÓõÄLinuxϵͳ¼à¿Ø¹¤¾ßºÍÒªÁ죬Äã¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóÑ¡ÔñºÏÊʵŤ¾ß¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý´úÂ룬ʹÓÃPython¾ç±¾ÊµÊ±¼à¿ØCPUʹÓÃÂʲ¢¼Í¼µ½ÈÕÖ¾ÎļþÖУº
import psutil import time def monitor_cpu_usage(interval, duration, log_file): with open(log_file, 'w') as f: for i in range(duration): cpu_usage = psutil.cpu_percent(interval=interval) f.write(f'{time.strftime("%Y-%m-%d %H:%M:%S")} - CPU usage: {cpu_usage}% ') time.sleep(interval) monitor_cpu_usage(1, 10, 'cpu_usage.log')
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëʹÓÃpsutilÄ£¿é»ñÈ¡CPUʹÓÃÂÊ£¬²¢½«Æä¼Í¼µ½ÈÕÖ¾ÎļþÖС£Äã¿ÉÒÔƾ֤ÐèÒªµ÷½â²ÉÑù¾àÀëºÍÒ»Á¬Ê±¼ä¡£
×ܽá
ÔÚLinuxϵͳÉϼà¿ØϵͳÐÔÄÜÊǺÜÊÇÖ÷ÒªµÄ£¬¿ÉÒÔ×ÊÖúÎÒÃÇʵʱ·¢Ã÷Ï¢Õù¾öÐÔÄÜÎÊÌâ¡£±¾ÎÄÏÈÈÝÁ˼¸ÖÖ³£Óõļà¿Ø¹¤¾ßºÍÒªÁ죬ÒÔ¼°Ò»¸ö¼òÆӵĴúÂëʾÀý¡£Ï£ÍûÄܶÔÄãÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉϼà¿ØϵͳÐÔÄܵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡