Coder Social home page Coder Social logo

ec2spec's Introduction

Gem Version Build Status MIT License

ec2spec is a simple comparison tool for Amazon EC2 Instances you can access.

Supports the following items.

item from
instance type host
instance id host
vCPU AWS Price List API
memory AWS Price List API
price AWS Price List API

The target host must be accessible from the machine. Also, only On-Demand way and Linux machine.

Installation

$ gem install ec2spec

Usage

$ ec2spec ssh -h host1 ... [options]

Example

$ ec2spec ssh -h host1 host2 host3
I, [2018-08-12T20:54:25.814752 #64341]  INFO -- : Started: host1
I, [2018-08-12T20:54:25.814835 #64341]  INFO -- : Started: host2
I, [2018-08-12T20:54:25.814867 #64341]  INFO -- : Started: host3
E, [2018-08-12T20:54:25.826113 #64341] ERROR -- : Connection refused: host3
I, [2018-08-12T20:54:29.385848 #64341]  INFO -- : Finished: host1
I, [2018-08-12T20:54:37.560003 #64341]  INFO -- : Finished: host2
+---------------+-------------+---------------------+-------+
|               | host1       | host2               | host3 |
+---------------+-------------+---------------------|-------+
| instance_type |    t2.micro |          c4.2xlarge |   N/A |
|   instance_id |  i-xxxxxxxx |          i-yyyyyyyy |   N/A |
|          vCPU |           1 |                   8 |   N/A |
|        memory |       1 GiB |              15 GiB |   N/A |
| price (USD/H) |      0.0152 |               0.504 |   N/A |
| price (USD/M) |     11.3088 |             374.976 |   N/A |
+---------------+-------------+---------------------+-------+

The data of host3 could not be acquired due to a connection refused error.

Options

-h, --host    Target hosts name.

--days        How many days per one month.

--format      Output format (default: plain_text).
              plain_text, json, hash, slack, markdown

--region      Region of EC2 (default: ap-northeast-1).

--unit        Currency unit.
              with --rate.

--rate        Dollar exchange rate.
              with --unit.
              
--calc_type   Calculate exchange currency rate type.
              api, manual
              with --app_id, --unit (if app)
                   --unit, rate (if manual)

--app_id      App ID of Open Exchange Rates
              https://openexchangerates.org/
              with --calc_type, --unit

--debug       Output logs as DEBUG level.

--format (plain_text)

+---------------+-------------+-------------+
|               | host1       | host2       |
+---------------+-------------+-------------|
| instance_type |    t2.micro |  c4.2xlarge |
|   instance_id |  i-xxxxxxxx |  i-yyyyyyyy |
|          vCPU |           1 |           8 |
|        memory |       1 GiB |      15 GiB |
| price (USD/H) |      0.0152 |       0.504 |
| price (USD/M) |     11.3088 |     374.976 |
+---------------+-------------+-------------+

--format (json and hash)

{"host1":{"instance_type":"t2.micro","instance_id":"i-xxxxxxxx","vCPU":"1","memory":"1 GiB","price (USD/H)":0.0152,"price (USD/M)":11.3088},"host2":{"instance_type":"c4.2xlarge","instance_id":"i-yyyyyyyy","vCPU":"8","memory":"15 GiB","price (USD/H)":0.504,"price (USD/M)":374.976}}

--format (slack)

```
+---------------+-------------+-------------+
|               | host1       | host2       |
+---------------+-------------+-------------+
| instance_type |    t2.micro |  c4.2xlarge |
|   instance_id |  i-xxxxxxxx |  i-yyyyyyyy |
|          vCPU |           1 |           8 |
|        memory |       1 GiB |      15 GiB |
| price (USD/H) |      0.0152 |       0.504 |
| price (USD/M) |     11.3088 |     374.976 |
+---------------+-------------+-------------+
```

--format (markdown)

|               | stg-bastion | worker1     |
|---------------|-------------|-------------|
| instance_type |    t2.micro |  c4.2xlarge |
|   instance_id |  i-xxxxxxxx |  i-yyyyyyyy |
|          vCPU |           1 |           8 |
|        memory |       1 GiB |      15 GiB |
| price (USD/H) |      0.0152 |       0.504 |
| price (USD/M) |     11.3088 |     374.976 |

Exchange currency rate

Manual

Output JPY as exchange rate is 1 dollar 111 yen.

$ ec2spec ssh -h host1 host2 --unit JPY --calc_type manual

API

First, get App ID from https://openexchangerates.org/

Output JPY with it.

$ ec2spec ssh -h host1 host2 --unit JPY --calc_type api --app_id xxxxxxxx

Note: Exchange rate is cached in ~/.ec2spec/oxr.json. If you want to refresh, you have to delete it.

As a library

> require 'ec2spec'
> hosts = %w[host1 host2]
> client = Ec2spec::Client.new(hosts, 30, 'hash')
> result_json = client.run
> puts result_json
I, [2018-08-12T20:54:25.814752 #64341]  INFO -- : Started: host1
I, [2018-08-12T20:54:25.814835 #64341]  INFO -- : Started: host2
I, [2018-08-12T20:54:29.385848 #64341]  INFO -- : Finished: host1
I, [2018-08-12T20:54:37.560003 #64341]  INFO -- : Finished: host2
=> {"host1":{"instance_type":"t2.micro","instance_id":"i-xxxxxxxx","vCPU":"1","memory":"1 GiB","price (USD/H)":0.152,"price (USD/M)":11.3088},"host2":{"instance_type":"c4.2xlarge","instance_id":"i-yyyyyyyy","vCPU":"8","memory":"15 GiB","price (USD/H)":0.504,"price (USD/M)":374.976}}

Requirement

  • Ruby(MRI) 2.3.0 or higher

Competitors

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kyoshidajp/ec2spec.

License

The gem is available as open source under the terms of the MIT License.

ec2spec's People

Contributors

kyoshidajp avatar

Watchers

 avatar

ec2spec's Issues

Add slack output option

Add slack as a --format option value outputs result with ```

For example:

```
+---------------+-------------+-------------+-------+
|               | host1       | host2       | host3 |
+---------------+-------------+-------------|-------+
| instance_type |    t2.micro |  c4.2xlarge |   N/A |
|   instance_id |  i-xxxxxxxx |  i-yyyyyyyy |   N/A |
|          vCPU |           1 |           8 |   N/A |
|        memory |       1 GiB |      15 GiB |   N/A |
| price (USD/H) |      0.0152 |       0.504 |   N/A |
| price (USD/M) |     11.3088 |     374.976 |   N/A |
+---------------+-------------+---------------------+
```

Output the reason for the error that data can not be acquired

I, [2018-08-12T20:54:25.814752 #64341]  INFO -- : Started: host1
I, [2018-08-12T20:54:25.814835 #64341]  INFO -- : Started: host2
I, [2018-08-12T20:54:25.814867 #64341]  INFO -- : Started: host3
I, [2018-08-12T20:54:25.826113 #64341]  INFO -- : Finished: host3
I, [2018-08-12T20:54:29.385848 #64341]  INFO -- : Finished: host1
I, [2018-08-12T20:54:37.560003 #64341]  INFO -- : Finished: host2
+---------------+-------------+-------------+-------+
|               | host1       | host2       | host3 |
+---------------+-------------+-------------|-------+
| instance_type |    t2.micro |  c4.2xlarge |   N/A |
|   instance_id |  i-xxxxxxxx |  i-yyyyyyyy |   N/A |
|          vCPU |           1 |           8 |   N/A |
|        memory |       1 GiB |      15 GiB |   N/A |
| price (USD/H) |      0.0152 |       0.504 |   N/A |
| price (USD/M) |     11.3088 |     374.976 |   N/A |
+---------------+-------------+---------------------+

The data of host3 could not be acquired due to some error.

However, should output the reason why the data can not be acquired.

Can i use this tool via web application?

Thank you for create such a good tool ๐Ÿ˜„

But i think how wonderful it would be if i can use this tool via web application.
Specifically, I wanna receive results by JSON below for example.

{
  host1: {
    instance_type: "t2.micro",
    instance_id: "i-xxxxxxxx",
    memory: "1016324kB",
  },
  ...
}

So, Are you planning to implement it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.