ãã®è¨äºã¯ Mackerel Advent Calendar 2024 ã® 9 æ¥ç®ã®è¨äºã§ãã
æ®æ®µä½¿ãã®ã¢ãã¤ã«åç·ã¯ docomo ã¨ããã irumo ãªãã§ãããèªå® ããé¢ãã¦çæ´»ããã¨ã®ã¬ã使ãåã£ã¦è²·ã足ãæ¥ã ãéã£ã¦ãã¾ãã
ãã¼ã¿éä¿¡éã£ã¦ãªããä¸æããã¨ã¢ã©ã¼ãåºããªãã§ãããã2GB 使ã£ãå¾ã«ã使ã£ã¦ãããã£ã¦è¨ããã¦ãå°ããã¨ãããã㧠Mackerel ã§ç£è¦ããããã«ãã¾ããã
ã¾ãã¯ãã©ã¦ã¶ãã https://irumo.docomo.ne.jp/ ã触ã£ã¦ Developer Tools ã® Network ã¿ããçºããã
https://irumo.docomo.ne.jp/api/uw/tra/v1.0/getdatareferenceinf
ã¸ã® POST 㧠JSON ãè¿ã£ã¦ãã¦ããã£ã½ãã®ãåãã£ãã®ã§ããªã¯ã¨ã¹ãããããã©ãã¾ã§åã£ã¦ãåãããã試ãã
ä»å㯠spsp
Cookie ã ã渡ãã°åãã£ã½ãã£ãã§ãã
curl 'https://irumo.docomo.ne.jp/api/uw/tra/v1.0/getdatareferenceinf' \ -H 'User-Agent: DataUsageCheckerBot/1.0 (@onk)' \ -H 'Cookie: spsp=xxxxxxxx' \ -H 'Content-Type: application/x-www-form-urlencoded' \ --data-raw 'requestpatterncode=0009&getuser_div=3'
{ ... "data": { ... "daydatainfo": { ... "dayusedatainfo_list": [ { "targetdate": "20241201", "daydatadetailinfo": { "databypacket": "973737", "databygb": "0.93", "speedlimitreleasecount": "0" }, "speedlimitreleasecountinfo": { "databypacket": "0", "databygb": "0.00" }, "highspeeddatainfo": { "databypacket": "973737", "databygb": "0.93" } }, ...
åæ¥ã®ãã¼ã¿ã« speedlimitreleasecount
ã¨ãã¦è²·ã足ããåæ°ãå
¥ã£ã¦ãã®ãã¡ãã£ã¨é¢ç½ããhighspeeddatainfo
㨠speedlimitreleasecountinfo
ã¯ããããé常æã¨é度å¶éæã§ä½¿ã£ãéä¿¡éã§ããã
JSON ãåããããã¨ã¯å å·¥ã㦠Mackerel ã«éãã°å®æãããï¼
å¤ãåãã®ã¯ jq ã§ã¨ã¤ã£ã¦ããã¾ãã
... | jq -r ' .data.daydatainfo.dayusedatainfo_list[] | select(.targetdate | test("20241201")) | .daydatadetailinfo.databypacket'
973737
ããã£ã½ãæ°åãåããã®ã§éä¿¡ç¨ã«ã¡ãã£ã¨å å·¥ã
ã¾ããã¼ãã³ã¼ããã¦è©¦ãã¦ãã test("20241201")
ã®é¨åã¯å¤ãã --arg today $(date '+%Y%m%d')
ã¨æ¸¡ãã¾ãã
ã¾ããMackerel åãã«æãããªãã¿ãåºåãã®æååã«ãããã§ãããã\(...)
㧠String interpolation ã§ããããnow
ã§ç¾å¨æå»ãé¬æã§ããã®ã§ãå
¨ä½ã¯ãããªãã¾ãã
... | jq -r --arg today $(date '+%Y%m%d') ' .data.daydatainfo.dayusedatainfo_list[] | select(.targetdate | test($today)) | "custom.irumo.data-usage\t\(.daydatadetailinfo.databypacket)\t\(now)"'
custom.irumo.data-usage 908991 1733754915
ãã¨ã¯ mkr throw
ã§æãã¦å®æã§ãã
... | mkr throw --service irumo
ãã¼ã¿ãæºã¾ã£ããç·å½¢å帰é¢æ°ã使ã£ã¦ã¢ã©ã¼ããæããããã¦éã³ã¾ãããã身ã®åãã®ã¡ããªãã¯ã£ã½ããã¼ã¿ã¯ã¨ãããã Mackerel ã«æãã¦ããã¨ããã®ãã¡ä½¿ãéãæãã¤ããã®ã§ãã
Mackerel Advent Calendar 2024ãææ¥ã¯ id:taxintt ããã§ãã
追è¨
1 æ¥ã®ãã¼ã¿åãåºãã¦ãæ¯æ¥ 0 ããå§ã¾ã£ã¦ãã¾ãã®ã§ãä»æã®ãã¼ã¿ãåè¨ããå¿ è¦ãããã¾ããã
jq -r --arg month $(date '+%Y%m') ' (.data.daydatainfo.dayusedatainfo_list | map( select(.targetdate | test($month)) | .daydatadetailinfo.databypacket | tonumber ) | add) as $total | "custom.irumo.data-usage\t\($total)\t\(now)" '