linuxÉó²écpuʹÓÃÂÊ
linuxÉó²écpuʹÓÃÂʵÄÒªÁ죺1¡¢Ê¹ÓÃtopÏÂÁtopÏÂÁîÊÇÒ»¸ö³£ÓõÄlinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÉó²éϵͳµÄÀú³ÌºÍ×ÊԴʹÓÃÇéÐΣ»2¡¢Ê¹ÓÃmpstatÏÂÁmpstatÏÂÁîÊÇÒ»¸ölinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÏÔʾcpuʹÓÃÂʺÍÆäËûcpuͳ¼ÆÊý¾Ý£»3¡¢Ê¹ÓÃsarÏÂÁsarÏÂÁîÊÇÒ»¸ölinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÉó²écpuʹÓÃÂÊÒÔ¼°ÆäËûϵͳÐÔÄÜÖ¸±ê¡£
LinuxÊÇÒ»ÖÖ¿ªÔ´²Ù×÷ϵͳ£¬±»ÆÕ±éÓÃÓÚЧÀÍÆ÷ºÍǶÈëʽװ±¸ÉÏ¡£×÷Ϊһ¸öЧÀÍÆ÷²Ù×÷ϵͳ£¬¼à¿Øϵͳ×ÊÔ´µÄʹÓÃÇéÐÎÊǺÜÊÇÖ÷ÒªµÄ¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚLinuxϵͳÉÏÉó²éCPUʹÓÃÂÊ¡£
ÔÚLinuxÖÐÓм¸ÖÖÒªÁì¿ÉÒÔÉó²éCPUʹÓÃÂÊ£¬ÏÂÃ潫ÖðÒ»ÏÈÈÝÕâЩҪÁì¡£
1. ʹÓÃtopÏÂÁî
topÏÂÁîÊÇÒ»¸ö³£ÓõÄLinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÉó²éϵͳµÄÀú³ÌºÍ×ÊԴʹÓÃÇéÐΡ£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Éó²éCPUʹÓÃÂÊ£º
top
µÇ¼ºó¸´ÖÆ
Æô¶¯topÏÂÁîºó£¬»áÏÔʾĿ½ñϵͳµÄ¸÷Ïî×ÊԴʹÓÃÇéÐΣ¬°üÀ¨CPUʹÓÃÂÊ¡£ÔÚtop½çÃ棬¿ÉÒÔ¿´µ½Ò»¸öCPUÐУ¬ÆäÖаüÀ¨ÁËCPUʹÓÃÂʵÄÐÅÏ¢¡£ÀýÈ磺
%Cpu(s): 5.0 us, 2.0 sy, 0.0 ni, 93.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬usÌåÏÖÓû§¿Õ¼ä³ÌÐòµÄCPUʹÓÃÂÊ£¬syÌåÏÖϵͳÄں˵ÄCPUʹÓÃÂÊ£¬idÌåÏÖCPU¿ÕÏеÄʱ¼ä¡£
2. ʹÓÃmpstatÏÂÁî
mpstatÏÂÁîÊÇÒ»¸öLinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÏÔʾCPUʹÓÃÂʺÍÆäËûCPUͳ¼ÆÊý¾Ý¡£mpstatÏÂÁîĬÈÏÏÔʾËùÓÐCPUµÄʹÓÃÇéÐΣ¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Éó²éCPUʹÓÃÂÊ£º
mpstat
µÇ¼ºó¸´ÖÆ
Æô¶¯mpstatÏÂÁîºó£¬»áÏÔʾÿ¸öCPU½¹µãµÄʹÓÃÇéÐΣ¬°üÀ¨Óû§¿Õ¼ä³ÌÐò¡¢ÏµÍ³Äںˡ¢¿ÕÏеÈÏà¹ØÐÅÏ¢¡£ÀýÈ磺
02:40:01 AM CPU %user %nice %sys %iowait %irq %soft %steal %guest %idle 02:40:01 AM all 5.42 0.02 2.09 0.04 0.00 0.01 0.00 0.00 92.42
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬%userÌåÏÖÓû§¿Õ¼ä³ÌÐòµÄCPUʹÓÃÂÊ£¬%sysÌåÏÖϵͳÄں˵ÄCPUʹÓÃÂÊ£¬%idleÌåÏÖCPU¿ÕÏеÄʱ¼ä¡£
3. ʹÓÃsarÏÂÁî
sarÏÂÁîÊÇÒ»¸öLinuxϵͳ¼à¿ØÏÂÁ¿ÉÒÔʵʱÉó²éCPUʹÓÃÂÊÒÔ¼°ÆäËûϵͳÐÔÄÜÖ¸±ê¡£sarÏÂÁîÐèҪװÖÃsysstat¹¤¾ß°üÀ´Ê¹Ó᣿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´Éó²éCPUʹÓÃÂÊ£º
sar -u
µÇ¼ºó¸´ÖÆ
Æô¶¯sarÏÂÁîºó£¬»áÏÔʾCPUµÄʹÓÃÇéÐΣ¬°üÀ¨Óû§¿Õ¼ä³ÌÐò¡¢ÏµÍ³Äںˡ¢¿ÕÏеÈÏà¹ØÐÅÏ¢¡£ÀýÈ磺
12:00:01 AM CPU %user %nice %system %iowait %steal %idle 12:10:01 AM all 8.24 0.00 3.29 0.02 0.00 88.45
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬%userÌåÏÖÓû§¿Õ¼ä³ÌÐòµÄCPUʹÓÃÂÊ£¬%systemÌåÏÖϵͳÄں˵ÄCPUʹÓÃÂÊ£¬%idleÌåÏÖCPU¿ÕÏеÄʱ¼ä¡£
³ýÁËÒÔÉϵÄÏÂÁîÍ⣬»¹¿ÉÒÔʹÓÃÆäËû¹¤¾ßÀ´Éó²éCPUʹÓÃÂÊ£¬Èçhtop¡¢nmonµÈ¡£ÕâЩ¹¤¾ßÌṩÁ˸ü¸»ºñµÄ½çÃæºÍ¹¦Ð§£¬Äܹ»¸üÏêϸµØÏÔʾϵͳ×ÊÔ´µÄʹÓÃÇéÐΡ£
×ܽá
ÔÚLinuxϵͳÉÏÉó²éCPUʹÓÃÂÊ¿ÉÒÔʹÓÃtop¡¢mpstat¡¢sarµÈÏÂÁҲ¿ÉÒÔʹÓÃһЩÆäËû¹¤¾ß¡£Æ¾Ö¤ÏÖʵÐèÇóÑ¡ÔñºÏÊʵÄÏÂÁî»ò¹¤¾ßÀ´¾ÙÐмà¿Ø¡£Í¨¹ýʵʱÉó²éCPUʹÓÃÂÊ£¬¿ÉÒÔʵʱÏàʶϵͳµÄÔËÐÐÇéÐΣ¬×ö³öÏìÓ¦µÄÓÅ»¯ºÍµ÷½â¡£
ÒÔÉϾÍÊÇlinuxÉó²écpuʹÓÃÂʵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡