ºìÁªLinuxÃÅ»§
Linux°ïÖú

linuxÏÂsarµÄÔ­Àí

·¢²¼Ê±¼ä:2008-01-24 01:19:05À´Ô´:ºìÁª×÷Õß:Fromlung
Ô­±¾ÊÇΪÁËÕÒ³öϵͳload×´¿öµÄÒì³££¬Í¨¹ý³£¹æÊÖ¶ÎÎÞ·¨¼ì²éµÃµ½£¬²»µÃÒÔÖ»ºÃ¿¼¾¿loadµÄÒƶ¯Æ½¾ù¼ÆËã·½·¨¡£ÏÈÕÒÁËsarµÄsource codeÀ´¿´£¬×îºóÈ´·¢ÏÖsar²»¹ýÊǶÁÁËlinux /proc ϵÄһϵÁÐÄÚ´æÎļþ£¬Í¨¹ý²ÉÑùÀ´µÃµ½Êý¾Ý¶øÒÑ¡£

ÓÉÓÚ´ÓÀ´Ã»ÓжÁ¹ýlinuxÏà¹ØµÄsource code£¬¶ÔºÜ¶à·ç¸ñ¡¢±äÁ¿¶¨ÒåÏ°¹ß¶¼²»¶®£¬ºÜ·Ñ¾¢¡£ÈÆÀ´ÈÆÈ¥´Ómainº¯Êý½øÈ¥ÕÒÁË°ëÌ죬²ÅÔÚÒ»¶ÑÎļþºÍÍ·¶¨ÒåÖÐÕÒµ½¸ùÔ´£¬Ö÷Òª¿ªÊ¼Ã»ÒÔΪÊÇ´ÓÎļþÖжÁ£¬»¹ÒÔΪֱ½ÓʹÓÃosµÄһЩº¯Êý»ñÈ¡×Ô¼º¼ÆËãµÄÄØ¡£

sarÊÇͨ¹ýfscanfÏÂÃæÕâЩÎļþÀ´µÃµ½Êä³öÊý¾ÝµÄ

ÒýÓÃ:
/* Files */
#define PROC "/proc"
#define PSTAT "stat"
#define MEMINFO "/proc/meminfo"
#define PID_STAT "/proc/%ld/stat"
#define SERIAL "/proc/tty/driver/serial"
#define FDENTRY_STATE "/proc/sys/fs/dentry-state"
#define FFILE_NR "/proc/sys/fs/file-nr"
#define FINODE_STATE "/proc/sys/fs/inode-state"
#define FDQUOT_NR "/proc/sys/fs/dquot-nr"
#define FDQUOT_MAX "/proc/sys/fs/dquot-max"
#define FSUPER_NR "/proc/sys/fs/super-nr"
#define FSUPER_MAX "/proc/sys/fs/super-max"
#define FRTSIG_NR "/proc/sys/kernel/rtsig-nr"
#define FRTSIG_MAX "/proc/sys/kernel/rtsig-max"
#define NET_DEV "/proc/net/dev"
#define NET_SOCKSTAT "/proc/net/sockstat"
#define SADC "sadc"
#define SADC_PATH "/usr/lib/sa/sadc"
#define SADC_LOCAL_PATH "/usr/local/lib/sa/sadc"
#define LOADAVG "/proc/loadavg"


ºÜÃ÷ÏÔ×îºóÒ»ÐÐ proc/loadavg ¾ÍÊÇ load µÄÀ´Ô´¡£ÕâҲ˵Ã÷¡£ÆäʵÎÒÃÇ×Ô¼ºÐ´¸ö³ÌÐòÖÜÆÚÐԵزɼ¯ proc/loadavg ÖÐÊý¾Ý£¬ÎÒÃÇÒ²¿É×ö¸öʵÓù¤¾ß¡£

µ«ÕâÏÔÈ»¸øÎÒ´øÀ´ÁíÒ»¸öÎÊÌ⣬ÄǾÍÊÇÒªÃ÷°× load µÄ¼ÆËãÔ­Àí(µ½µ×Òƶ¯Æ½¾ùÊDz»ÊÇrun queue size²ÉÑùºóµÄ¼òµ¥Çóƽ¾ù »¹ÊÇ¿¼ÂÇÁ˼ÓȨ»òÕß·½²îµÈ)£¬»¹ÐèҪȥ¶Á linuxµÄsource code¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ