Reputation: 29
Is there any way to find (using Ruby) the Total time running over the past 30 days by an AWS Instance , and the total cost for the time.
Upvotes: 2
Views: 672
Reputation: 91
Full disclosure: I'm an engineer at Cloudability but we have an EC2 analytics product that will track instance uptime as well as utilization and bunch of other metrics.
Some info if you're interested:
http://blog.cloudability.com/ghost-devops-past/
https://cloudability.com/features/
Upvotes: 0
Reputation: 12901
If you want to keep a better eye on your costs running in AWS, you have a rather new option to access your billing information programatically.
You can set up an S3 bucket that will be used to upload a detailed billing information in CSV format every few hours. Then you can access these CSV files and analyze what are your costs in different sections as EC2, RDS, DynamoDB and all others.
It gives you a better solution for checking your costs status beyond a single instance. You can access your billing information files in S3 with your Ruby SDK.
See more details here: http://docs.aws.amazon.com/awsaccountbilling/latest/about/programaccess.html
Note that you can also define CloudWatch alerts that are based on Billing.
You can define what is your expected cost and get notifications once you are 50%, 80% and over your expectation, for example.
See more details here: http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/ListMetricsExample.html
Upvotes: 3
Reputation: 30565
You can use the AWS Ruby SDK found here: https://github.com/aws/aws-sdk-ruby
There's documentation on how to use the SDK: http://docs.aws.amazon.com/AWSRubySDK/latest/frames.html
In the documentation - http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/Instance.html for EC2 instance you can get the instance launch time. You can then work out, based on your Region how long the instance has been running and your cost based on Instance Type (Which the SDK also returns)
UPDATE
Based on the comments there is also options to use 3rd Party cost monitoring tools such as:
Upvotes: 2