Skip to content

Instantly share code, notes, and snippets.

@wesleyit
Last active August 29, 2015 14:02
Show Gist options
  • Save wesleyit/618af2527b74771c6f04 to your computer and use it in GitHub Desktop.
Save wesleyit/618af2527b74771c6f04 to your computer and use it in GitHub Desktop.
With this ruby script, you will be able to calculate how many minutes left to complete 1 more hour of utilization.
#!/usr/bin/ruby
# ##########################################################
# Encoding: UTF-8
# calc_ec2_time_left.rb
# With this ruby script, you will be able to calculate
# how many minutes left to complete 1 more hour of
# utilization.
# Wesley Rodrigues da Silva <wesley.it at gmail.com>
# LICENCE CREATIVE COMMONS BY - 2014
# http://creativecommons.org/licenses/by/2.0/legalcode
# ########################################################
require 'date'
require 'json'
require 'open-uri'
@json = JSON.parse(open('http://169.254.169.254/latest/dynamic/instance-identity/document').read)
@started = @json['pendingTime'].split('T')[1].split(':')[1].to_i
@now = Time.now.strftime("%M").to_i
@time_left = ( 60 - @started + @now ) % 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment