Last active
August 29, 2015 14:02
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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