aws_instance_list 1.2.6 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +13 -9
- data/aws_instance_list.gemspec +1 -0
- data/lib/aws_instance_list/base.rb +48 -0
- data/lib/aws_instance_list/elasti_cache.rb +61 -0
- data/lib/aws_instance_list/list.rb +23 -15
- data/lib/aws_instance_list/metric.rb +46 -1
- data/lib/aws_instance_list/rds.rb +7 -36
- data/lib/aws_instance_list/version.rb +1 -1
- data/lib/aws_instance_list.rb +2 -0
- data/lib/config/default_settings.yaml +39 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d05c98e5aae6d7a2860094f1838a61d2a2529271
|
4
|
+
data.tar.gz: 4a5047d23b616bc8366c704dfa691bfe6e8eaa77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18a92fcc6d8aad273103f4c5f6f28edd8921551af149cbbb4bac206062e62cb3aa7f4d44f4b17ef33b2bb27485cdea07221a6b43107911d715998f9f8caa87c3
|
7
|
+
data.tar.gz: 3e904bfcc67dbfa6ce0ca2c44745a17eda886cce7039ada66ad2bfcbb941d98f6b1975fd5c4c8eca0106cd4a97346ff09574187e9cb43e92e4b0c650a625296d
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
aws_instance_list (1.
|
4
|
+
aws_instance_list (1.3.1)
|
5
5
|
aws-sdk-cloudwatch (~> 1.6)
|
6
6
|
aws-sdk-ec2 (~> 1.37)
|
7
|
+
aws-sdk-elasticache (~> 1.7)
|
7
8
|
aws-sdk-rds (~> 1.23)
|
8
9
|
dotenv (~> 2.5)
|
9
10
|
|
@@ -11,20 +12,23 @@ GEM
|
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
14
|
aws-eventstream (1.0.1)
|
14
|
-
aws-partitions (1.
|
15
|
-
aws-sdk-cloudwatch (1.
|
16
|
-
aws-sdk-core (~> 3)
|
15
|
+
aws-partitions (1.105.0)
|
16
|
+
aws-sdk-cloudwatch (1.10.0)
|
17
|
+
aws-sdk-core (~> 3, >= 3.26.0)
|
17
18
|
aws-sigv4 (~> 1.0)
|
18
|
-
aws-sdk-core (3.
|
19
|
+
aws-sdk-core (3.32.0)
|
19
20
|
aws-eventstream (~> 1.0)
|
20
21
|
aws-partitions (~> 1.0)
|
21
22
|
aws-sigv4 (~> 1.0)
|
22
23
|
jmespath (~> 1.0)
|
23
|
-
aws-sdk-ec2 (1.
|
24
|
-
aws-sdk-core (~> 3)
|
24
|
+
aws-sdk-ec2 (1.51.0)
|
25
|
+
aws-sdk-core (~> 3, >= 3.26.0)
|
25
26
|
aws-sigv4 (~> 1.0)
|
26
|
-
aws-sdk-
|
27
|
-
aws-sdk-core (~> 3)
|
27
|
+
aws-sdk-elasticache (1.7.0)
|
28
|
+
aws-sdk-core (~> 3, >= 3.26.0)
|
29
|
+
aws-sigv4 (~> 1.0)
|
30
|
+
aws-sdk-rds (1.33.0)
|
31
|
+
aws-sdk-core (~> 3, >= 3.26.0)
|
28
32
|
aws-sigv4 (~> 1.0)
|
29
33
|
aws-sigv4 (1.0.3)
|
30
34
|
byebug (10.0.2)
|
data/aws_instance_list.gemspec
CHANGED
@@ -39,5 +39,6 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_dependency "aws-sdk-rds", "~> 1.23"
|
40
40
|
spec.add_dependency "aws-sdk-ec2", "~> 1.37"
|
41
41
|
spec.add_dependency "aws-sdk-cloudwatch", "~> 1.6"
|
42
|
+
spec.add_dependency "aws-sdk-elasticache", "~> 1.7"
|
42
43
|
spec.add_dependency "dotenv", "~> 2.5"
|
43
44
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module AwsInstanceList
|
4
|
+
|
5
|
+
class Base
|
6
|
+
|
7
|
+
attr_accessor :client, :region, :metric
|
8
|
+
|
9
|
+
def initialize region: 'eu-west-1'
|
10
|
+
|
11
|
+
@region=region
|
12
|
+
|
13
|
+
@metric = AwsInstanceList::Metric.new region: region
|
14
|
+
|
15
|
+
@instances = []
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def instances options={}
|
20
|
+
ds=descriptions(options)
|
21
|
+
@instances+=ds.send( list_method )
|
22
|
+
if ds.marker
|
23
|
+
options[:marker]=ds.marker
|
24
|
+
instances(options)
|
25
|
+
else
|
26
|
+
@instances
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def yaml
|
31
|
+
@yaml||=yaml_default.merge(yaml_file)[demodulize]
|
32
|
+
end
|
33
|
+
|
34
|
+
def yaml_default
|
35
|
+
YAML.load_file AwsInstanceList::DEFAULT_SETTINGS
|
36
|
+
end
|
37
|
+
|
38
|
+
def yaml_file
|
39
|
+
ENV.has_key?('AWS_INSTANCE_LIST_YAML') ? YAML.load_file(ENV['AWS_INSTANCE_LIST_YAML']) : {}
|
40
|
+
end
|
41
|
+
|
42
|
+
def demodulize
|
43
|
+
self.class.name.split('::').last
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'aws-sdk-elasticache'
|
2
|
+
|
3
|
+
module AwsInstanceList
|
4
|
+
|
5
|
+
class ElastiCache < AwsInstanceList::Base
|
6
|
+
|
7
|
+
def initialize region: 'eu-west-1'
|
8
|
+
|
9
|
+
super region: region
|
10
|
+
|
11
|
+
@client=Aws::ElastiCache::Client.new region: region
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_method
|
16
|
+
:cache_clusters
|
17
|
+
end
|
18
|
+
|
19
|
+
def descriptions options={}
|
20
|
+
client.describe_cache_clusters(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def bytes_used_for_cache cache_cluster_id
|
24
|
+
metric.bytes_used_for_cache cache_cluster_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def freeable_memory cache_cluster_id
|
28
|
+
metric.freeable_memory cache_cluster_id
|
29
|
+
end
|
30
|
+
|
31
|
+
def cache_list options: {}, fields: nil
|
32
|
+
|
33
|
+
fields||=load_cache_fields
|
34
|
+
|
35
|
+
instances(options).map do |i|
|
36
|
+
fields.map { |f| i.send(f) } + metrics(i) << region
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def group_name i
|
41
|
+
i.cache_parameter_group.cache_parameter_group_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def maxmemory cache_node_type
|
45
|
+
yaml['maxmemory'][cache_node_type]
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_cache_fields
|
49
|
+
yaml['cache']['fields']
|
50
|
+
end
|
51
|
+
|
52
|
+
def metrics instance
|
53
|
+
used=bytes_used_for_cache(instance.cache_cluster_id)
|
54
|
+
total=maxmemory instance.cache_node_type
|
55
|
+
[used, total, used / total * 100.0]
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
@@ -6,37 +6,45 @@ module AwsInstanceList
|
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@regions=AwsInstanceList::Region.list
|
9
|
-
@
|
9
|
+
@list={}
|
10
10
|
end
|
11
11
|
|
12
12
|
def db_list
|
13
|
+
list
|
14
|
+
end
|
13
15
|
|
14
|
-
|
16
|
+
def rds_db_list region:
|
17
|
+
rds=AwsInstanceList::RDS.new region: region
|
18
|
+
rds.db_list
|
19
|
+
end
|
15
20
|
|
16
|
-
|
21
|
+
def list call_to: :rds_db_list
|
17
22
|
|
18
|
-
|
23
|
+
threads = []
|
19
24
|
|
20
|
-
|
21
|
-
@db_list[region]=rds_db_list region: region
|
22
|
-
end
|
25
|
+
regions.each do |region|
|
23
26
|
|
27
|
+
threads << Thread.new do
|
28
|
+
@list[region]=self.send( call_to, region: region)
|
24
29
|
end
|
25
30
|
|
26
|
-
|
27
|
-
break if threads.count { |th| th.alive? } == 0
|
28
|
-
end
|
31
|
+
end
|
29
32
|
|
33
|
+
loop do
|
34
|
+
break if threads.count { |th| th.alive? } == 0
|
30
35
|
end
|
31
36
|
|
32
|
-
@
|
37
|
+
@list.values.flatten(1)
|
33
38
|
|
34
39
|
end
|
35
40
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
41
|
+
def cache_list
|
42
|
+
list call_to: :cache_instance_list
|
43
|
+
end
|
44
|
+
|
45
|
+
def cache_instance_list region:
|
46
|
+
ec=AwsInstanceList::ElastiCache.new region: region
|
47
|
+
ec.cache_list
|
40
48
|
end
|
41
49
|
|
42
50
|
end
|
@@ -34,7 +34,52 @@ module AwsInstanceList
|
|
34
34
|
statistics: ["Minimum"]
|
35
35
|
})
|
36
36
|
|
37
|
-
resp.datapoints.
|
37
|
+
if resp.datapoints.empty?
|
38
|
+
'-'
|
39
|
+
else
|
40
|
+
resp.datapoints.last.minimum / ( 1024.0 ** 3)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def bytes_used_for_cache cache_cluster_id
|
46
|
+
resp=statistics( {
|
47
|
+
namespace: "AWS/ElastiCache",
|
48
|
+
metric_name: "BytesUsedForCache",
|
49
|
+
dimensions: [
|
50
|
+
{
|
51
|
+
name: "CacheClusterId",
|
52
|
+
value: cache_cluster_id,
|
53
|
+
},
|
54
|
+
],
|
55
|
+
start_time: Time.now - 600,
|
56
|
+
end_time: Time.now ,
|
57
|
+
period: 60,
|
58
|
+
statistics: ["Maximum"]
|
59
|
+
})
|
60
|
+
|
61
|
+
resp.datapoints.last.maximum
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def freeable_memory cache_cluster_id
|
67
|
+
resp=statistics( {
|
68
|
+
namespace: "AWS/ElastiCache",
|
69
|
+
metric_name: "FreeableMemory",
|
70
|
+
dimensions: [
|
71
|
+
{
|
72
|
+
name: "CacheClusterId",
|
73
|
+
value: cache_cluster_id,
|
74
|
+
},
|
75
|
+
],
|
76
|
+
start_time: Time.now - 600,
|
77
|
+
end_time: Time.now ,
|
78
|
+
period: 60,
|
79
|
+
statistics: ["Maximum"]
|
80
|
+
})
|
81
|
+
|
82
|
+
resp.datapoints.last.maximum
|
38
83
|
|
39
84
|
end
|
40
85
|
|
@@ -1,42 +1,30 @@
|
|
1
1
|
require 'aws-sdk-rds'
|
2
|
-
require 'yaml'
|
3
2
|
|
4
3
|
module AwsInstanceList
|
5
4
|
|
6
|
-
class RDS
|
7
|
-
|
8
|
-
attr_accessor :client, :region
|
5
|
+
class RDS < AwsInstanceList::Base
|
9
6
|
|
10
7
|
def initialize region: 'eu-west-1'
|
11
8
|
|
12
|
-
|
9
|
+
super region: region
|
13
10
|
|
14
11
|
@client=Aws::RDS::Client.new region: region
|
15
12
|
|
16
|
-
@db_instances = []
|
17
|
-
|
18
13
|
end
|
19
14
|
|
20
|
-
def
|
21
|
-
|
15
|
+
def list_method
|
16
|
+
:db_instances
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
25
|
-
|
26
|
-
@db_instances+=descriptions.db_instances
|
27
|
-
if descriptions.marker
|
28
|
-
options[:marker]=descriptions.marker
|
29
|
-
db_instances(options)
|
30
|
-
else
|
31
|
-
@db_instances
|
32
|
-
end
|
19
|
+
def descriptions options={}
|
20
|
+
client.describe_db_instances(options)
|
33
21
|
end
|
34
22
|
|
35
23
|
def db_list options: {}, fields: nil
|
36
24
|
|
37
25
|
fields||=load_db_fields
|
38
26
|
|
39
|
-
|
27
|
+
instances(options).map do |i|
|
40
28
|
fields.map { |f| i.send(f) } << free_storage_space(i.db_instance_identifier) << region
|
41
29
|
end
|
42
30
|
end
|
@@ -45,24 +33,7 @@ module AwsInstanceList
|
|
45
33
|
yaml['db']['fields']
|
46
34
|
end
|
47
35
|
|
48
|
-
def yaml
|
49
|
-
@yaml||=yaml_default.merge(yaml_file)[demodulize]
|
50
|
-
end
|
51
|
-
|
52
|
-
def yaml_default
|
53
|
-
YAML.load_file AwsInstanceList::DEFAULT_SETTINGS
|
54
|
-
end
|
55
|
-
|
56
|
-
def yaml_file
|
57
|
-
ENV.has_key?('AWS_INSTANCE_LIST_YAML') ? YAML.load_file(ENV['AWS_INSTANCE_LIST_YAML']) : {}
|
58
|
-
end
|
59
|
-
|
60
|
-
def demodulize
|
61
|
-
self.class.name.split('::').last
|
62
|
-
end
|
63
|
-
|
64
36
|
def free_storage_space db_instance_identifier
|
65
|
-
metric = AwsInstanceList::Metric.new region: region
|
66
37
|
metric.free_storage_space db_instance_identifier
|
67
38
|
end
|
68
39
|
|
data/lib/aws_instance_list.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
+
require 'aws_instance_list/base'
|
1
2
|
require 'aws_instance_list/list'
|
2
3
|
require 'aws_instance_list/region'
|
3
4
|
require 'aws_instance_list/metric'
|
4
5
|
require 'aws_instance_list/rds'
|
6
|
+
require 'aws_instance_list/elasti_cache'
|
5
7
|
require 'aws_instance_list/version'
|
6
8
|
|
7
9
|
require 'dotenv/load'
|
@@ -6,3 +6,42 @@ RDS:
|
|
6
6
|
- engine
|
7
7
|
- allocated_storage
|
8
8
|
- db_instance_status
|
9
|
+
ElastiCache:
|
10
|
+
cache:
|
11
|
+
fields:
|
12
|
+
- cache_cluster_id
|
13
|
+
- engine
|
14
|
+
- cache_node_type
|
15
|
+
maxmemory:
|
16
|
+
cache.t1.micro: 142606336
|
17
|
+
cache.t2.micro: 581959680
|
18
|
+
cache.t2.small: 1665138688
|
19
|
+
cache.t2.medium: 3461349376
|
20
|
+
cache.m1.small: 943718400
|
21
|
+
cache.m1.medium: 3093299200
|
22
|
+
cache.m1.large: 7025459200
|
23
|
+
cache.m1.xlarge: 14889779200
|
24
|
+
cache.m2.xlarge: 17091788800
|
25
|
+
cache.m2.2xlarge: 35022438400
|
26
|
+
cache.m2.4xlarge: 70883737600
|
27
|
+
cache.m3.medium: 2988441600
|
28
|
+
cache.m3.large: 6501171200
|
29
|
+
cache.m3.xlarge: 14260633600
|
30
|
+
cache.m3.2xlarge: 29989273600
|
31
|
+
cache.m4.large: 6892593152
|
32
|
+
cache.m4.xlarge: 15328501760
|
33
|
+
cache.m4.2xlarge: 31889126359
|
34
|
+
cache.m4.4xlarge: 65257290629
|
35
|
+
cache.m4.10xlarge: 166047614239
|
36
|
+
cache.c1.xlarge: 6501171200
|
37
|
+
cache.r3.large: 14470348800
|
38
|
+
cache.r3.xlarge: 30513561600
|
39
|
+
cache.r3.2xlarge: 62495129600
|
40
|
+
cache.r3.4xlarge: 126458265600
|
41
|
+
cache.r3.8xlarge: 254384537600
|
42
|
+
cache.r4.large: 13201781556
|
43
|
+
cache.r4.xlarge: 26898228839
|
44
|
+
cache.r4.2xlarge: 54197537997
|
45
|
+
cache.r4.4xlarge: 108858546586
|
46
|
+
cache.r4.8xlarge: 218255432090
|
47
|
+
cache.r4.16xlarge: 437021573120
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_instance_list
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Diego PL
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.6'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: aws-sdk-elasticache
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.7'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.7'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: dotenv
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,6 +158,8 @@ files:
|
|
144
158
|
- bin/console
|
145
159
|
- bin/setup
|
146
160
|
- lib/aws_instance_list.rb
|
161
|
+
- lib/aws_instance_list/base.rb
|
162
|
+
- lib/aws_instance_list/elasti_cache.rb
|
147
163
|
- lib/aws_instance_list/list.rb
|
148
164
|
- lib/aws_instance_list/metric.rb
|
149
165
|
- lib/aws_instance_list/rds.rb
|