clear_skies 0.4.1 → 0.5.4
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 +3 -3
- data/lib/clear_skies.rb +1 -0
- data/lib/clear_skies/aws/cloud_watch/billing.rb +4 -0
- data/lib/clear_skies/aws/cloud_watch/elastic_beanstalk_gauge.rb +2 -2
- data/lib/clear_skies/aws/cloud_watch/elb_gauge.rb +2 -2
- data/lib/clear_skies/aws/cloud_watch/gauge.rb +7 -3
- data/lib/clear_skies/aws/cloud_watch/rds_gauge.rb +2 -2
- data/lib/clear_skies/aws/cloud_watch/redshift_gauge.rb +40 -0
- data/lib/clear_skies/elasticsearch/report.rb +129 -36
- data/lib/clear_skies/redis/report.rb +26 -45
- data/lib/clear_skies/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4663b9f343938c385dbea126a760ead8b1680241
|
4
|
+
data.tar.gz: 83704537b0a74a203504639974d8c77ff36df7fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37c48599ec83e12fafca817bb478ffa10f34034a7c51e97516949c085edd8e6ac2d2f6c7db6555555881e1ee88dfe383d53b508adf47e235f4cbbec810e8e6ed
|
7
|
+
data.tar.gz: dcf63b1909ad72ed5e4c595b6ed9f490e61449f9f6edbd715d394d1ccbad79153846a18a4192a0e9e9995040ca8c8e09f8bc28597d2119134270e2cca3b696fa
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
clear_skies (0.4
|
4
|
+
clear_skies (0.5.4)
|
5
5
|
awesome_print
|
6
6
|
aws-sdk
|
7
7
|
elasticsearch
|
@@ -74,7 +74,7 @@ GEM
|
|
74
74
|
multipart-post (>= 1.2, < 3)
|
75
75
|
globalid (0.4.0)
|
76
76
|
activesupport (>= 4.2.0)
|
77
|
-
greek_fire (0.
|
77
|
+
greek_fire (0.5.0)
|
78
78
|
rails (>= 4.2.0)
|
79
79
|
i18n (0.8.6)
|
80
80
|
jmespath (1.3.1)
|
@@ -87,7 +87,7 @@ GEM
|
|
87
87
|
mime-types-data (~> 3.2015)
|
88
88
|
mime-types-data (3.2016.0521)
|
89
89
|
mini_portile2 (2.2.0)
|
90
|
-
minitest (5.10.
|
90
|
+
minitest (5.10.3)
|
91
91
|
multi_json (1.12.1)
|
92
92
|
multipart-post (2.0.0)
|
93
93
|
nio4r (2.1.0)
|
data/lib/clear_skies.rb
CHANGED
@@ -13,6 +13,7 @@ require "clear_skies/aws/cloud_watch/billing"
|
|
13
13
|
require "clear_skies/aws/cloud_watch/rds_gauge"
|
14
14
|
require "clear_skies/aws/cloud_watch/elb_gauge"
|
15
15
|
require "clear_skies/aws/cloud_watch/elastic_beanstalk_gauge"
|
16
|
+
require "clear_skies/aws/cloud_watch/redshift_gauge"
|
16
17
|
require "clear_skies/aws/cloud_watch/request_counter"
|
17
18
|
require "clear_skies/redis/report"
|
18
19
|
require "clear_skies/elasticsearch/report"
|
@@ -5,8 +5,8 @@ module ClearSkies
|
|
5
5
|
def self.beanstalk_client
|
6
6
|
@beanstalk_client ||= ::Aws::ElasticBeanstalk::Client.new
|
7
7
|
end
|
8
|
-
def initialize(metric_name, dimension, statistics, description: nil, &block)
|
9
|
-
super("AWS/ElasticBeanstalk", metric_name, dimension, statistics, description: description, &block)
|
8
|
+
def initialize(metric_name, dimension, statistics, description: nil, aws_parameters:nil, &block)
|
9
|
+
super("AWS/ElasticBeanstalk", metric_name, dimension, statistics, description: description, aws_parameters: aws_parameters, &block)
|
10
10
|
end
|
11
11
|
|
12
12
|
def application_name(environment_name)
|
@@ -6,8 +6,8 @@ module ClearSkies
|
|
6
6
|
def self.elb_client
|
7
7
|
@elb_client ||= Aws::ElasticLoadBalancing::Client.new
|
8
8
|
end
|
9
|
-
def initialize(metric_name, dimension, statistics, description: nil, &block)
|
10
|
-
super("AWS/ELB", metric_name, dimension, statistics, description: description, &block)
|
9
|
+
def initialize(metric_name, dimension, statistics, description: nil, aws_parameters:nil, &block)
|
10
|
+
super("AWS/ELB", metric_name, dimension, statistics, description: description, aws_parameters: aws_parameters, &block)
|
11
11
|
end
|
12
12
|
|
13
13
|
def tags(load_balancer_name)
|
@@ -46,10 +46,14 @@ module ClearSkies
|
|
46
46
|
|
47
47
|
next unless @block.call(labels) if @block
|
48
48
|
|
49
|
+
start_time = Time.now.advance(@aws_parameters[:start_time] || {minutes: -6})
|
50
|
+
end_time = Time.now.advance(@aws_parameters[:end_time] || {minutes: -5})
|
51
|
+
period = @aws_parameters[:period] || end_time - start_time
|
52
|
+
|
49
53
|
stats = metric.get_statistics(
|
50
|
-
start_time:
|
51
|
-
end_time:
|
52
|
-
period:
|
54
|
+
start_time: start_time,
|
55
|
+
end_time: end_time,
|
56
|
+
period: period,
|
53
57
|
statistics: @statistics,
|
54
58
|
extended_statistics: @extended_statistics,
|
55
59
|
dimensions: metric.dimensions
|
@@ -3,8 +3,8 @@ module ClearSkies
|
|
3
3
|
|
4
4
|
module CloudWatch
|
5
5
|
class RDSGauge < ClearSkies::AWS::CloudWatch::Gauge
|
6
|
-
def initialize(metric_name, dimension, statistics, description: nil, &block)
|
7
|
-
super("AWS/RDS", metric_name, dimension, statistics, description: description, &block)
|
6
|
+
def initialize(metric_name, dimension, statistics, description: nil, aws_parameters:nil, &block)
|
7
|
+
super("AWS/RDS", metric_name, dimension, statistics, description: description, aws_parameters: aws_parameters, &block)
|
8
8
|
end
|
9
9
|
|
10
10
|
def tags(db)
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module ClearSkies
|
2
|
+
module AWS
|
3
|
+
module CloudWatch
|
4
|
+
class RedshiftGauge < ClearSkies::AWS::CloudWatch::Gauge
|
5
|
+
def initialize(metric_name, dimension, statistics, description: nil, aws_parameters:nil, &block)
|
6
|
+
super("AWS/Redshift", metric_name, dimension, statistics, description: description, aws_parameters: aws_parameters, &block)
|
7
|
+
end
|
8
|
+
|
9
|
+
def extra_labels(cluster_id)
|
10
|
+
labels = {}
|
11
|
+
|
12
|
+
cluster = Aws::Redshift::Client.new.describe_clusters({
|
13
|
+
cluster_identifier: cluster_id
|
14
|
+
}).clusters[0]
|
15
|
+
|
16
|
+
vpc_id = cluster.vpc_id
|
17
|
+
labels["vpc_id"] = vpc_id if vpc_id.present?
|
18
|
+
|
19
|
+
cluster.tags.each do |tag|
|
20
|
+
labels[tag.key.downcase] = tag.value
|
21
|
+
end
|
22
|
+
labels
|
23
|
+
rescue Aws::Redshift::Errors::ClusterNotFound
|
24
|
+
return labels
|
25
|
+
end
|
26
|
+
|
27
|
+
def labels_from_metric(metric)
|
28
|
+
labels = super(metric)
|
29
|
+
|
30
|
+
if labels.has_key?("cluster_identifier")
|
31
|
+
labels.merge!(Rails.cache.fetch("#{labels["cluster_identifier"]}_extra_labels_", expires_in: 1.hour, race_condition_ttl: 60.seconds) do
|
32
|
+
extra_labels(labels["cluster_identifier"])
|
33
|
+
end)
|
34
|
+
end
|
35
|
+
labels
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'elasticsearch'
|
2
|
+
require 'uri'
|
2
3
|
|
3
4
|
module ClearSkies
|
4
5
|
module Elasticsearch
|
@@ -12,65 +13,157 @@ module ClearSkies
|
|
12
13
|
@reports ||= []
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
+
|
17
|
+
def self.flatten_hash(hash, prefix="elasticsearch")
|
18
|
+
ret = HashWithIndifferentAccess.new
|
19
|
+
hash.each do |k, value|
|
20
|
+
name = "#{prefix}_#{k}"
|
21
|
+
if value.is_a?(Hash)
|
22
|
+
ret.merge!(flatten_hash(value, name))
|
23
|
+
elsif(value.is_a?(Numeric))
|
24
|
+
ret[name] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
return ret
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_reader :url, :extra_labels
|
16
31
|
def initialize(url, extra_labels)
|
17
32
|
@url = url
|
18
|
-
|
19
|
-
|
33
|
+
|
34
|
+
@extra_labels = {host: URI(url).host}.merge extra_labels
|
20
35
|
end
|
21
36
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
metrics.docs_count = stats["docs"]["count"]
|
27
|
-
metrics.docs_deleted = stats["docs"]["deleted"]
|
28
|
-
metrics
|
37
|
+
def metrics
|
38
|
+
client = ::Elasticsearch::Client.new(hosts: url)
|
39
|
+
stats = client.cluster.stats
|
40
|
+
ClearSkies::Elasticsearch::Report.flatten_hash(stats)
|
29
41
|
end
|
30
42
|
|
31
|
-
def
|
43
|
+
def indicies
|
32
44
|
client = ::Elasticsearch::Client.new(hosts: @url)
|
33
|
-
|
45
|
+
client.indices.get_aliases
|
46
|
+
end
|
34
47
|
|
35
|
-
|
36
|
-
|
48
|
+
def report_indicies
|
49
|
+
indicies.map do |index|
|
50
|
+
ReportIndex.new(self, index)
|
37
51
|
end
|
38
52
|
end
|
39
53
|
|
40
|
-
|
54
|
+
def nodes
|
55
|
+
client = ::Elasticsearch::Client.new(hosts: @url)
|
56
|
+
client.nodes.stats["nodes"]
|
57
|
+
end
|
41
58
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
block.call(label.delete(:metric))
|
59
|
+
def report_nodes
|
60
|
+
nodes.map do |node_name, node_props|
|
61
|
+
ReportNode.new(self, node_name, node_props)
|
46
62
|
end
|
47
63
|
end
|
64
|
+
end
|
48
65
|
|
66
|
+
class ReportIndex
|
67
|
+
attr_reader :report, :index
|
49
68
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
69
|
+
def initialize(report, index)
|
70
|
+
@report = report
|
71
|
+
@index = index
|
72
|
+
@extra_labels = { index: index_alias }
|
73
|
+
end
|
74
|
+
|
75
|
+
def index_alias
|
76
|
+
@index[1]["aliases"].keys&.first || @index[0]
|
77
|
+
end
|
78
|
+
|
79
|
+
def index_name
|
80
|
+
@index[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
def extra_labels
|
84
|
+
@report.extra_labels.merge(@extra_labels)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
def metrics
|
89
|
+
client = ::Elasticsearch::Client.new(hosts: report.url)
|
90
|
+
stats = client.indices.stats["indices"][index_name]["total"]
|
91
|
+
ClearSkies::Elasticsearch::Report.flatten_hash(stats)
|
56
92
|
end
|
57
93
|
end
|
58
94
|
|
59
|
-
class
|
60
|
-
|
61
|
-
|
95
|
+
class ReportNode
|
96
|
+
attr_reader :report, :extra_labels
|
97
|
+
|
98
|
+
def initialize(report, node_name, node_props)
|
99
|
+
@report = report
|
100
|
+
@node_props = node_props
|
101
|
+
@extra_labels = { node_name: node_name }
|
102
|
+
end
|
103
|
+
|
104
|
+
def extra_labels
|
105
|
+
@report.extra_labels.merge(@extra_labels)
|
106
|
+
end
|
107
|
+
|
108
|
+
def metrics
|
109
|
+
ClearSkies::Elasticsearch::Report.flatten_hash(@node_props, "elasticsearch_node")
|
62
110
|
end
|
111
|
+
|
63
112
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
113
|
+
|
114
|
+
|
115
|
+
class MeasureSet < GreekFire::MeasureSet
|
116
|
+
def items
|
117
|
+
metrics = []
|
118
|
+
|
119
|
+
### Cluster Metrics ##
|
120
|
+
labels = ClearSkies::Elasticsearch::Report.reports.map do | report|
|
121
|
+
GreekFire::SmartLabel.new(report.metrics, report.extra_labels)
|
122
|
+
end
|
123
|
+
|
124
|
+
metric_names = labels.map {|i| i.value.keys}.flatten.uniq
|
125
|
+
|
126
|
+
metric_names.each do |metric|
|
127
|
+
metrics << GreekFire::Gauge.new(metric, labels: labels) do |label|
|
128
|
+
label.value[metric]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
### Index Metrics
|
133
|
+
labels = ClearSkies::Elasticsearch::Report.reports.map do | report|
|
134
|
+
report.report_indicies.map do |report_index|
|
135
|
+
GreekFire::SmartLabel.new(report_index.metrics, report_index.extra_labels)
|
136
|
+
end
|
137
|
+
end.flatten
|
138
|
+
|
139
|
+
metric_names = labels.map {|i| i.value.keys}.flatten.uniq
|
140
|
+
|
141
|
+
metric_names.each do |metric|
|
142
|
+
metrics << GreekFire::Gauge.new(metric, labels: labels) do |label|
|
143
|
+
label.value[metric]
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
### Node Metrics
|
148
|
+
labels = ClearSkies::Elasticsearch::Report.reports.map do | report|
|
149
|
+
report.report_nodes.map do |report_node|
|
150
|
+
GreekFire::SmartLabel.new(report_node.metrics, report_node.extra_labels)
|
151
|
+
end
|
152
|
+
end.flatten
|
153
|
+
|
154
|
+
metric_names = labels.map {|i| i.value.keys}.flatten.uniq
|
155
|
+
|
156
|
+
metric_names.each do |metric|
|
157
|
+
metrics << GreekFire::Gauge.new(metric, labels: labels) do |label|
|
158
|
+
label.value[metric]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
metrics
|
67
163
|
end
|
68
164
|
end
|
165
|
+
|
69
166
|
end
|
70
167
|
end
|
71
168
|
|
72
|
-
|
73
|
-
# GreekFire::Metric.register(ClearSkies::Elasticsearch::Gauge.new("elasticsearch_docs_deleted") { |metrics| metrics.docs_deleted })
|
74
|
-
|
75
|
-
|
76
|
-
#For a <DIM>, grab N metrics.
|
169
|
+
GreekFire::Metric.register ClearSkies::Elasticsearch::MeasureSet.new
|
@@ -29,16 +29,17 @@ module ClearSkies
|
|
29
29
|
ReportDimension.new(self, dimension)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
def items
|
34
|
-
report_dimensions.map
|
35
|
-
end
|
36
32
|
end
|
37
33
|
|
38
34
|
class MeasureSet < GreekFire::MeasureSet
|
39
35
|
def items
|
40
|
-
|
41
|
-
|
36
|
+
labels = ClearSkies::Redis::Report.reports.map do | report|
|
37
|
+
report.report_dimensions.map do |report_dimension|
|
38
|
+
GreekFire::SmartLabel.new(report_dimension.metrics, report_dimension.extra_labels)
|
39
|
+
end
|
40
|
+
end.flatten
|
41
|
+
|
42
|
+
return [] unless labels.length > 0
|
42
43
|
|
43
44
|
[
|
44
45
|
"keys",
|
@@ -52,7 +53,9 @@ module ClearSkies
|
|
52
53
|
"rdb_last_bgsave_time_sec",
|
53
54
|
"total_commands_processed"
|
54
55
|
].map do |metric_name|
|
55
|
-
|
56
|
+
GreekFire::Gauge.new("redis_#{metric_name}", labels: labels) do |label|
|
57
|
+
label.value[metric_name.to_sym]
|
58
|
+
end
|
56
59
|
end
|
57
60
|
end
|
58
61
|
end
|
@@ -63,53 +66,31 @@ module ClearSkies
|
|
63
66
|
def initialize(report, dimension)
|
64
67
|
@report = report
|
65
68
|
@dimension = dimension
|
69
|
+
@extra_labels = { db: dimension }
|
70
|
+
end
|
71
|
+
|
72
|
+
def extra_labels
|
73
|
+
@report.extra_labels.merge(@extra_labels)
|
66
74
|
end
|
67
75
|
|
68
76
|
def metrics
|
69
77
|
redis = ::Redis.new(host: report.host, port: report.port, db: @dimension)
|
70
78
|
redis_info = redis.info
|
71
79
|
|
72
|
-
metrics =
|
73
|
-
metrics
|
74
|
-
metrics
|
75
|
-
metrics
|
76
|
-
metrics
|
77
|
-
metrics
|
78
|
-
metrics
|
79
|
-
metrics
|
80
|
-
metrics
|
81
|
-
metrics
|
82
|
-
metrics
|
80
|
+
metrics = HashWithIndifferentAccess.new
|
81
|
+
metrics[:keys ]= redis.dbsize
|
82
|
+
metrics[:last_save ]= Time.now.to_i - redis.lastsave
|
83
|
+
metrics[:uptime ]= redis_info["uptime_in_seconds"].to_f
|
84
|
+
metrics[:connected_clients ]= redis_info["connected_clients"].to_i
|
85
|
+
metrics[:blocked_clients ]= redis_info["blocked_clients"].to_i
|
86
|
+
metrics[:used_memory ]= redis_info["used_memory"].to_f
|
87
|
+
metrics[:mem_fragmentation_ratio ]= redis_info["mem_fragmentation_ratio"].to_f
|
88
|
+
metrics[:rdb_changes_since_last_save ]= redis_info["rdb_changes_since_last_save"].to_f
|
89
|
+
metrics[:rdb_last_bgsave_time_szec ]= redis_info["rdb_last_bgsave_time_sec"].to_f
|
90
|
+
metrics[:total_commands_processed ]= redis_info["total_commands_processed"].to_f
|
83
91
|
metrics
|
84
92
|
end
|
85
93
|
end
|
86
|
-
|
87
|
-
class Measure < GreekFire::Measure
|
88
|
-
def initialize(report_dimensions, prefix, name)
|
89
|
-
@report_dimensions = report_dimensions
|
90
|
-
super("#{prefix}_#{name}") do |label|
|
91
|
-
label.delete(:metric).metrics.to_h[name.to_sym]
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def labels
|
97
|
-
@report_dimensions.map do |report_dimension|
|
98
|
-
report_dimension.report.extra_labels.merge({metric: report_dimension })
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
class Gauge < ClearSkies::Redis::Measure
|
104
|
-
def to_partial_path
|
105
|
-
GreekFire::Gauge._to_partial_path
|
106
|
-
end
|
107
|
-
end
|
108
|
-
class Counter < ClearSkies::Redis::Measure
|
109
|
-
def to_partial_path
|
110
|
-
GreekFire::Counter._to_partial_path
|
111
|
-
end
|
112
|
-
end
|
113
94
|
end
|
114
95
|
end
|
115
96
|
|
data/lib/clear_skies/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clear_skies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Constantine
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/clear_skies/aws/cloud_watch/elb_gauge.rb
|
151
151
|
- lib/clear_skies/aws/cloud_watch/gauge.rb
|
152
152
|
- lib/clear_skies/aws/cloud_watch/rds_gauge.rb
|
153
|
+
- lib/clear_skies/aws/cloud_watch/redshift_gauge.rb
|
153
154
|
- lib/clear_skies/aws/cloud_watch/request_counter.rb
|
154
155
|
- lib/clear_skies/aws/reservation_utilization.rb
|
155
156
|
- lib/clear_skies/elasticsearch/report.rb
|