ÔÚUNIX/Linuxϵͳȡ֤ÖУ¬¼°Ê±ÊÕ¼¯Ó²Å̵ÄÐÅÏ¢ÖÁ¹ØÖØÒª£¬¡¶Unix/LinuxÍøÂçÈÕÖ¾·ÖÎöÓëÁ÷Á¿¼à¿Ø¡·Ò»ÊéÖУ¬½«ÏêϸÌÖÂÛ¸÷ÖÖ³£¼ûϵͳ½ø³Ìϵͳµ÷Óü°¾µÏñÎļþ»ñÈ¡·½·¨¡£ÏÂÃæ¼òµ¥¾Ù¼¸¸öÀý×Ó¡£
1.ÊÕ¼¯ÕýÔÚÔËÐеĽø³Ì
ÔÚUNIX/Linuxȡ֤ʱºÜ¶àϵͳºÍÍøÂçÐÅÏ¢ÊǶÌʱ´æÔڵĿÉνÊÇת˲¼´ÊÅ£¬ÈçºÎ׼ȷµÄ²¶×½µ½ÄÄЩÖëË¿Âí¼£ÄØ?ÍøÂ簲ȫÈËÔ±ÐèÒª¾ßÓÐÃôÈñµÄ¹Û²ìÁ¦ºÍ·á¸»µÄ¾ÑéÏÂÃæÀý¾Ù¼¸¸ö³£Óõķ½·¨¡£
Ê×ÏÈ£¬ÔÚÊÕ¼¯Ö÷»úÉÏÆô¶¯Ò»¸ö¼àÌý½ø³Ì£º
#nc -l -p 10005 >ps_lsof_log |
Ö´ÐÐÍêÕâÌõÃüÁîºó»Ø³µ£¬ÏµÍ³´ò¿ª10005¶Ë¿ÚµÈ´ý½ÓÊÜ£¬È»ºóÔÚ±»µ÷²éµÄÁíÒ»Ö÷»úÉÏÔËÐÐÏàÓ¦µÄps µ÷Óãº
#(ps aux; ps-auxeww; lsof)|nc 192.168.150.100 10005 -w 3 |
¼¸ÃëÖÓºó»Øµ½ÃüÁîÐÐÌáʾ·û£¬ÐèҪעÒâµÄÊÇÕâÁ½ÌõÃüÁî³É¶Ô³öÏÖ,·¢ËÍÍêÊý¾Ýºó¿ªÆôµÄ¶Ë¿Ú½ÓÊÕÊý¾Ý½ÓÊÕÍê±Ï¼´¹Ø±Õ¶Ë¿Ú£¬Èç¹ûÄãµÚ¶þ´ÎûÓпªÆô¼àÌý¶Ë¿Ú£¬¼ÌÐø·¢ËÍpsÊý¾Ý¾Í»á³öÏÖÁ¬½Ó·ÃÎʾܾø¡£
#(ps aux;ps auxeww;losf) | nc 192.168.150.109 10005 ¨Cw 3 (UNKNOWN) [192.168.150.109] 10005 (?) : Conection refused |
ÔÚÉÏÊöÃüÁîÖУ¬ÓеÄÃüÁî²úÉú³¤Êä³ö½á¹û£¬ÓеIJúÉú¶ÌÊä³ö½á¹û£¬×÷ΪÊÕ¼¯Ö¤¾ÝÀ´Ëµ£¬ÕⶼҪ¼ÓÒÔÀûÓá£ÄÇôÓÐÄÄЩÃüÁîÄܹ»Ê¹ÓõĿÉÊÕ¼¯ÕýÔÚÔËÐеĽø³ÌÐÅÏ¢µÄ¹¤¾ßÄØ?
ÀýÈ磺
who;
uptime;
ps(²é¿´½ø³ÌµÄÄÚ´æµØÖ·£ºps -ealf);
top;
lsof(²é¿´½ø³ÌÒÑ´ò¿ªµÄÎļþ£ºlsof -p PID);
strace(¸ú×Ù½ø³ÌµÄϵͳµ÷ÓúÍÐźţºstrace -p PID);
truss;
ltrace(¸ú×Ù½ø³ÌµÄ¿âµ÷ÓÃ:ltrace -p PID)µÈ¡£
2.LinuxÏÂϵͳµ÷Óò鿴¹¤¾ß
ÀàËÆ´Û¸ÄϵͳÎļþ¡¢Ö²ÈëľÂí»òÐíÔÚ¿ØÖÆ̨ÉÏÄÜƹý³õ¼¶¹ÜÀíÔ±£¬Ò»µ©ÉîÈ뵽ϵͳ²ãÃæľÂíÃǶ¼»áÔÐα϶£¬Strace³£ÓÃÀ´¸ú×Ù½ø³ÌÖ´ÐÐʱµÄϵͳµ÷ÓúÍËù½ÓÊÕµÄÐźš£
Linuxϵͳ£¬½ø³Ì²»ÄÜÖ±½Ó·ÃÎÊÓ²¼þÉ豸£¬µ±½ø³ÌÐèÒª·ÃÎÊÓ²¼þÉ豸(±ÈÈç¶ÁÈ¡´ÅÅÌÎļþ£¬½ÓÊÕÍøÂçÊý¾ÝµÈµÈ)ʱ£¬±ØÐëÓÉÓû§Ì¬Ä£Ê½Çл»ÖÁÄÚºË̬ģʽ£¬Í¨¹ýϵͳµ÷Ó÷ÃÎÊÓ²¼þÉ豸¡£Ëùνϵͳµ÷ÓÃ(Systemcall)£¬¾ÍÊÇÄÚºËÌṩµÄ¡¢¹¦ÄÜÊ®·ÖÇ¿´óµÄһϵÁеĺ¯Êý¡£ÕâЩϵͳµ÷ÓÃÊÇÔÚÄÚºËÖÐʵÏֵģ¬ÔÙͨ¹ýÒ»¶¨µÄ·½Ê½°Ñϵͳµ÷ÓøøÓû§¡£Strace¿ÉÒÔ¸ú×Ùµ½Ò»¸ö½ø³Ì²úÉúµÄϵͳµ÷ÓÃ,°üÀ¨²ÎÊý£¬·µ»ØÖµ£¬Ö´ÐÐÏûºÄµÄʱ¼ä¡£StraceÔÚ±¾ÊéµÄÓ¦Óüû±¾Õµİ¸ÀýÑо¿Ò»¡£
3.UNIXÏÂϵͳµ÷Óò鿴¹¤¾ß
DTraceÊÇUnixƽ̨ϵĶ¯Ì¬¸ú×Ù¹¤¾ß£¬ÊÇÓÉ Sun¹«Ë¾¿ª·¢,¿ÉÒÔÒÔ¶ÔºËÐÄ(kernel)ºÍÓ¦ÓóÌÐò(user
application)½øÐж¯Ì¬¸ú×Ù,µ±È»Ò²¿ÉÒÔÕÒ³öϵͳƿ¾±£¬ÔÚ¼×¹ÇÎÄÊÕ¹ºSunÖ®ºóÕâÒ»¼¼ÊõÓÖ±»ÒÆÖ²µ½ÁËOracle
Linuxϵͳ¼ÌÐø·¢Ñï¹â´ó(¸ü¶à²Î¿¼Announcement:Dtrace for Oracle Linux
General Availability)¡£
Õâ¿î¹¤¾ßÔÚSolaris ºÍOpen Solarisƽ̨϶¼¿ÉÒÔʹÓá£
4.Ó¦ÓþÙÀý
¢ÙÏÔʾµ±Ç°¶¯Ì¬ÏµÍ³ÖеĶ¯Ì¬Dtrace̽Õëprobe
¢Úͨ³£ÎÒÃDz鿴ϵͳfirefox½ø³ÌµÄÇé¿öʹÓÃÈçÏÂÃüÁî
Ò²¿ÉÒÔÓÃDtrace²é¿´probe̽Õ룬²Ù×÷ÈçÏ£º
ºÎ¿´»úÆ÷æÏÐ״̬ÄØ£¬³£ÓÃvmstat£¬µÃÖª²úÉú2535¶àϵͳµ÷Óᣵ«ÊÇ£¬ÈçºÎ¼òµ¥²éÕÒÄĸö½ø³ÌµÄÎÊÌâÄØ?ÊÔÓý¨ÒéʹÓÃdtrace¹¤¾ß¡£
´Ó×îºóÒ»ÐÐÏÔʾ¿´£¬ÏÔÈ»·¢ÏÖfirefox-binÊDzúÉú´óÁ¿ÏµÍ³µ÷ÓõijÌÐò, ÔÙ¿´¿´I/O·Ö²¼¡£ÀýÈ绹ÊÇfirefox½ø³Ì£¬ÊäÈëÒÔÏÂÃüÁî¡£
ͨ¹ýÒÔÉÏÏÔʾ£¬¿É¹Û²ìµ½´óÁ¿Firefox²úÉúµÄI/OÔÚ8¡«64×ֽڼ䣬½Ó×ÅÉîÈë¿´Firefox³ÌÐòÄÚ²¿Çé¿ö£¬ÊäÈëÒÔÏÂÃüÁî¡£
Dtrace¹¦ÄÜÇ¿´ó£¬¾«¶È¸ß£¬¶øSolaris 10ϵÄÀÏÅÆϵͳ¸ú×Ù¹¤¾ßtruss£¬ÖµµÃ´ó¼Ò×¢ÒâµÄÊÇtruss¹¤¾ßÓÐʱ»á½µµÍϵͳ25%¡«30%µÄCPUÀûÓÃÂÊ¡£
5.Systrace
ÁíÒ»¿î¹¦Äܸü¼ÓÇ¿´óµÄϵͳµ÷ÓÃÍâ´ø±¨¾¯¹¦ÄܵĿªÔ´Èí¼þsystrace¾ÍǶÈëÔÚOpenBSDϵͳÖУ¬ÔÚFreeBSDºÍLinuxÒ²¿ÉÒÔ×ÔÐа²×°¡£Systrace¹¤¾ß£¬¿ÉÒÔÓÃÀ´·ÀֹľÂíÈí¼þ¶ÔϵͳµÄΣº¦¡£ÔÚÕâ¸öÀý×ÓÖÐÈçÏÂͼËùʾ£¬Systrace¼ì²âÔÚfragroute-1.2Ŀ¼ÏµÄÒ»¸öÅäÖÃÖаüº¬¶ñÒâ½Å±¾Ä¾Âí¡£
Systrace¹¤¾ßÏÂÔصØÖ·£º http://www.citi.umich.edu/u/provos/systrace/systrace-1.6f.tar.gz
6.ÊÕ¼¯/procϵͳÖеÄÐÅÏ¢
ProcÒ»Ö±°éËæ×ÅLiux kernel, ·¢Õ¹ÖÁ½ñÔÚLinux¿ªÊ¼Ö÷ÒªÓ¦ÓÃÔÚÍøÂçÏà¹Ø·½Ãæ, ºóÀ´ÎªÁ˼ò»¯ÏµÍ³¹ÜÀíºÍµ÷ÊÔ,
Öð½¥°ÑËüÓ¦Óõ½ÆäËû·½Ãæ¡£ÏÖÔÚ, procÒѾ³ÉΪLinux ÄÚºËÖÐʹÓÃ×î¹ã·ººÍ×î³É¹¦µÄÌØÐÔÖ®Ò»¡£ProcÔÚÄÚ´æÖн¨Á¢ÐéÄâµÄÎļþ½Úµã,
Óû§¿ÉÒÔÖ±½ÓʹÓÃÎļþϵͳÖеıê׼ϵͳµ÷ÓÃÈ¥·ÃÎÊproc ϵÄÐÅÏ¢, µ±Óû§·¢³ö·ÃÎÊ/procϵġ°Îļþ¡±ÇëÇóʱ,
ÔÙÓÉϵͳ¶¯Ì¬Éú³É¡£ËùÒÔProc¾ÍÊÇÒ»¸öÐéÄâµÄÎļþϵͳ£¬Í¨¹ýÎļþϵͳµÄ½Ó¿ÚʵÏÖ£¬µ±ÏµÍ³ÖØÆô»òµçÔ´¹Ø±ÕʱÕâ¸öÎļþϵͳµÄÊý¾Ý½«Ïûʧ¡£/proc»¹Îª/dev/kmem
Ìṩһ¸ö½á¹¹»¯µÄ½Ó¿Ú£¬±ãÓÚϵͳÕï¶Ï²¢²é¿´Ã¿Ò»¸öÕýÔÚÔËÐеĿÉÖ´ÐÐÎļþµÄ»·¾³¡£ÄÚ´æÖеÄÿ¸ö½ø³ÌÔÚ/proc
Öж¼ÓÐÒ»¸öĿ¼£¬°´ËüµÄ½ø³ÌID À´ÃüÃû¡£Èç¹ûÔÚÉÏÃæÁгöµÄps µÄÊä³öÖп´²»¼ûµÄ½ø³Ì³öÏÖÔÚ/proc ÖУ¬Õâ¾Í¿ÉÄÜÊÇps
Òѱ»ÌØÂåÒÁ»¯ÁË(±»´Û¸Ä²¢¼ÓÁËΣÏÕ³ÌÐò)£¬ËùÒÔÎÒÃÇÒªÊìϤProc,ÒÔ±ãÓ¦¶Ô¹¥»÷Õ߶ÔprocϵÄÎļþ×öÊֽš£trace:DynamicTracing
in Oracle Solaris,MacOS X and FreeBSD¡·
ÏÂÃæͨ¹ýncÃüÁÈçºÎͨ¹ýÍøÂçÊÕ¼¯proc½ø³ÌµÄ·½·¨£¬ÎªÁËÊÕ¼¯ Proc½ø³Ì £¬Ê¹ÓÃÏÂÃæÓÃ2ÌõÃüÁî:
#nc -l ¨Cp 10006>proc_log #ls -d/proc[1-9] * | nc 192.168.0.2 10006 -w 3 |
ÏÂÆÚ°¸ÀýÔ¤±¨£¬¶ÔÓÚÕâ¸öncÃüÁÔÚÍøÂçÈ¡Ö¤ÖÐÄÜÆ𵽹ؼü×÷Óã¬ÔÚÏÂÃæÕâÆðÍøÂ簲ȫʼþ·ÖÎöÔÚnc¾ÍÆðµ½Á˹ؼü×÷Óá£
|