LoginSignup
5
3

More than 5 years have passed since last update.

Slack通知: AWSコストとTrusted Advisorを見やすく表現する

Last updated at Posted at 2018-02-19

何かを解決したいときの第一歩は、可視化から始めるとよいでしょう。
ということで、AWSコストとTrusted AdvisorをSlackに見やすく通知してみました。

全体的に気をつけた点

  • ファーストビューに収める
  • グラフィカルにする。絵文字を使う

Trusted Advisor

image.png

Slackメッセージのattachmentsサンプル

Ruby風


{
    "attachments": [{
        "text": "<https://console.aws.amazon.com/trustedadvisor|TrustedAdvisor>
${savings}/月 節約できるかも?",
        "fields": [{
            "title": ":moneybag:コスト最適化",
            "value": ":broken_heart: ${cost_optimizing.error} :yellow_heart: ${cost_optimizing.warning}",
            "short": true
        }, {
            "title": ":timer_clock:パフォーマンス",
            "value": ":broken_heart: ${performance.error} :yellow_heart: ${performance.warning}",
            "short": true
        }, {
            "title": ":closed_lock_with_key:セキュリティ",
            "value": ":broken_heart: ${security.error} :yellow_heart: ${security.warning}",
            "short": true
        }, {
            "title": ":umbrella:フォールトトレランス",
            "value": ":broken_heart: ${fault_tolerance.error} :yellow_heart:  ${fault_tolerance.warning}",
            "short": true
        }, {
            "title": ":chart_with_upwards_trend:サービス制限",
            "value": ":broken_heart: ${service_limits.error} :yellow_heart:  ${service_limits.warning}",
            "short": true
        }],
        "color": "#DDDDDD"
    }]
}

利用するAWSのAPI

  • DescribeTrustedAdvisorCheckSummaries
    • Trusted Advisorのデータ取得
  • DescribeTrustedAdvisorChecks
    • Trusted Advisorのカテゴリ名を一括取得するだけ

工夫した点

  • Trusted Advisorの各カテゴリのマークに絵文字を合わせた
  • 重要なものだけ見せるため、問題のないGreen表示はカットした

AWSコスト

image.png

Slackメッセージのattachmentsサンプル

python風

{"attachments": [
        {
            "title": "今月のAWSコスト",
            "title_link": "https://console.aws.amazon.com/billing/home",
            "fields": [
                {
                    "title":  "¥{:,d}".format(math.ceil(total_cost)*rate) + ' ぐらい(現在)\n',
                    "value":  formatted_text + '\n今日までで${cost}'.format(cost=total_cost),
                    "short": "false"
                },
            ],
            "color": "#fff600",
            'ts':time.time(),
            "footer": '📕 {no1} ${no1cost} \n📒 {no2} ${no2cost}\n📗 others'.format(no1=no1,no2=no2 ,no1cost=no1cost ,no2cost=no2cost)
            }]
}

利用するAWSのAPI

  • GetMetricStatistics : コストの取得
  • ListMetrics : AWSサービス名を一括取得するだけ

工夫した点

  • 割合を表現するため、7×7の49マス正方形を利用する
    • 1マス約2%となる
    • 長さ高さも大きすぎず小さすぎず
  • 各マスについては端数は大雑把に処理する
    • 多少ずれてても趣旨はぶれない
5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3