AWS CloudWatchのメトリクスをCLIからカジュアルに確認できるツールkumomeを作った

AWSのCloudWatchのメトリクスをCLIからカジュアルに確認したいと思ってツールを作り始めている - Copy/Cut/Paste/Hatena

の続きです。kumome という名前でリリースしました。

github.com

asciicast

これは何?

AWS CloudWatchのメトリクスをCLIから確認するためのツールです。特徴としてコマンドオプションをYAMLファイルで拡張できます。

インストールは

$ gem install kumome

デフォルトの設定では ec2 rds elb のメトリクスを取得可能になっています。

$ kumome --ec2=i-123ab45c,i-890ed12c --rds=my-rds --elb=my-elb --profile mycreds

デフォルトの設定は以下。kumome config で現在の設定を出力可能です。

---
resources:
  ec2:
    namespace: AWS/EC2 # required
    dimensions_name: InstanceId # required
    metrics:
      cpu:
        metric_name: CPUUtilization # required
        statistic: Average # required
        unit: Percent
        alarm: '>=50' # "metric alarm name" or "operator and number"
      netin:
        metric_name: NetworkIn
        statistic: Average
        unit: Bytes
      netout:
        metric_name: NetworkOut
        statistic: Average
        unit: Bytes
  rds:
    namespace: AWS/RDS
    dimensions_name: DBInstanceIdentifier
    metrics:
      cpu:
        metric_name: CPUUtilization
        statistic: Average
        unit: Percent
        alarm: '>=50'
      read:
        metric_name: ReadIOPS
        statistic: Average
        unit: Count/Second
      write:
        metric_name: WriteIOPS
        statistic: Average
      conn:
        metric_name: DatabaseConnections
        statistic: Average
        unit: Count
        alarm: '>=50'
  elb:
    namespace: AWS/ELB
    dimensions_name: LoadBalancerName
    metrics:
      req:
        metric_name: RequestCount
        statistic: Sum
      400:
        metric_name: HTTPCode_Backend_4XX
        statistic: Sum
      500:
        metric_name: HTTPCode_Backend_5XX
        statistic: Sum

例えばAWS Lambdaのメトリクスを取得したいときには、以下のようなコンフィグを記述します。

---
resources:
  lambda: # "command option name"
    namespace: AWS/Lambda # required
    dimensions_name: FunctionName # required
    metrics:
      count:
        metric_name: Invocations # required
        statistic: Sum # required
        unit: Count
        alarm: '>=100' # "metric alarm name" or "operator and number"
      error:
        metric_name: Errors
        statistic: Sum
        unit: Count
        alarm: '>=5'
      duration:
        metric_name: Duration
        statistic: Average

そうすれば新たに ---lambda オプションをつくることができます。

$ kumome --config=./custom.yml --lambda=my-lambda-func-name,hook-lambda-func-name --profile mycreds

カスタムメトリクス用のコマンドオプションも作り放題です。

というわけで

自分は、プロジェクトごとにconfig.ymlを作成しておいて、何かあったときは、Amazon Management Consoleにログインして確認するのではなく、まず kumome でざっと確認するようにしています。

カジュアルに確認できるので、心理的に良いです。

まだ、作り始めたばかりですので機能も少ないですが是非お試し下さい。 Pull Requestお待ちしています。