Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CloudWatch から Mackerel にメトリックを送る方法 2019年版 / Mac...

CloudWatch から Mackerel にメトリックを送る方法 2019年版 / Mackerel Meetup 13

FUJIWARA Shunichiro

March 01, 2019
Tweet

More Decks by FUJIWARA Shunichiro

Other Decks in Technology

Transcript

  1. Metrin - AWS CloudWatchͷ൚༻؂ࢹϓϥάΠϯ github.com/y13i/metrin $ metrin --namespace AWS/EC2 \

    --metric-name CPUUtilization \ --statistic Average --dimension InstanceId:i-xxxxxxxxx \ --start-time -600 print --last-value-only CloudWatch.InstanceId.i-xxxxxxxxx.CPUUtilization.Average 1.468 1482596160 mackerel-agent ͕ѻ͑ΔܗࣜͰprint͢ΔͷͰ agent ͔Βୟ͘ 1ϝτϦοΫ͝ͱʹίϚϯυ࣮ߦ αʔϏεϝτϦοΫ͸ mackerel-agent Ͱ͸౤ߘͰ͖ͳ͍
  2. mackerel-cloudwatch-forwarder github.com/shogo82148/mackerel-cloudwatch-forwarder Lambda function. JSONͰऔಘ͢ΔϝτϦοΫΛఆٛ { "service_metrics": [ { "service":

    "your service name", "name": "metric name on mackerel", "metric": [ "Namespace", "MetricName", "Dimension1Name", "Dimension1Value", {} ], "stat": "Sum" } ], "host_metrics": [ { "hostId": "host id", "name": "metric name on mackerel", "metric": [ "Namespace", "MetricName", "Dimension1Name", "Dimension1Value", {} ], "stat": "Sum" } ] }
  3. ͜Ε·ͰͷιϦϡʔγϣϯ CloudWatch ͷ GetMetricStatistics API Λ࢖͍ͬͯΔ → 1ϝτϦοΫ͝ͱʹ 1 API

    call ͕ൃੜ͢Δ ઃఆͷ֬ೝ͕೉͍͠ → ಈ͔ͯ͠Έͳ͍ͱҙਤͨ͠஋͕సૹͰ͖͍ͯΔ͔෼͔ΓͮΒ ͍ (Mackerelʹؒҧͬͨ஋ΛೖΕͯ͠·͏ͱফͮ͠Β͍)
  4. MetricDataQuery JSON [{ "Id": "m1", "Label": "service=MyService:alb.my-alb.response-time.p99", "MetricStat": { "Metric":

    { "Namespace": "AWS/ApplicationELB", "MetricName": "TargetResponseTime", "Dimensions": [{ "Name": "LoadBalancer", "Value": "app/my-alb/8e0641feccf3491c" }] }, "Period": 60, "Stat": "p99" } }, { "Id": "m2", "Label": "service=MyService:alb.my-alb.response-time.p90", "MetricStat": { "Metric": { "Namespace": "AWS/ApplicationELB", "MetricName": "TargetResponseTime", "Dimensions": [{ "Name": "LoadBalancer", "Value": "app/my-alb/8e0641feccf3491c" }] }, "Period": 60, "Stat": "p90" } }]
  5. Go ϥΠϒϥϦ import ( "github.com/fujiwara/cloudwatch-to-mackerel/agent" ) query := []byte(`[ ...

    ]`) // MetricDataQuery JSON err := agent.Run(agent.Option{Query: query}) ؀ڥม਺Ͱೝূ৘ใ͕ద੾ʹઃఆͯ͋͠Ε͹͜Ε͚ͩ Lambda Ͱ΋ಈ͔ͤ·͢
  6. ͍͍ͱ͜Ζ MetricDataQuery JSON ͸ aws-cli Ͱ࢖͑ΔܗࣜͱಉҰ → aws cloudwatch get-metric-data

    Ͱઃఆ֬ೝ͕༰қ ϗετɾαʔϏεϝτϦοΫ྆ରԠ Metric Math ʹ΋ରԠ → ෳ਺ϝτϦοΫͷԋࢉ݁ՌͰΞϥʔτͱ͔ Enjoy!