æéãçµã€ã«ã€ããŠããµãŒããŒã®æ°ãå¢å ããé ããæ©ããããªãã¯çåã«æãã§ããã
ãçŸåšã·ã¹ãã ã§äœãèµ·ãã£ãŠããã®ã§ããïŒã ãã®ã¹ã¯ãªãããŸãã¯ãã®ã¹ã¯ãªããã¯ã©ã®ãããã®é »åºŠã§å®è¡ãããŸããïŒ æãæéããããæäœã¯äœã§ããïŒâ Zabbixã¿ã€ãã®ç£èŠã·ã¹ãã ã¯ãã¢ããªã±ãŒã·ã§ã³ã®ç¶æ ã®äžè¬çãªè¡šé¢çãªç»åã®ã¿ãæäŸããŸãã
ãããã®è³ªåã«å¯ŸããåçãåŸãããã«ãBadbaã¯ãªã¢ã«ã¿ã€ã ã®ç£èŠããã³çµ±èšãµãŒãã¹PinbaãéçºããŸããã ãã®èšäºã§ã¯ãã·ã¹ãã ã®ç£èŠãšãããã¡ã€ãªã³ã°ã«äœ¿çšããçµéšã«ã€ããŠèª¬æããŸãã
Badooã«ã€ããŠäžèš
ã¿ã¹ã¯ã®é£æ床ãè©äŸ¡ããããã«ãBadooãã©ã®ãããªãã®ããç°¡åã«èª¬æããŸãã çŸåšã2ã€ã®ããŒã¿ã»ã³ã¿ãŒãããã1ã€ã¯ã¢ã¡ãªã«ã«ããã1ã€ã¯ãšãŒãããã«ãããŸãã äœçŸãã®PHPãµãŒããŒãMySQLãµãŒããŒãC / C ++ã§æžãããæ°åã®memcachedããã³ãèªå·±äœæããµãŒãã¹ãããŒã¿ã»ã³ã¿ãŒã«ã€ã³ã¹ããŒã«ãããŠããŸãã Badooã«ã¯ç¬èªã®ãµããããžã§ã¯ãïŒããšãã°ãWebãµã€ããã¢ãã€ã«ããã€ã¹ãšãã¹ã¯ãããçšã®ã¢ããªã±ãŒã·ã§ã³ïŒããããå®è£ ãšè² è·ã®æ§è³ªã¯å€§ããç°ãªããŸãã 1ã€ã®PHPãªã¯ãšã¹ãã§ãå€æ°ã®ç°ãªãããŒã¿ãœãŒã¹ïŒããŒã¿ããŒã¹ããã£ãã·ã¥ããµãŒãã¹ïŒãšã®ããåããçºçããå¯èœæ§ããããŸãã ããã¯ããã©ãŒãã³ã¹ã«ã¯æªãã§ãããããžãã¹ã¿ã¹ã¯ã®è§£æ±ºã«ã¯å¿ èŠã§ãã ãŸããããã«å ããŠãæ°ããã³ãŒããé±ã«2ã5åæçš¿ããŸãã ãã®ãããªã·ã¹ãã ã®ããã©ãŒãã³ã¹ãç£èŠããããšã¯ç°¡åãªäœæ¥ã§ã¯ãããŸããã ãã³ãã¯ãPHPã¹ã¯ãªããã®ããã©ãŒãã³ã¹ã®ç£èŠã«é¢é£ããåé¡ã®å€§ããªå±€ã®è§£æ±ºãæ¯æŽããŸããã ãã®ãµãŒãã¹ã¯ãåŠçããããã¹ãŠã®PHPãªã¯ãšã¹ãã«é¢ããæ å ±ãåéãããã®ããŒã¿ã«é¢ãã詳现ãªã¬ããŒããçæããŸãã
ä»çµã¿
Habrahabrã«ã¯ãPinbaã§ã®äœæ¥ãéå§ããæ¹æ³ã«é¢ããèšäºãæ¢ã«ãããŸãããã Pinba-PHPããªã¢ã«ã¿ã€ã ã§ç£èŠãã ãã ãã®äžã§ãèè ã¯Pinbaã®ã€ã³ã¹ããŒã«æ¹æ³ãšæ§ææ¹æ³ã説æããã®ã§ãä»åºŠã¯ãã£ãšèå³æ·±ãããšã«éäžããŸãã
Pinbaã䜿çšããäžè¬çãªã¹ããŒã ãå³ã«ç€ºããŸãã
ãã³ãã¯ãPHPã¢ãžã¥ãŒã«ïŒè±èªã®PHPæ¡åŒµæ©èœ ïŒãšãµãŒããŒã§æ§æãããŠããŸãã Pinbaã¢ãžã¥ãŒã«ã¯ãåŠçããããã¹ãŠã®ãªã¯ãšã¹ãã«é¢ããããŒã¿ããµãŒããŒã«èªåçã«éä¿¡ããŸãã ãã³ããµãŒããŒã¯ãCã§èšè¿°ããããµãŒãã¹ã§ãã
- UDPçµç±ã§åŠçãããèŠæ±ã«é¢ããããŒã¿ãåéããŸãã
- ãã®ãã¹ãŠã®ããŒã¿ãã¡ã¢ãªã«ä¿åããã¬ããŒããäœæããŸãã
- MySQLãããã³ã«ã䜿çšããŠçããŒã¿ãšã¬ããŒããžã®ã¢ã¯ã»ã¹ãæäŸããŸããã€ãŸããå®éã«ã¯MySQLãšã³ãžã³ã§ãã
çŸåšã·ã¹ãã ã§äœãèµ·ãã£ãŠããã®ããç¥ãã«ã¯ãMySQLã¯ã©ã€ã¢ã³ãã䜿çšããŠãµãŒããŒã«æ¥ç¶ããã¬ããŒãããŒãã«ããããã€ãã®ã¯ãšãªãå®è¡ããŸãã ããšãã°ãåPHPã¹ã¯ãªããïŒPinbaã§æã䜿çšãããŠããã¬ããŒãã®1ã€ïŒã®ãªã¯ãšã¹ãã«é¢ããçµ±èšã衚瀺ã§ããŸãã
mysql> SELECT * FROM report_by_script_name;
以äžã§ã¯ãPinbaã§ã¬ããŒããæäœããæ¹æ³ã«ã€ããŠè©³ãã説æããŸãã
Pinbaã®PHPã¢ãžã¥ãŒã«ã®ä»çµã¿
PinbaãµãŒãã¹ã®æåã®ããŒãžã§ã³ã®èšç»æ®µéã§ãããPHPã³ãŒãã«å€æŽãå ããããšãªããäžè¬çãªçµ±èšæ å ±ã®åéãæŽçãããšããã¢ã€ãã¢ãããã«æãã€ããŸããã PHPã¢ãžã¥ãŒã«ã®äœæçµéšããã人ã¯ãåŸè ãåãªã¯ãšã¹ãã®åïŒãã§ãŒãºPHP_RINITïŒããã³åŠçåŸïŒãã§ãŒãºPHP_RSHUTDOWNïŒã«ããã€ãã®ã¢ã¯ã·ã§ã³ãå®è¡ã§ããããšãç¥ã£ãŠããŸãã ããšãã°ãPHP_RINITãã§ãŒãºã§ã¯ãã¢ãžã¥ãŒã«ã¯å éšãªãœãŒã¹ãåæåã§ããRSHUTDOWNã§ã¯ãªãœãŒã¹ã解æŸã§ããŸãã Pinbaã®PHPã¢ãžã¥ãŒã«ã¯ãããã®ãã§ãŒãºã®äž¡æ¹ã䜿çšããŸãã RINITã§ã¯ãåæåãããRSHUTDOWNã§ã¯ãèŠæ±ã®åŠçã«è²»ãããããªãœãŒã¹ã®æ°ãèšç®ããããã¹ãŠã®ããŒã¿ãUDPãã±ããã«ãã£ãŠPinbaãµãŒããŒã«éä¿¡ãããŸãã
UDPãã±ãããCã«éä¿¡ããã®ã¯ååã«éããããPinbaã¢ãžã¥ãŒã«ã¯PHPããã»ã¹ã«äœåãªè² è·ãè¿œå ããŸããã ãŸããPinbaã¯ã¢ãžã¥ãŒã«ãšããŠæ©èœãããããã€ã³ã¹ããŒã«ãšæ§æãè¡ãã ãã§ååã§ããPHPã³ãŒããå€æŽããããšãªããããã«ãåã¹ã¯ãªããã®ãªã¯ãšã¹ãæ°ãå¹³åæéãªã©ã®ã·ã¹ãã ã®ãã©ã¡ãŒã¿ãŒãèŠã€ããããšãã§ããŸãããªã©ãªã©ã
æ®å¿µãªãããè€éãªã·ã¹ãã ãããå Žåãå ±éã®ãã©ã¡ãŒã¿ãŒã§ã¯ååã§ã¯ãããŸããã
ã¿ã€ããŒ
æåã¯ãPinbaã®æåã®ããŒãžã§ã³ã«ã¯ã¿ã€ããŒããããŸããã§ããïŒPinba v0.1ãšåŒã³ãŸãããïŒã ãã®ããŒãžã§ã³ã§ã¯ãç¹å®ã®ã¹ã¯ãªãããåŒã³åºãããé »åºŠãå¹³åå¿çæéããã€ãåäœã®å¹³åå¿çãµã€ãºãªã©ãããããŸãã MySQLãmemcachedããŸãã¯ãã®ä»ã®ãµãŒãã¹ãžã®ã¯ãšãªã®é »åºŠãèŠã€ããããšã¯äžå¯èœã§ããã ããã»ã©éèŠã§ã¯ãªãããã«æãããããããŸããããç§ãã¡ã®ã·ã¹ãã ã§ã¯ãMySQLãšmemcachedã«å ããŠãC / C ++ã§æžãããå€æ°ã®ãµãŒãã¹ããããŸãã
ã·ã¹ãã ã«åé¡ãçºçããå ŽåïŒããšãã°ãäœãããã¹ããŒããŠã³ããå§ããå ŽåïŒãPinba v0.1ã¯åé¡ãããããšã瀺ããŸãããããããäœã§ããããããã«ç解ã§ãããšã¯éããŸããã§ããã ã»ãšãã©ã®å Žåããã®ãããªç¶æ³ã§ã¯ãPHPãã¯ãšãªãå®è¡ãããµãŒãã¹ïŒMySQLãmemcachedãªã©ïŒã®1ã€ãæ眪ã§ããã
ãã®ãããªåé¡é åãè¿ éã«èŠã€ããæ¹æ³ãåŠã¶ããã«ããã³ãã®æ¬¡ã®ããŒãžã§ã³ã§ã¿ã€ããŒãå°å ¥ãããŸããã
å®éãmysql_connect / mysql_query / memcache_connectåŒã³åºããªã©ã®åäœæéã枬å®ãããã®æéãPinbaãµãŒããŒã«éä¿¡ããŠã¿ã€ããŒã¬ããŒããäœæããããšã«ããŸããã æ¬äŒŒPHPã³ãŒãã§ã¯ã次ã®ããã«ãªããŸãã
pinba_timer_start(array('type'=>'db::connect', 'host'=>'users.sql')); $conn = mysql_connect(...); pinba_timer_stop();
ããã§ã¯ãmysql_connectåŒã³åºãã®å®è¡æéã枬å®ãã2ã€ã®ã¿ã°ãã¿ã€ããŒã«ã¢ã¿ããããŸããããã«ãããåŸã§ã¬ããŒããäœæã§ããŸãã
ãã¹ãŠã®ã¿ã€ããŒã¯ããã¹ãŠã®ããŒã¿ãšãšãã«PinbaãµãŒããŒã«éä¿¡ãããããã«ã¬ããŒãããŒãã«ãäœæãããŸãã ããã«ãããçŸåšæãæéãããã£ãŠããæäœã確èªã§ããŸãã ããã«ãããšãã°ãæ°çŸã®MySQLãµãŒããŒãããããã®ãã¡ã®1ã€ã ããé ããªãå ŽåãPinbaã¯éåžžã«æè»ãªã¿ã€ããŒã¬ããŒãã¹ããŒã ã®ãããã§åãåé¡ã®ãµãŒããŒãç°¡åã«èšç®ã§ããŸãã
ããŒãã«ã䜿ãå§ãã
ãã³ããã¢ã¯ã»ã¹ã§ããããŒãã«ã®ãªã¹ãã¯æ¬¡ã®ãšããã§ãã
mysql> SHOW TABLES FROM pinba; +--------------------------------------+ | Tables_in_pinba | +--------------------------------------+ | info | | report_by_hostname | | report_by_hostname_and_script | | report_by_hostname_and_server | | report_by_hostname_server_and_script | | report_by_script_name | | report_by_server_and_script | | report_by_server_name | | report_by_status | | request | | tag | | timer | | timertag | +--------------------------------------+ 13 rows in set (0.00 sec)
åŸæ¥ããã¹ãŠã®ããŒãã«ã¯ãçããŒã¿ãšã¬ããŒããå«ãããŒãã«ã®2çš®é¡ã«åé¡ã§ããŸãã
çããŒã¿ã®4ã€ã®ããŒãã«ããããŸãïŒãªã¯ãšã¹ããã¿ã°ãã¿ã€ããŒãã¿ã€ããŒã¿ã°ã ãããã®ããŒãã«ã«ã¯ãæåŸã®æ°åéã®ã¹ã¯ãªãããã¿ã€ããŒãããã³ã¿ã°ãžã®ååŒã³åºãã®èšé²ãå«ãŸããŠããŸãã è² è·ã®é«ãã·ã¹ãã ã§ã¯ããããã®ããŒãã«ã«ã¯äœçŸäžãã®ã¬ã³ãŒããå«ãŸããŠããå¯èœæ§ããããããçŽæ¥äœ¿çšããããšã¯ãå§ãããŸããã 代ããã«ãã·ã¹ãã ããã©ãŒãã³ã¹ãåæããã®ã«ååãªæçšãªããŒã¿ãå«ãã¬ããŒãããŒãã«ã䜿çšããããšããå§ãããŸãã
ã¬ããŒãè¡š
Report_by_script_name-æã䜿çšãããã¬ããŒãã®1ã€ã åã¹ã¯ãªãããåŒã³åºãããé »åºŠãå®è¡ã«ããã£ãå¹³åæéãCPU䜿çšçãããã«èµ·å ãããã©ãã£ãã¯éã«é¢ããæ å ±ãå«ãŸããŠããŸãã
mysql> DESC report_by_script_name; +------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+--------------+------+-----+---------+-------+ | req_count | int(11) | YES | | NULL | | | req_per_sec | float | YES | | NULL | | | req_time_total | float | YES | | NULL | | | req_time_percent | float | YES | | NULL | | | req_time_per_sec | float | YES | | NULL | | | ru_utime_total | float | YES | | NULL | | | ru_utime_percent | float | YES | | NULL | | | ru_utime_per_sec | float | YES | | NULL | | | ru_stime_total | float | YES | | NULL | | | ru_stime_percent | float | YES | | NULL | | | ru_stime_per_sec | float | YES | | NULL | | | traffic_total | float | YES | | NULL | | | traffic_percent | float | YES | | NULL | | | traffic_per_sec | float | YES | | NULL | | | script_name | varchar(128) | YES | | NULL | | +------------------+--------------+------+-----+---------+-------+ 15 rows in set (0.00 sec)
æ¥å°ŸèŸ_totalãä»ãããã£ãŒã«ãã¯ãéå»5åéã®ãã¹ãŠã®ãªã¯ãšã¹ãã«å¯Ÿå¿ããå€ã®åèšã§ãã ã€ãŸããããšãã°ã req_time_totalã¯ãéå»5åéã®å¯Ÿå¿ããã¹ã¯ãªããã®ãã¹ãŠã®ãªã¯ãšã¹ãã®å®è¡æéã®åèšã§ãã ãŸãã req_time_total / req_countã¯ãã¹ã¯ãªããã®å¹³åå®è¡æéã§ãã req_utime_ *ããã³req_stime_ *ãã£ãŒã«ãã¯ããããããŠãŒã¶ãŒã¢ãŒãããã³ã·ã¹ãã ã¢ãŒãã§ã®CPU䜿çšçã瀺ããŸãã
åœç€Ÿã§ã¯ããããã®ããŒã¿ã«åŸã£ãŠãç¹å®ã®ã¹ã¯ãªããã«å¯Ÿãããªã¯ãšã¹ãæ°ã®ã°ã©ããšãã¹ã¯ãªããã«ããCPUæ¶è²»ã®ã°ã©ããäœæããŸãïŒã°ã©ã1ã2ïŒã
å³1
å³è¡š2ã
Report_by_hostname ïŒãã®ã¬ããŒãã¯ãç¹å®ã®ãµãŒããŒã«éä¿¡ããããªã¯ãšã¹ãã®æ°ã瀺ããŸãã ãã£ãŒã«ãã®ãªã¹ãã¯ã»ãšãã©åãã§ãããscript_nameãã£ãŒã«ãã®ä»£ããã«ããã¹ãåãã£ãŒã«ããããŒãã«ã«å«ãŸããŠããŸãã
mysql> DESC report_by_hostname; +------------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------+-------------+------+-----+---------+-------+ | req_count | int(11) | YES | | NULL | | ......... | hostname | varchar(32) | YES | | NULL | | +------------------+-------------+------+-----+---------+-------+ 15 rows in set (0.00 sec)
ãããããhostnameå€æ°ã®HostããããŒã§æž¡ããããã¡ã€ã³ãèŠããšäºæ³ããã人ãããŸãã ããããå®éã«ã¯ãã¹ãåã¯å€æ°$ _ENV ['HOSTNAME']ã®å 容ã§ããããã·ã³ã®ååãå«ãŸããŠããŸãã
ãã®ã¬ããŒãã®äž»ãªç®çã¯ãç¹å®ã®ãµãŒããŒãžã®ãªã¯ãšã¹ãæ°ã«é¢ããæ å ±ãšãäžéšã®ãµãŒããŒãžã®ãªã¯ãšã¹ããè¿é£ãµãŒããŒããå€ããã©ããã«é¢ããæ å ±ãååŸããããšã§ãã
Report_by_server_name ïŒãã®ã¬ããŒãã§ã¯ãããŒã¿ã¯ãªã¯ãšã¹ããéä¿¡ããããã¡ã€ã³ããšã«ã°ã«ãŒãåãããŸãã ç¹å®ã®ãã¡ã€ã³ã«éããããªã¯ãšã¹ãã®æ°ã瀺ããŸãã ããŒãã«æ§é ã¯åã®2ã€ãšåãã§ãããããŒã¿ã®ã¿ãserver_nameãã£ãŒã«ãã§ã°ã«ãŒãåãããŠããŸãã
Report_by_status ïŒãã®ã¬ããŒãã¯ãã¹ã¯ãªãããçµäºããHTTPã¹ããŒã¿ã¹ã衚瀺ããããã«äœ¿çšãããŸãã
mysql> SELECT req_count, status FROM report_by_status; +-----------+--------+ | req_count | status | +-----------+--------+ | 540622 | 200 | | 2578 | 301 | | 21955 | 302 | | 296 | 403 | | 2090 | 404 | +-----------+--------+ 5 rows in set (0.14 sec)
ã¬ããŒãã®ã¹ããŒã¿ã¹ã500ã®å ŽåãPHPã³ãŒãã®ã©ããã«ãèŽåœçãªãšã©ãŒããããããšãæå³ããŸãã
ã¿ã€ããŒãšã¿ã°
äžèšã®ã¬ããŒãã¯ãäžè¬çãªã·ã¹ãã åæã«åœ¹ç«ã¡ãŸãã ãããããã詳现ãªåæã®ããã«ãã¿ã€ããŒãšã¿ã°ã䜿çšããŸãã
ã¿ã€ããŒã¯ãã³ãŒãã®å®è¡æéã§ãã ã¿ã€ããŒã«ã¯è€æ°ã®ã¿ã°ãæ·»ä»ã§ããŸãã ã¿ã°ã«ã¯ããŒãšå€ããããŸãã ããšãã°ãäžèšã®ã¿ã€ããŒã³ãŒãã§ã¯ã
pinba_timer_start(array('group'=>'db::connect', 'host'=>'users.sql')); $conn = mysql_connect(...); pinba_timer_stop();
mysql_connecté¢æ°ã®å®è¡æéã枬å®ããã°ã«ãŒããšãã¹ãã®2ã€ã®ã¿ã°ãæ·»ä»ããŸãã
ããã©ã«ãã§ã¯ãPinbaã«ã¯ã¿ã€ããŒãšã¿ã°ã«é¢ããã¬ããŒãã¯ãããŸããããéåžžã«æè»ã«äœæã§ããŸãã 以äžã§ã¯ãBadooã§ãããã©ã®ããã«è¡ããããã詳ããèŠãŠãããŸãã
ãŸããã¿ã€ããŒã䜿çšããŠãMySQLãmemcachedãC / C ++ã§èšè¿°ããããµãŒãã¹ãªã©ãããŸããŸãªããŒã¿ãœãŒã¹ãžã®ãªã¯ãšã¹ãã«é¢ããçµ±èšãååŸããŸãã ã°ã«ãŒããšãã¹ãïŒãã¹ãã¯ããŒã¿ããŒã¹ãŸãã¯ãµãŒãã¹ã®ã¢ãã¬ã¹ãã°ã«ãŒãã¯ãµãŒãã¹ã®æäœïŒã®2ã€ã®ã¿ã°ãæã€Pinbaã¿ã€ããŒã䜿çšããŠããã®ãããªãã¹ãŠã®ãªã¯ãšã¹ãããã©ãããããŸããã
ãããã£ãŠãPinbaã«éä¿¡ãããã¿ã°ãã·ã¹ãã ã«å®è£ ããå Žåãããã€ãã®ã¬ããŒããäœæã§ããŸãã ãŸãããã¹ãŠã®ã¿ã°å€ã«é¢ããå®å šãªã¬ããŒãã«ãªããŸãã groupã¿ã°ã䜿çšããäŸã§ã¯ããã®æäœãŸãã¯ãã®æäœãåŒã³åºãããé »åºŠãšããã®æäœã«ãããæéïŒåèšïŒã«é¢ããã¬ããŒããäœæã§ããŸãã ãããè¡ãã«ã¯ãããŒãã«ãäœæããŸãã
CREATE TABLE `tag_info_group` ( `tag_value` varchar(64) DEFAULT NULL, `req_count` int(11) DEFAULT NULL, `req_per_sec` float DEFAULT NULL, `hit_count` int(11) DEFAULT NULL, `hit_per_sec` float DEFAULT NULL, `timer_value` float DEFAULT NULL ) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='tag_info:group'
ããŒãã«åã¯ä»»æã§ãããäœã«ã圱é¿ããŸããã ãã£ãŒã«ãã®é åºãäŸãšãŸã£ããåãã§ãããENGINEããã³COMMENT = 'tag_infoïŒgroup'ã®å€ã§ããããšãéèŠã§ãã ã³ã¡ã³ãå ã®groupã¯ãã¬ããŒããäœæããã¿ã°ã®ååã§ãã ãŸããtag_infoã¯ã¬ããŒãã®äžçš®ã§ãïŒtag_reportããããŸããããã«ã€ããŠã¯ä»¥äžã§èª¬æããŸãïŒã
ããŒãã«ãäœæãããšãPinbaã¯èªåçã«ããŒã¿ã®å ¥åãéå§ããŸãã ãã®ã¬ããŒãã¯æ¬¡ã®ããã«ãªããŸãã
mysql> SELECT * FROM tag_info_group ORDER BY timer_value; +--------------------+-----------+-------------+-----------+-------------+-------------+ | tag_value | req_count | req_per_sec | hit_count | hit_per_sec | timer_value | +--------------------+-----------+-------------+-----------+-------------+-------------+ | curl_request | 56216 | 281.08 | 56710 | 283.55 | 11977.3 | | memcache_get | 2563499 | 12817.5 | 11462991 | 57315 | 6823.04 | | hsc_connect | 2319186 | 11595.9 | 2870366 | 14351.8 | 6140.5 | | hsc_open_index | 2319158 | 11595.8 | 3285335 | 16426.7 | 5805.61 | | hsc_select | 2312567 | 11562.8 | 3158465 | 15792.3 | 5778.57 | | memcache_connect | 2563064 | 12815.3 | 4007451 | 20037.3 | 2389.65 | | memcache_set | 917102 | 4585.51 | 1616016 | 8080.08 | 1059.08 | | memcache_delete | 600720 | 3003.6 | 2451872 | 12259.4 | 785.702 | | scribe_receive | 382881 | 1914.41 | 975892 | 4879.46 | 382.522 | | hsc_update | 84877 | 424.385 | 85287 | 426.435 | 317.637 | | hsc_insert | 41564 | 207.82 | 41574 | 207.87 | 280.468 | | scribe_send | 382894 | 1914.47 | 975892 | 4879.46 | 174.156 | | memcache_increment | 60817 | 304.085 | 88734 | 443.67 | 30.9102 | | memcache_add | 14818 | 74.09 | 16281 | 81.405 | 4.71686 | | memcache_multi_get | 2543 | 12.715 | 2543 | 12.715 | 1.59621 | | hsc_delete | 4 | 0.02 | 9 | 0.045 | 0.003373 | +--------------------+-----------+-------------+-----------+-------------+-------------+ 16 rows in set (0.00 sec)
ããšãã°ããã®ã¬ããŒãã¯ãéåžžã«é ãcurl_requestãããããšã瀺ããŠããŸãã
tag_infoã¿ã€ãã®ã¬ããŒãã¯ãã·ã¹ãã ã§ã®äœ¿çšã®æŠèŠã瀺ããŸãã ç¹å®ã®æäœãåŒã³åºãããå Žæããã詳现ã«èª¿ã¹ãã«ã¯ãåãã¬ããŒããäœæããå¿ èŠããããŸãããã¹ã¯ãªããã®ååã§ã°ã«ãŒãåãããŸãã ãããè¡ãã«ã¯ãPinbaã§ããŒãã«ãäœæããŸãã
CREATE TABLE `tag_report_group` ( `script_name` varchar(128) DEFAULT NULL, `tag_value` varchar(64) DEFAULT NULL, `req_count` int(11) DEFAULT NULL, `req_per_sec` float DEFAULT NULL, `hit_count` int(11) DEFAULT NULL, `hit_per_sec` float DEFAULT NULL, `timer_value` float DEFAULT NULL ) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='tag_report:group'
ããŒãã«æ§é ã¯ã以åã®tag_info_groupã¬ããŒããšå€ãã®ç¹ã§äŒŒãŠããŸãã script_nameãã£ãŒã«ãã衚瀺ãããCOMMENTãã£ãŒã«ãã«tag_reportã¿ã€ãã®ã¬ããŒããäœæããããšã«æ³šæããŠãã ããã ãã®ããŒãã«ãããåã®ãã®ãšåãããŒã¿ããã¹ãŠååŸã§ããŸããã script_nameã§ã°ã«ãŒãåãããŸã ã
ç¹å®ã®ã¹ã¯ãªããã§å®è¡ãããæäœã確èªã§ããŸãã
mysql> SELECT tag_value, req_count, hit_count, timer_value, hit_count/req_count FROM tag_report_group WHERE script_name='/admin/messages/all.phtml' ORDER BY timer_value DESC; +--------------------+-----------+-----------+-------------+---------------------+ | tag_value | req_count | hit_count | timer_value | hit_count/req_count | +--------------------+-----------+-----------+-------------+---------------------+ | memcache_get | 107439 | 3227537 | 1060.68 | 30.0406 | | memcache_connect | 107439 | 887789 | 270.919 | 8.2632 | | scribe_receive | 107573 | 283478 | 68.9106 | 2.6352 | | memcache_set | 34339 | 153080 | 50.6079 | 4.4579 | | scribe_send | 107573 | 283478 | 39.7583 | 2.6352 | | memcache_delete | 18236 | 21306 | 4.54436 | 1.1683 | | curl_request | 15 | 15 | 0.514396 | 1.0000 | | memcache_decrement | 1250 | 1250 | 0.251141 | 1.0000 | | memcache_multi_get | 125 | 125 | 0.066473 | 1.0000 | | memcache_increment | 2 | 2 | 0.000336 | 1.0000 | +--------------------+-----------+-----------+-------------+---------------------+ 10 rows in set (0.03 sec)
ãã®äŸã¯ã hit_countãã£ãŒã«ããšreq_countãã£ãŒã«ãã®éãã瀺ããŠããŸã ã Req_countã¯ãæå®ãããtag_valueã®ã¿ã€ããŒãå°ãªããšã1ååŒã³åºãããHTTPèŠæ±ã®æ°ã§ãã Hit_count-æå®ãããtag_valueã®ã¿ã€ããŒãåŒã³åºãããåæ°ã
äžèšã®äŸã¯ãã¹ã¯ãªãã/admin/messages/all.phtmlã§ãmemcache_getãå¹³å30ååŒã³åºãããããšã瀺ããŠããŸãã ããããããã¯ããã°ã©ããŒã®ãšã©ãŒã§ãããããŒãžãæé©åããå¿ èŠããããŸãã
å€æ°ã®ããŒã¿ããŒã¹ãµãŒããŒãmemcachedãããã³ãã®ä»ã®ãµãŒãã¹ãããå Žåã1ã€ã®ãµãŒããŒã®ã¿ããã¹ããŒããŠã³ãããå ŽåããããŸãã ãããŠãäžè¬çãªèæ¯ã«å¯Ÿãããã®ãæå¶ãã¯æããã§ã¯ãªããããããŸããã ãããã®ç®çã®ããã«ã serverãšããå¥ã®ã¿ã°ãäœæããŸããã ãã®ããã«ãäžè¬ã¬ããŒãtag_infoïŒserverãäœæããåãã¹ãã®äžè¬çµ±èšã確èªã§ããŸãã memcachedçµ±èšã®ãµã³ãã«ããŒã¿ã次ã«ç€ºããŸãã
mysql> SELECT * FROM tag_info_server WHERE tag_value LIKE 'memcache%' ORDER BY timer_value; +------------------+-----------+-------------+-----------+-------------+-------------+ | tag_value | req_count | req_per_sec | hit_count | hit_per_sec | timer_value | +------------------+-----------+-------------+-----------+-------------+-------------+ | memcached7.mlan | 350702 | 1753.51 | 1767513 | 8837.57 | 781.644 | | memcached3.mlan | 336217 | 1681.08 | 1734430 | 8672.15 | 871.633 | | memcached1.mlan | 350082 | 1750.41 | 1823910 | 9119.55 | 883.52 | | memcached8.mlan | 357798 | 1788.99 | 1793808 | 8969.04 | 908.848 | | memcached10.mlan | 343287 | 1716.44 | 1757085 | 8785.42 | 909.042 | | memcached5.mlan | 398042 | 1990.21 | 1861729 | 9308.64 | 914.772 | | memcached4.mlan | 401584 | 2007.92 | 1877775 | 9388.88 | 937.53 | | memcached2.mlan | 459912 | 2299.56 | 2028406 | 10142 | 971.189 | | memcached6.mlan | 399768 | 1998.84 | 1912571 | 9562.86 | 975.094 | | memcached9.mlan | 425276 | 2126.38 | 1939575 | 9697.88 | 1008.29 | +------------------+-----------+-------------+-----------+-------------+-------------+ 10 rows in set (0.00 sec)
ãã¹ãã¿ã°ã®äžè¬çãªã¬ããŒãã¯ãååãªæ å ±ãæäŸããŸããã 1ã€ãŸãã¯å¥ã®ãã¹ãã§ã¿ã€ããŒãåŒã³åºãé »åºŠã瀺ããŸãããå®è¡ãããæäœã«é¢ããæ å ±ã¯ãããŸããã 幞ããªããšã«ãPinbaã¯2ã€ã®ã¿ã°ãã°ã«ãŒãåããŠtag_infoãtag_reportãªã©ã®ã¬ããŒããäœæã§ããŸãã
CREATE TABLE `tag_info_group_server` ( `group_value` varchar(64) DEFAULT NULL, `server_value` varchar(64) DEFAULT NULL, `req_count` int(11) DEFAULT NULL, `req_per_sec` float DEFAULT NULL, `hit_count` int(11) DEFAULT NULL, `hit_per_sec` float DEFAULT NULL, `timer_value` float DEFAULT NULL ) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='tag2_info:group,server'
ãã®ã¬ããŒãã䜿çšãããšãåãã¹ãã®æäœã«é¢ããçµ±èšãååŸã§ããŸãã ããšãã°ãç¹å®ã®ãã¹ãã§ã®æäœã®çµ±èšã衚瀺ã§ããŸãã
mysql> SELECT * FROM tag_info_group_server WHERE server_value = 'dbs101.mlan' ORDER BY timer_value; +-------------+--------------+-----------+-------------+-----------+-------------+-------------+ | group_value | server_value | req_count | req_per_sec | hit_count | hit_per_sec | timer_value | +-------------+--------------+-----------+-------------+-----------+-------------+-------------+ | db::replace | dbs101.mlan | 154 | 0.77 | 154 | 0.77 | 0.257526 | | db::delete | dbs101.mlan | 1340 | 6.7 | 1340 | 6.7 | 1.84398 | | db::begin | dbs101.mlan | 6437 | 32.185 | 6589 | 32.945 | 2.96375 | | db::commit | dbs101.mlan | 6437 | 32.185 | 6589 | 32.945 | 3.04067 | | db::insert | dbs101.mlan | 4674 | 23.37 | 11171 | 55.855 | 13.9457 | | db::update | dbs101.mlan | 6358 | 31.79 | 10399 | 51.995 | 18.197 | | db::connect | dbs101.mlan | 16826 | 84.13 | 16826 | 84.13 | 22.1383 | | db::select | dbs101.mlan | 14372 | 71.86 | 47106 | 235.53 | 180.235 | +-------------+--------------+-----------+-------------+-----------+-------------+-------------+ 8 rows in set (0.01 sec)
æãããªçç±ãããã»ãšãã©ã®æéãå ããã®ã¯SELECTã§ãã
ãŸããããšãã°ãç°ãªããã¹ãã§ã®åãæäœã®çµ±èšãæ¯èŒã§ããŸãã memcache_connectã®äŸïŒ
mysql> SELECT server_value, req_count, hit_count, timer_value FROM tag_info_group_server WHERE group_value='memcache_connect' ORDER BY timer_value; +------------------+-----------+-----------+-------------+ | server_value | req_count | hit_count | timer_value | +------------------+-----------+-----------+-------------+ | memcached1.mlan | 366138 | 365061 | 191.808 | | memcached3.mlan | 354688 | 353760 | 192.184 | | memcached10.mlan | 365358 | 364341 | 197.353 | | memcached8.mlan | 368912 | 367839 | 213.768 | | memcached7.mlan | 374160 | 373152 | 215.914 | | memcached5.mlan | 415444 | 414434 | 217.855 | | memcached4.mlan | 423394 | 422242 | 252.416 | | memcached2.mlan | 478949 | 477641 | 272.346 | | memcached6.mlan | 414088 | 413003 | 279.038 | | memcached9.mlan | 441589 | 440481 | 377.952 | +------------------+-----------+-----------+-------------+ 10 rows in set (0.01 sec)
tag2_reportã¿ã€ãã®ã¬ããŒããäœæããããšãã§ããŸãããã®ã¬ããŒãã§ã¯ã2ã€ã®ã¿ã°ã«é¢ããæ å ±ãã¹ã¯ãªããããšã«åé¡ãããŸãã
CREATE TABLE `tag_report_group_server` ( `sc0ript_name` varchar(128) DEFAULT NULL, `tag1_value` varchar(64) DEFAULT NULL, `tag2_value` varchar(64) DEFAULT NULL, `req_count` int(11) DEFAULT NULL, `req_per_sec` float DEFAULT NULL, `hit_count` int(11) DEFAULT NULL, `hit_per_sec` float DEFAULT NULL, `timer_value` float DEFAULT NULL ) ENGINE=PINBA DEFAULT CHARSET=latin1 COMMENT='tag2_report:group,server'
ãã®è¡šã圹ç«ã€äŸã瀺ããŸãã ãã®ã·ã¹ãã ã§ã¯ããã¹ãŠã®ãŠãŒã¶ãŒãæ°çŸã®MySQLãµãŒããŒã«åæ£ãããŠããŸãã ããã¯ã·ã£ãŒãã£ã³ã°ãšåŒã°ããŸãã ç¹å®ã®ã¿ã¹ã¯ã®ããã®ç¹å®ã®äžå€®MySQLãµãŒããŒããããŸãã çè«çã«ã¯ããã¹ãŠã®Webã¹ã¯ãªããã¯ãã·ã£ãŒããã®ã¿ãç §äŒããäžå€®ããŒã¿ããŒã¹ã¯ç §äŒããªãã§ãã ããã ãã·ã£ãŒããã®ãã¹ãåã¯ãdbs *ãŸãã¯dbb *ã§å§ãŸããŸãã ãã®ãªã¯ãšã¹ãã䜿çšããŠãä»ã®MySQLãµãŒããŒã«æ¥ç¶ããã¹ã¯ãªããããããã©ããã確èªã§ããŸãã
mysql> SELECT * FROM tag_report_group_server WHERE tag1_value='db::connect' AND tag2_value NOT LIKE 'dbs%' AND tag2_value NOT LIKE 'dbb%';
ã©ã®ã¹ã¯ãªãããäžå€®ããŒã¿ããŒã¹ã§ã¯ãšãªãå®è¡ãããã瀺ããŸãã
nginx +ãã³ã
ããããããã ãã§ãååã§ã¯ãããŸããã§ããã ã¯ã©ã€ã¢ã³ããHTTPãªã¯ãšã¹ããéä¿¡ãããšãåŸè ã¯ãŸãnginxã«å ¥ãã次ã«PHPã«ãããã·ããŸãã ãã®æç¹ã§PHPããã»ã¹ããªã¯ãšã¹ããåãå ¥ããŠåŠçã§ããªãå Žåã¯ã©ããªããŸããïŒ ããšãã°ããµãŒããŒãéè² è·ã«ãªã£ãŠããå ŽåããŸãã¯ãããã¯ãŒã¯ã®åé¡ãåå ã§ãnginxãphp-fpmããã»ã¹ã«æ¥ç¶ã§ããŸãããïŒ ãã®å ŽåããŠãŒã¶ãŒã«ã¯ãšã©ãŒã衚瀺ãããŸãããPHPã§ã¯ãšã©ãŒãããããŸããïŒnginxãã°ã«ã¯èšé²ãããŸãïŒã
ã¯ã©ã€ã¢ã³ãã«è¿ãå¿çïŒHTTPã¹ããŒã¿ã¹ïŒãææ¡ããããã«ãPinbaéçºè ã®Anton Dovgalã¯nginxã®ã¢ãžã¥ãŒã«ãäœæããŸããã nginxã®ã¢ãžã¥ãŒã«ã¯PHPã¢ãžã¥ãŒã«ãšåãããã«æ©èœããŸãããæãããªçç±ããã¿ã€ããŒã¯ãããŸããã 圌ãäœæããæãæçšãªã¬ããŒãã¯ã report_by_script_and_statusããã³report_by_statusã§ãã
ãããã
ãã³ãã¯æåŸã®æ°åéã®ããŒã¿ãä¿åããŸãã ãã®æéã¯èšå®ã§å€æŽã§ããŸã ã ããããããã¯ã·ã¹ãã ã®ããã©ãŒãã³ã¹ãæéãšãšãã«ã©ã®ããã«å€åããããç£èŠãããå Žåã«ã¯ååã§ã¯ãããŸããã ãããè¡ãã«ã¯ãPinbaã¬ããŒãããŒã¿ïŒå¿ ããããã¹ãŠã§ã¯ãªãïŒãé·æéä¿åããã°ã©ããäœæããå¿ èŠããããŸãã ãããã£ãŠãã·ã¹ãã ãšãã®åã ã®ã¹ã¯ãªããã®è² è·ã®ãã€ããã¯ã¹ã芳å¯ããããPHPã³ãŒããããŒã¿ããŒã¹ãmemcachedãããã³ãã®ä»ã®ããŒã¿ãœãŒã¹ãããŒãããæ¹æ³ãç£èŠãããã§ããŸãã
ãã³ãã¯ãé·æéã«ããã£ãŠããŒã¿ãããããããã³ä¿åããæ¹æ³ãç¥ããŸããã ãã®ããã«ã¯ãåå¥ã®ãŠãŒãã£ãªãã£ã䜿çšããå¿ èŠããããŸãã ãã³ããç£èŠãããã®å€ã®äžéšã«åºã¥ããŠã°ã©ããäœæããããã«Zabbixãèšå®ã§ããŸãã RRDtoolãGraphiteãªã©ã®ãªã³ã°ïŒãµã€ã¯ãªãã¯ïŒããŒã¿ããŒã¹ã䜿çšã§ããŸãã åœç€Ÿã§ã¯ãRRDtoolã䜿çšããŠããŸãã
RRDtoolã¯ç°¡åã«èª¬æããŠããŸããã 圌ã«ã¯å€ãã®ãã¥ã¢ã³ã¹ãããããã£ãŒãäœæã®å¥œã¿ã¯äººã«ãã£ãŠç°ãªãããããã®ãããã¯ã¯å¥ã®èšäºã«å€ããŸãã ã€ã³ã¿ãŒãããã«ã¯ããã®ãŠãŒãã£ãªãã£ã»ããããŒãããå§ããã®ã«åœ¹ç«ã€ååãªã¬ã€ããæ¢ã«ãããŸãã
çµæ
ãã³ãã¯ç§ãã¡ã«äœããããŸãããïŒ ã»ãšãã©ã®ããã©ãŒãã³ã¹ã®åé¡ã¯ããã®å®è£ åããããã£ãšæ©ãæ€åºããå§ããŸããã ã¹ã¯ãªããããŠãŒã¶ãŒã«ããé »ç¹ã«èŠæ±ãããããã«ãªã£ãå Žåããã³ãã§ç°¡åã«èŠã€ããããšãã§ããŸãã ãµãŒãã¹ã®1ã€ïŒMySQLãmemcachedãªã©ïŒã®åäœãçªç¶é ããªã£ãå ŽåãPinbaã®é©åãªã¬ããŒãã䜿çšãããšããã®ãµãŒãã¹ãç°¡åã«ããŒã«ã©ã€ãºã§ããŸãã ãŸãããªã¯ãšã¹ãã®é »åºŠãé«ãããã«ãã¹ããŒããŠã³ããå§ããå ŽåãPinbaã®ãããã§ãç¹å®ã®åé¡ãµãŒãã¹ãé »ç¹ã«ãªã¯ãšã¹ãããã¹ã¯ãªãããããŒã«ã©ã€ãºã§ããå ŽåããããŸãã
æ°ããããŒãžã§ã³ã®ã³ãŒãããµãŒããŒã«ã¢ããããŒãããåŸããã³ããã£ãŒããèŠããšéåžžã«äŸ¿å©ã§ãã ã·ã¹ãã ã®è² è·ãã©ã®ããã«å€åãããã確èªã§ããŸãã ãã ãããã®ããã«ã¯ãã©ã®ãããªã°ã©ããäœæãããããèããããšãéèŠã§ãã
ãã ãããµãŒããŒå šäœã®ç£èŠã®ä»£ããã«Pinbaã䜿çšããªãã§ãã ããã ããšãã°ãZabbixã䜿çšããŠããã¹ãŠã®ãµãŒããŒã®CPUãã¡ã¢ãªããã£ã¹ã¯ãããã³ãããã¯ãŒã¯ã¢ã¯ãã£ããã£ã®æ¶è²»ãç£èŠããŸãã äžæ¹ãRRDã«ã¯ãã£ãŒããå«ãPinbaããããŸãã ããã2ã€ã®ã·ã¹ãã ã®ã°ã©ããæ¯èŒããããšã«ãããPHPãªã¯ãšã¹ãã®ãã³ã¹ãããç°¡åã«èšç®ãããµãŒããŒã1ç§éã«åŠçã§ãããªã¯ãšã¹ãã®æ°ãèŠç©ããããšãã§ããŸãã ãããŠãããã«ãããè¿ãå°æ¥ã«æ°ãããµãŒããŒãè³Œå ¥ããå¿ èŠãããã®ãââãã³ãŒããæé©åããæ©äŒãããã®ãââãèšç»ã§ããŸãã
PHPã¢ãžã¥ãŒã«ãšã¯å¥ã«ãPinbaã¯æ±ºããŠPHPã«é¢é£ä»ããããŠããããä»ã®èšèªã§æžãããã·ã¹ãã ãç£èŠããããã«äœ¿çšã§ããŸãã GitHubã«ã¯ãæ¢ã«PythonãšRubyã§Pinbaã䜿çšãããããžã§ã¯ãããããŸãã
ããã·ã max_m Matyukhinãéçºè
ããã¥ãŒäŒç€Ÿ