Mackerel Advent Calendar 2015 12æ11æ¥ã®è¨äºã§ãã
æ¨æ¥ã®æ
å½ã¯ @kuchitama ããã§ããã
qiita.com
blog.share-wis.com
ããã«ã¡ã¯ã ãã¦ã«ããï¼ id:stefafafan ) ã¨ããã¾ããMackerelãã¼ã ã«é å±ãã¦ããæ°å ¥ç¤¾å¡ã§ããèªåã¯å ã 大å¦ã§ã¯Webç³»ã®ãã¨ã¯ã»ã¨ãã©ãã£ã¦ããªãã£ãã®ã§ããµã¼ãç£è¦ãã»ã¼ç¡ç¸ã§ããï¼ãããããããã£ãã¨ã³ã¸ãã¢ãå¤ãã¨æãã¾ããï¼Mackerelã¯ãããããµã¼ãã¨ãã«å ¨ç¶è©³ãããªãã¨ã³ã¸ãã¢ã«å¯¾ãã¦ãã¨ã¦ãããããã¦ãå®ã¯ãµã¼ã以å¤ã®ãã¨ãè²ã ç£è¦ã§ããã®ã§ä»åã¯ç§ã®å¥½ããªTwitterãç£è¦ãã¦ã¿ã¾ããã
æé ã¯ä»¥ä¸ã®ã¨ããã§ãã
- Mackerelã«ã¦ã¼ã¶ç»é²ãã
- ãµã¼ãã¹ãç»é²ãã
- Twitter APIãå©ã
- ãµã¼ãã¹ã¡ããªãã¯ãPOSTãã
- åªè¶æã«æµ¸ã
Mackerelã«ã¦ã¼ã¶ç»é²ãã
ã¾ãã¯ã¦ã¼ã¶ç»é²ãã¾ããããç»é²ã¯ã¨ã¦ãç°¡åã§ãï¼æåã®2é±éã¯ãã©ã¤ã¢ã«æéã§è²ã
ãªæ©è½ã試ãã¦ããã®å¾ããªã¼ãã©ã³ã«ãã¤ãã¾ãï¼ã
Sign Up · Mackerel
ç»é²ããããã¥ã¼ããªã¢ã«ã¨ãã表示ãããã¨æãã®ã§ãã®ã¸ãããã£ã¦ã¿ãã¨è¯ãã¨æãã¾ãã
ãµã¼ãã¹ãç»é²ãã
å·¦å´ã«ãµã¤ããã¼ãããã¨æãã¾ããããã« Services ã¨ããé
ç®ãããã®ã§ã¯ãªãã¯ãã¦ãæ°ãããµã¼ãã¹ã追å ãã¦ã¿ã¾ãããããµã¼ãã¹åã¨ã¡ã¢ãèªç±ã«æå®ãã¦ããã¾ããããããã¾ã§åºæ¥ããããããç»é¢ã«ãªããã¨æãã¾ãã
Roles 㨠Service Metrics ã¨ããï¼ã¤ã®ã¿ããããã¾ãããä»å㯠Service Metrics ã®ã¿ãã使ãã¾ããService Metrics ã¿ãã«è¡ãã¨å®éã«è©¦ãã curl ã³ãã³ããããã®ã§ãããå®è¡ãã¦ã¿ãã¨ã°ã©ãã表示ããã¾ããç°¡åï¼ï¼
Twitter APIãå©ã
ä»åã¯ã¨ããããèªåã®TLã®æµéã観測ãããã¨æããPythonç¨ã®Twitterã©ã¤ãã©ãªã®Tweepyã使ã£ã¦1åéã«æµãã¦ãããã¤ã¼ãæ°ãéè¨ãã¦ã¿ã¾ãããä»åã¯Mackerelã®è¨äºãªã®ã§Twitterã®APIãtweepyã®ä½¿ãæ¹ãªã©ã¯ä»¥ä¸ã®è¨äºãåç
§ãã¦ãã ããã
stefafafan.hatenablog.com
ãµã¼ãã¹ã¡ããªãã¯ãPOSTãã
ãã¦ãTwitterãããã¤ã¼ãæ°ãªã©ãéè¨ãããã©ãããã°ããã®ã§ããããã
ä¸ã®curlã³ãã³ããè¦ãæ¹ãªããããã¨æãã¾ãããname, time, valueã®3é
ç®ãPOSTããã ãã§ã°ã©ãã«å¤ãåæ ããã¾ãããµã¼ãã¹ã¡ããªãã¯ã®ååã¨åå¾æéã¨å¤ã§ããã
ããã®é
åãä½ããJSONãPOSTããã°ããã ãã§ããç§ã¯ä»¥ä¸ã®ãããªJSONãPOSTãã¾ããã
[ { 'name': 'twitter.userstream.stefafafan_tweet_count', 'time': 1449221691, 'value': userFeedCount }, { 'name': 'twitter.userstream.timeline_tweet_count', 'time': 1449221691, 'value': homefeedCount }, { 'name': 'twitter.userstream.retweeted_tweet_count', 'time': 1449221691, 'value': retweetedFeedCount } ]
ãªãPOSTã®ä»æ¹ã«ã¤ãã¦ã§ãããèªåã®å¥½ããªè¨èªã§JSONåãã¦ãªã¯ã¨ã¹ããéãã°ããã ãã§ãããä¾ãã° Python ã ã¨ä»¥ä¸ã®ãããªPythonåãã®Mackerelã¯ã©ã¤ã¢ã³ããããã®ã§ä¾¿å©ã§ãã
github.com
ããã使ãã°ä¸è¨ã® metrics é åããã®ããã«ç°¡åã«POSTã§ãã¾ãï¼
client = Client(mackerel_api_key='<API key>') client.post_service_metrics('<Service name>', metrics)
åªè¶æã«æµ¸ã
ä¸è¨ã®ç°¡åãªã¹ãããã«ããç¡äºTLãç¾ããMackerelã®ã°ã©ãã§ç£è¦ã§ããããã«ãªãã¾ããã
ä¸ç®ã§æ·±å¤ã®æµéã®éãã«å¯¾ãããåå4~5æã®æµéã®é
ããæ¯è¼ã§ãã¦æ¥½ããã§ãã
èªåã®ãã¤ã¼ãã»ãªãã¤ã¼ãã»ãã以å¤ã®ãã¤ã¼ãã§ããã¦éè¨ãã¦POSTãã¦ãã®ã§ããããæãã®ã°ã©ãã«ãªã£ã¦ãã¾ãã
ãã®è¨äºã§ãMackerelã£ã¦é£ãããã ãã触ãã¦ããªãâ¦ãã£ã¦äººãã¡ãã£ã¨ã§ã触ã£ã¦ã¿ããã£ã¦æ°åã«ãªãããå¬ããã§ããã
ããããå
ãã£ã¨è²ã
ããã¨ããããä¾ãã°æµéã100ãã¤ã¼ã/åã®ã¨ãã«ã¢ã©ã¼ããçºçããã¦Slackã«æµãã¦ã¿ãã¨ãããã¨æ¥½ããããããã¾ããã
ã¿ãªããããã²Mackerelãè²ã
ãªãã®ã«æ´»ç¨ãã¦ã¿ã¦ãã ããã
ã¨ãããã¨ã§Mackerel Advent Calendar 2015ã12æ11æ¥ã®è¨äºã§ããã
ææ¥ã®æ
å½ã¯ la_luna_azul ããã§ãã