aws-reporting 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ def get_value(dimension, name)
2
+ dimension.find{|d| d[:name] == name}[:value]
3
+ end
@@ -0,0 +1,57 @@
1
+ module AwsReporting
2
+ module Plan
3
+ def self.to_array(yaml_array)
4
+ array = []
5
+ yaml_array.each{|i|
6
+ array << i.to_s
7
+ }
8
+ array
9
+ end
10
+
11
+ def self.build_template(yaml)
12
+ template = Hash.new{|h, k| h[k] = {}}
13
+ yaml.each{|d|
14
+ template[d["namespace"]][d["metric_name"]] = to_array(d["statistics"])
15
+ }
16
+ template
17
+ end
18
+
19
+ DEFAULT_STATISTICS = ['Maximum', 'Minimum', 'Average']
20
+
21
+ def self.create_plan(template, metrics)
22
+ plan = []
23
+ metrics.map{|m|
24
+ namespace = m[:namespace]
25
+ metric_name = m[:metric_name]
26
+ dimensions = m[:dimensions]
27
+ statiestics = nil
28
+ if template[namespace][metric_name]
29
+ statistics = template[namespace][metric_name]
30
+ else
31
+ $stderr.puts "Warning: Metric #{namespace} #{metric_name} is not defined. Default statistics are used."
32
+ statistics = DEFAULT_STATISTICS
33
+ end
34
+ region = m[:region]
35
+
36
+ {:namespace => namespace, :metric_name => metric_name, :dimensions => dimensions, :statistics => statistics, :region => region}
37
+ }
38
+ end
39
+
40
+ def self.metrics_file_path()
41
+ File.expand_path('../../../metrics/metrics.yaml', __FILE__)
42
+ end
43
+
44
+ def self.generate()
45
+ yaml = YAML.load(open(metrics_file_path()){|f| f.read })
46
+ template = build_template(yaml)
47
+
48
+ metrics = []
49
+ AWS.regions.each{|r|
50
+ AwsReporting::Config.update_region(r.name)
51
+ AWS::CloudWatch::MetricCollection.new.each{|m| metrics << {:namespace => m.namespace, :metric_name => m.metric_name, :dimensions => m.dimensions, :region => r.name}}
52
+ }
53
+
54
+ plan = create_plan(template, metrics)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,32 @@
1
+ module AwsReporting
2
+ module Resolver
3
+ class EBSResolver
4
+ def initialize
5
+ @ebs_name_table = {}
6
+ end
7
+
8
+ def self.namespace
9
+ "AWS/EBS"
10
+ end
11
+
12
+ def self.dimension_type
13
+ ["VolumeId"].sort
14
+ end
15
+
16
+ def init
17
+ AWS.regions.each{|r|
18
+ Config.update_region(r.name)
19
+ ec2 = AWS::EC2.new
20
+ ec2.volumes.each{|volume|
21
+ @ebs_name_table[volume.id] = volume.tags["Name"]
22
+ }
23
+ }
24
+ end
25
+
26
+ def get_name(element)
27
+ id = get_value(element[:dimensions], "VolumeId")
28
+ @ebs_name_table[id]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module AwsReporting
2
+ module Resolver
3
+ class EC2Resolver
4
+ def initialize
5
+ @ec2_name_table = {}
6
+ end
7
+
8
+ def self.namespace
9
+ "AWS/EC2"
10
+ end
11
+
12
+ def self.dimension_type
13
+ ["InstanceId"].sort
14
+ end
15
+
16
+ def init
17
+ AWS.regions.each{|r|
18
+ Config.update_region(r.name)
19
+ ec2 = AWS::EC2.new
20
+ ec2.instances.each{|instance|
21
+ @ec2_name_table[instance.id] = instance.tags["Name"]
22
+ }
23
+ }
24
+ end
25
+
26
+ def get_name(element)
27
+ id = get_value(element[:dimensions], "InstanceId")
28
+ @ec2_name_table[id]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ module AwsReporting
2
+ class Resolvers
3
+ def initialize
4
+ @resolvers = Hash.new{|h, k| h[k] = {}}
5
+ end
6
+
7
+ def init
8
+ resolvers = [AwsReporting::Resolver::EC2Resolver,
9
+ AwsReporting::Resolver::EBSResolver]
10
+
11
+ resolvers.each{|resolver_class|
12
+ resolver = resolver_class.new
13
+ resolver.init
14
+ @resolvers[resolver_class.namespace][resolver_class.dimension_type] = resolver
15
+ }
16
+ end
17
+
18
+ def get_name(element)
19
+ namespace = element[:namespace]
20
+ dimension_type = element[:dimensions].map{|d| d[:name]}.sort
21
+
22
+ resolver = @resolvers[namespace][dimension_type]
23
+
24
+ return nil unless resolver
25
+
26
+ resolver.get_name(element)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ require 'webrick'
2
+
3
+ module AwsReporting
4
+ class Server
5
+ def initialize(path, port)
6
+ @server = WEBrick::HTTPServer.new(:DocumentRoot => path, :Port => port, :BindAddress => "0.0.0.0")
7
+ end
8
+
9
+ def start()
10
+ @server.start
11
+ end
12
+
13
+ def stop()
14
+ puts 'server stopped.'
15
+ @server.stop
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ module AwsReporting
2
+ module Statistics
3
+ def get(region, namespace, metric_name, start_time, end_time, period, dimensions, statistics)
4
+ client = AWS::CloudWatch::Client.new(:config => Config.get, :region => region)
5
+
6
+ datapoints = client.get_metric_statistics(:namespace => namespace,
7
+ :metric_name => metric_name,
8
+ :start_time => start_time.iso8601,
9
+ :end_time => end_time.iso8601,
10
+ :period => period,
11
+ :dimensions => dimensions,
12
+ :statistics => statistics)[:datapoints]
13
+
14
+ info = {:region => region,
15
+ :namespace => namespace,
16
+ :metric_name => metric_name,
17
+ :dimensions => dimensions,
18
+ :start_time => start_time.iso8601,
19
+ :end_time => end_time.iso8601,
20
+ :period => period,
21
+ :statistics => statistics,
22
+ :unit => datapoints[0] ? datapoints[0][:unit] : nil }
23
+
24
+ data = datapoints.sort_by{|d| d[:timestamp] }
25
+ .map{|d|
26
+ datapoint = {}
27
+
28
+ datapoint[:timestamp] = d[:timestamp].iso8601
29
+ datapoint[:maximum] = d[:maximum] if d[:maximum]
30
+ datapoint[:minimum] = d[:minimum] if d[:minimum]
31
+ datapoint[:average] = d[:average] if d[:average]
32
+ datapoint[:sum] = d[:sum] if d[:sum]
33
+ datapoint[:sample_count] = d[:sample_count] if d[:sample_count]
34
+
35
+ datapoint
36
+ }
37
+
38
+ {:info => info, :datapoints => data}
39
+ end
40
+
41
+ module_function :get
42
+ end
43
+ end
@@ -0,0 +1,35 @@
1
+ module AwsReporting
2
+ module Store
3
+ class Counter
4
+ def initialize
5
+ @counter = 0
6
+ @mutex = Mutex.new
7
+ end
8
+
9
+ def get
10
+ @mutex.synchronize{
11
+ @counter += 1
12
+ return @counter
13
+ }
14
+ end
15
+ end
16
+
17
+ FILE_COUNTER = Counter.new
18
+
19
+ def save(dir, data)
20
+ FileUtils.mkdir_p(dir)
21
+
22
+ path = dir + '/' + FILE_COUNTER.get.to_s + '.json'
23
+
24
+ json = JSON.dump(data)
25
+
26
+ open(path, 'w'){|f|
27
+ f.print JSON.dump(data)
28
+ }
29
+
30
+ {:info => data[:info], :path => path}
31
+ end
32
+
33
+ module_function :save
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ module AwsReporting
2
+ module Version
3
+ def get
4
+ "AWS-Reporting v0.9.1"
5
+ end
6
+
7
+ module_function :get
8
+ end
9
+ end
@@ -0,0 +1,220 @@
1
+ AWS/AutoScaling,GroupDesiredCapacity,AVG
2
+ AWS/AutoScaling,GroupInServiceInstances,AVG
3
+ AWS/AutoScaling,GroupMaxSize,AVG
4
+ AWS/AutoScaling,GroupMinSize,AVG
5
+ AWS/AutoScaling,GroupPendingInstances,AVG
6
+ AWS/AutoScaling,GroupTerminatingInstances,AVG
7
+ AWS/AutoScaling,GroupTotalInstances,AVG
8
+ AWS/Billing,EstimatedCharges,AVG
9
+ AWS/DynamoDB,ConsumedReadCapacityUnits,SUM
10
+ AWS/DynamoDB,ProvisionedReadCapacityUnits,AVG
11
+ AWS/DynamoDB,ProvisionedWriteCapacityUnits,AVG
12
+ AWS/DynamoDB,ReadThrottleEvents,SUM
13
+ AWS/DynamoDB,ReturnedItemCount,SUM
14
+ AWS/DynamoDB,SuccessfulRequestLatency,AVG
15
+ AWS/DynamoDB,SystemErrors,SUM
16
+ AWS/DynamoDB,ThrottledRequests,SUM
17
+ AWS/DynamoDB,UserErrors,SUM
18
+ AWS/DynamoDB,WriteThrottleEvents,SUM
19
+ AWS/EBS,VolumeConsumedReadWriteOps,AVG
20
+ AWS/EBS,VolumeIdleTime,SUM
21
+ AWS/EBS,VolumeQueueLength,AVG
22
+ AWS/EBS,VolumeReadBytes,SUM
23
+ AWS/EBS,VolumeReadOps,SUM
24
+ AWS/EBS,VolumeThroughputPercentage,AVG
25
+ AWS/EBS,VolumeTotalReadTime,SUM
26
+ AWS/EBS,VolumeTotalWriteTime,SUM
27
+ AWS/EBS,VolumeWriteBytes,SUM
28
+ AWS/EBS,VolumeWriteOps,SUM
29
+ AWS/EC2,CPUCreditBalance,AVG
30
+ AWS/EC2,CPUCreditUsage,AVG
31
+ AWS/EC2,CPUUtilization,AVG
32
+ AWS/EC2,DiskReadBytes,SUM
33
+ AWS/EC2,DiskReadOps,SUM
34
+ AWS/EC2,DiskWriteBytes,SUM
35
+ AWS/EC2,DiskWriteOps,SUM
36
+ AWS/EC2,NetworkIn,SUM
37
+ AWS/EC2,NetworkOut,SUM
38
+ AWS/EC2,StatusCheckFailed_Instance,SUM
39
+ AWS/EC2,StatusCheckFailed,SUM
40
+ AWS/EC2,StatusCheckFailed_System,SUM
41
+ AWS/ElastiCache,BytesReadIntoMemcached,SUM
42
+ AWS/ElastiCache,BytesUsedForCache,AVG
43
+ AWS/ElastiCache,BytesUsedForCacheItems,AVG
44
+ AWS/ElastiCache,BytesUsedForHash,AVG
45
+ AWS/ElastiCache,BytesWrittenOutFromMemcached,SUM
46
+ AWS/ElastiCache,CacheHits,SUM
47
+ AWS/ElastiCache,CacheMisses,SUM
48
+ AWS/ElastiCache,CasBadval,SUM
49
+ AWS/ElastiCache,CasHits,SUM
50
+ AWS/ElastiCache,CasMisses,SUM
51
+ AWS/ElastiCache,CmdConfigGet,SUM
52
+ AWS/ElastiCache,CmdConfigSet,SUM
53
+ AWS/ElastiCache,CmdFlush,SUM
54
+ AWS/ElastiCache,CmdGet,SUM
55
+ AWS/ElastiCache,CmdSet,SUM
56
+ AWS/ElastiCache,CmdTouch,SUM
57
+ AWS/ElastiCache,CPUUtilization,AVG
58
+ AWS/ElastiCache,CurrConfig,AVG
59
+ AWS/ElastiCache,CurrConnections,AVG
60
+ AWS/ElastiCache,CurrItems,AVG
61
+ AWS/ElastiCache,DecrHits,SUM
62
+ AWS/ElastiCache,DecrMisses,SUM
63
+ AWS/ElastiCache,DeleteHits,SUM
64
+ AWS/ElastiCache,DeleteMisses,SUM
65
+ AWS/ElastiCache,EvictedUnfetched,SUM
66
+ AWS/ElastiCache,Evictions,AVG
67
+ AWS/ElastiCache,Evictions,SUM
68
+ AWS/ElastiCache,ExpiredUnfetched,SUM
69
+ AWS/ElastiCache,FreeableMemory,AVG
70
+ AWS/ElastiCache,GetHits,SUM
71
+ AWS/ElastiCache,GetMisses,SUM
72
+ AWS/ElastiCache,GetTypeCmds,SUM
73
+ AWS/ElastiCache,HashBasedCmds,SUM
74
+ AWS/ElastiCache,IncrHits,SUM
75
+ AWS/ElastiCache,IncrMisses,SUM
76
+ AWS/ElastiCache,KeyBasedCmds,SUM
77
+ AWS/ElastiCache,ListBasedCmds,SUM
78
+ AWS/ElastiCache,NetworkBytesIn,AVG
79
+ AWS/ElastiCache,NetworkBytesOut,AVG
80
+ AWS/ElastiCache,NewConnections,AVG
81
+ AWS/ElastiCache,NewConnections,SUM
82
+ AWS/ElastiCache,NewItems,SUM
83
+ AWS/ElastiCache,Reclaimed,AVG
84
+ AWS/ElastiCache,Reclaimed,SUM
85
+ AWS/ElastiCache,ReplicationLag,AVG
86
+ AWS/ElastiCache,SetBasedCmds,SUM
87
+ AWS/ElastiCache,SetTypeCmds,SUM
88
+ AWS/ElastiCache,SlabsMoved,SUM
89
+ AWS/ElastiCache,SortedSetBasedCmds,SUM
90
+ AWS/ElastiCache,StringBasedCmds,SUM
91
+ AWS/ElastiCache,SwapUsage,AVG
92
+ AWS/ElastiCache,TouchHits,SUM
93
+ AWS/ElastiCache,TouchMisses,SUM
94
+ AWS/ElastiCache,UnusedMemory,AVG
95
+ AWS/ElasticMapReduce,CoreNodesPending,AVG
96
+ AWS/ElasticMapReduce,CoreNodesRunning,AVG
97
+ AWS/ElasticMapReduce,HbaseBackupFailed,SUM
98
+ AWS/ElasticMapReduce,HbaseMostRecentBackupDuration,AVG
99
+ AWS/ElasticMapReduce,HbaseTimeSinceLastSuccessfulBackup,AVG
100
+ AWS/ElasticMapReduce,HDFSBytesRead,SUM
101
+ AWS/ElasticMapReduce,HDFSBytesWritten,SUM
102
+ AWS/ElasticMapReduce,HDFSUtilization,AVG
103
+ AWS/ElasticMapReduce,IsIdle,SUM
104
+ AWS/ElasticMapReduce,JobsFailed,SUM
105
+ AWS/ElasticMapReduce,JobsRunning,SUM
106
+ AWS/ElasticMapReduce,LiveDataNodes,AVG
107
+ AWS/ElasticMapReduce,LiveTaskTrackers,AVG
108
+ AWS/ElasticMapReduce,MapSlotsOpen,AVG
109
+ AWS/ElasticMapReduce,MissingBlocks,AVG
110
+ AWS/ElasticMapReduce,ReduceSlotsOpen,AVG
111
+ AWS/ElasticMapReduce,RemainingMapTasks,AVG
112
+ AWS/ElasticMapReduce,RemainingMapTasksPerSlot,AVG
113
+ AWS/ElasticMapReduce,RemainingReduceTasks,AVG
114
+ AWS/ElasticMapReduce,RunningMapTasks,AVG
115
+ AWS/ElasticMapReduce,RunningReduceTasks,AVG
116
+ AWS/ElasticMapReduce,S3BytesRead,SUM
117
+ AWS/ElasticMapReduce,S3BytesWritten,SUM
118
+ AWS/ElasticMapReduce,TaskNodesPending,AVG
119
+ AWS/ElasticMapReduce,TaskNodesRunning,AVG
120
+ AWS/ElasticMapReduce,TotalLoad,AVG
121
+ AWS/ELB,BackendConnectionErrors,SUM
122
+ AWS/ELB,HealthyHostCount,AVG
123
+ AWS/ELB,HTTPCode_Backend_2XX,SUM
124
+ AWS/ELB,HTTPCode_Backend_3XX,SUM
125
+ AWS/ELB,HTTPCode_Backend_4XX,SUM
126
+ AWS/ELB,HTTPCode_Backend_5XX,SUM
127
+ AWS/ELB,HTTPCode_ELB_4XX,SUM
128
+ AWS/ELB,HTTPCode_ELB_5XX,SUM
129
+ AWS/ELB,Latency,AVG
130
+ AWS/ELB,RequestCount,SUM
131
+ AWS/ELB,SpilloverCount,SUM
132
+ AWS/ELB,SurgeQueueLength,AVG
133
+ AWS/ELB,UnHealthyHostCount,AVG
134
+ AWS/OpsWorks,cpu_idle,AVG
135
+ AWS/OpsWorks,cpu_nice,AVG
136
+ AWS/OpsWorks,cpu_system,AVG
137
+ AWS/OpsWorks,cpu_user,AVG
138
+ AWS/OpsWorks,cpu_waitio,AVG
139
+ AWS/OpsWorks,Load_15,AVG
140
+ AWS/OpsWorks,Load_1,AVG
141
+ AWS/OpsWorks,Load_5,AVG
142
+ AWS/OpsWorks,memory_buffers,AVG
143
+ AWS/OpsWorks,memory_cached,AVG
144
+ AWS/OpsWorks,memory_free,AVG
145
+ AWS/OpsWorks,memory_swap,AVG
146
+ AWS/OpsWorks,memory_total,AVG
147
+ AWS/OpsWorks,memory_used,AVG
148
+ AWS/OpsWorks,procs,AVG
149
+ AWS/RDS,BinLogDiskUsage,AVG
150
+ AWS/RDS,CPUUtilization,AVG
151
+ AWS/RDS,DatabaseConnections,AVG
152
+ AWS/RDS,DiskQueueDepth,AVG
153
+ AWS/RDS,FreeableMemory,AVG
154
+ AWS/RDS,FreeStorageSpace,AVG
155
+ AWS/RDS,NetworkReceiveThroughput,AVG
156
+ AWS/RDS,NetworkTransmitThroughput,AVG
157
+ AWS/RDS,ReadIOPS,AVG
158
+ AWS/RDS,ReadLatency,AVG
159
+ AWS/RDS,ReadThroughput,AVG
160
+ AWS/RDS,ReplicaLag,AVG
161
+ AWS/RDS,SwapUsage,AVG
162
+ AWS/RDS,WriteIOPS,AVG
163
+ AWS/RDS,WriteLatency,AVG
164
+ AWS/RDS,WriteThroughput,AVG
165
+ AWS/Redshift,CPUUtilization,AVG
166
+ AWS/Redshift,DatabaseConnections,AVG
167
+ AWS/Redshift,HealthStatus,AVG
168
+ AWS/Redshift,MaintenanceMode,AVG
169
+ AWS/Redshift,NetworkReceiveThroughput,AVG
170
+ AWS/Redshift,NetworkTransmitThroughput,AVG
171
+ AWS/Redshift,PercentageDiskSpaceUsed,AVG
172
+ AWS/Redshift,ReadIOPS,AVG
173
+ AWS/Redshift,ReadLatency,AVG
174
+ AWS/Redshift,ReadThroughput,AVG
175
+ AWS/Redshift,WriteIOPS,AVG
176
+ AWS/Redshift,WriteLatency,AVG
177
+ AWS/Redshift,WriteThroughput,AVG
178
+ AWS/Route53,HealthCheckStatus,AVG
179
+ AWS/SNS,NumberOfMessagesPublished,SUM
180
+ AWS/SNS,NumberOfNotificationsDelivered,SUM
181
+ AWS/SNS,NumberOfNotificationsFailed,SUM
182
+ AWS/SNS,PublishSize,AVG
183
+ AWS/SQS,ApproximateNumberOfMessagesDelayed,AVG
184
+ AWS/SQS,ApproximateNumberOfMessagesNotVisible,AVG
185
+ AWS/SQS,ApproximateNumberOfMessagesVisible,AVG
186
+ AWS/SQS,NumberOfEmptyReceives,SUM
187
+ AWS/SQS,NumberOfMessagesDeleted,SUM
188
+ AWS/SQS,NumberOfMessagesReceived,SUM
189
+ AWS/SQS,NumberOfMessagesSent,SUM
190
+ AWS/SQS,SentMessageSize,AVG
191
+ AWS/StorageGateway,CacheHitPercent,AVG
192
+ AWS/StorageGateway,CachePercentDirty,AVG
193
+ AWS/StorageGateway,CachePercentUsed,AVG
194
+ AWS/StorageGateway,CloudBytesDownloaded,SUM
195
+ AWS/StorageGateway,CloudBytesUploaded,SUM
196
+ AWS/StorageGateway,CloudDownloadLatency,AVG
197
+ AWS/StorageGateway,QueuedWrites,AVG
198
+ AWS/StorageGateway,ReadBytes,SUM
199
+ AWS/StorageGateway,ReadTime,AVG
200
+ AWS/StorageGateway,TotalCacheSize,AVG
201
+ AWS/StorageGateway,UploadBufferFree,AVG
202
+ AWS/StorageGateway,UploadBufferPercentUsed,AVG
203
+ AWS/StorageGateway,UploadBufferUsed,AVG
204
+ AWS/StorageGateway,WorkingStorageFree,AVG
205
+ AWS/StorageGateway,WorkingStoragePercentageUsed,AVG
206
+ AWS/StorageGateway,WorkingStoragePercentUsed,AVG
207
+ AWS/StorageGateway,WorkingStorageUsed,AVG
208
+ AWS/StorageGateway,WriteBytes,SUM
209
+ AWS/StorageGateway,WriteTime,AVG
210
+ AWS/SWF,DecisionTaskScheduleToStartTime,AVG
211
+ AWS/SWF,DecisionTasksCompleted,SUM
212
+ AWS/SWF,DecisionTaskStartToCloseTime,AVG
213
+ AWS/SWF,StartedDecisionTasksTimedOutOnClose,SUM
214
+ AWS/SWF,WorkflowsCanceled,SUM
215
+ AWS/SWF,WorkflowsCompleted,SUM
216
+ AWS/SWF,WorkflowsContinuedAsNew,SUM
217
+ AWS/SWF,WorkflowsFailed,SUM
218
+ AWS/SWF,WorkflowStartToCloseTime,AVG
219
+ AWS/SWF,WorkflowsTerminated,SUM
220
+ AWS/SWF,WorkflowsTimedOut,SUM