clear_skies 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/clear_skies/aws/reservation_utilization.rb +28 -6
- data/lib/clear_skies/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71658311ffdc9ed619d871de1c83e0536f973af9
|
4
|
+
data.tar.gz: a25bb06314702201194df39f39eb07456753aff6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef27ddde07cc95c78d34dec964bf3251ee129d91081f7a0d2d0d1775b8a774f54a106c66dd6541dcffe69741812942ced6d56d93cd7e55dea62129f3b92eeb83
|
7
|
+
data.tar.gz: 129defa2139170c0a31133dedc835712ef912c3055070d2c2dfcd182b97760f09ae250329d1cff6677f020f317cbb08b7aa466bd6d4b81f4fd03e6844e0dab60
|
data/Gemfile.lock
CHANGED
@@ -3,25 +3,27 @@ module ClearSkies
|
|
3
3
|
class ReservationUtilization < GreekFire::MeasureSet
|
4
4
|
def items
|
5
5
|
client = Aws::EC2::Client.new()
|
6
|
-
reservations = client.describe_reserved_instances
|
6
|
+
reservations = client.describe_reserved_instances.reserved_instances
|
7
|
+
active_reservations = reservations.map { |x| ReservationMatcher.new(x) if x.state == "active" }.compact
|
8
|
+
current_reservations = reservations.map { |x| ReservationMatcher.new(x) if x.start < Time.now && x.start + x.duration > Time.now && x.fixed_price > 0}.compact
|
7
9
|
|
8
10
|
instance_counts = Hash.new { 0 }
|
9
11
|
|
10
|
-
|
11
12
|
instance_spawns = client.describe_instances(filters: [{name: "instance-state-name", values: ["running"]}])
|
12
13
|
|
13
14
|
instance_spawns.reservations.each do |spawn|
|
14
15
|
spawn.instances.each do |instance|
|
15
|
-
|
16
|
+
active_reservations.find { |reservation| reservation.match(instance) }
|
16
17
|
|
17
18
|
instance_counts[{instance_type: instance.instance_type, availability_zone: instance.placement.availability_zone, tenancy: instance.placement.tenancy}] += 1
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
[
|
22
|
-
ReservationExpirationGauge.new(
|
23
|
-
ReservationPurchasedGauge.new(
|
24
|
-
|
23
|
+
ReservationExpirationGauge.new(active_reservations),
|
24
|
+
ReservationPurchasedGauge.new(active_reservations),
|
25
|
+
ReservationDailyCostGauge.new(current_reservations),
|
26
|
+
ReservationUsageGauge.new(active_reservations),
|
25
27
|
InstancesGauge.new(instance_counts)
|
26
28
|
]
|
27
29
|
end
|
@@ -41,6 +43,10 @@ module ClearSkies
|
|
41
43
|
@reservation.end - Time.now
|
42
44
|
end
|
43
45
|
|
46
|
+
def daily_cost
|
47
|
+
(reservation.fixed_price * instance_count) / (reservation.duration / 1.day)
|
48
|
+
end
|
49
|
+
|
44
50
|
def match(instance)
|
45
51
|
return false if match_count >= instance_count
|
46
52
|
return false unless @reservation.instance_type == instance.instance_type
|
@@ -93,6 +99,22 @@ module ClearSkies
|
|
93
99
|
end
|
94
100
|
end
|
95
101
|
|
102
|
+
class ReservationDailyCostGauge < GreekFire::Gauge
|
103
|
+
def initialize(reservations)
|
104
|
+
super("aws_ec2_reservation_amortized_daily_price", description: "Amortized daily cost of reservation") do |labels|
|
105
|
+
labels.delete(:reservation).daily_cost
|
106
|
+
end
|
107
|
+
|
108
|
+
@reservations = reservations
|
109
|
+
end
|
110
|
+
|
111
|
+
def labels
|
112
|
+
@reservations.map do |reservation|
|
113
|
+
reservation.labels.merge(reservation: reservation)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
96
118
|
class ReservationUsageGauge < GreekFire::Gauge
|
97
119
|
def initialize(reservations)
|
98
120
|
super("aws_ec2_reservation_usage", description: "Number of instance reservations in use") do |labels|
|
data/lib/clear_skies/version.rb
CHANGED