S3での利用料金解析

設定

インストール

ec2にインストール。やり方はここの通り
http://kazeburo.github.com/GrowthForecast/

起動

外からアクセスしたい場合は、ポートをec2で開けておく。データの保存場所を指定
growthforecast.pl --data-dir ~/gw --port 20008

データ保存

例えば、vegetation-billing-dailyのグラフに現時点の値=30を入力
curl -F number=30 http://localhost:20008/api/vegetation/billing/daily

データの確認、保存

ここからアクセス
http://hogehoge:20008/
もしくは、グラフだけ直接
http://hogehoge:20008/list/vegetation/billing?t=sh
daily.pngに保存
curl -o daily.png "http://localhost:20008/graph/vegetation/billing/daily?t=sh&gmode=gauge"

s3 billing csv との連携
  1. s3cmdでbilling csv を取ってくる。
  2. トータル料金を抜き出す
  3. GrowthForecastに値を送る
  4. グラフをpngで保存する
  5. pngをS3にs3cmdで戻す


billing.shで以下を保存して定期実行

s3cmd --force get s3://ecoris/399748833865-aws-billing-csv-2013-04.csv billing04.csv
data=$(tail -n 2 billing04.csv |sed -n '1p'|awk -F"," '{gsub("\"","",$29);print $29}'|cut -d '.' -f 1)
echo $data
curl -F number=${data} http://localhost:20008/api/vegetation/billing/daily
curl -o daily.png "http://localhost:20008/graph/vegetation/billing/daily?t=sh&gmode=gauge"
s3cmd put daily.png s3://ecoris/vegetation/html/

毎時0分に実行
sudo crontab -e

0 * * * * /home/ubuntu/test.sh
fluentd(td-agent?)

fluentdを使えば、上記のログを取ってきて、GrowthForcastへ出力の部分が汎用的にできるようになるが、S3からログを取ってくるプラグインが見つからないのと、pngをアップする部分は結局、別で実行しなくてはいけないので、すべてお手製スクリプトで作成

http://help.treasure-data.com/kb/installing-td-agent-daemon/installing-td-agent-for-debian-and-ubuntu
http://d.hatena.ne.jp/naoya/20130219/1361262854

ファウンディング

クラウドファウンディング
個人スポンサー
http://www.goodsmileracing.com/personal-sponsors.html