radiosonde 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75143e75e9fad051bdae8993ad6d67d583b3873f
4
- data.tar.gz: d0c7c4e7fee046cd4d644702aab4b406200f126c
3
+ metadata.gz: 833238437bfc6c3c546b32d92b775025bf404998
4
+ data.tar.gz: 7c4779551a627ac35ff89b7955e6df7a03cdc264
5
5
  SHA512:
6
- metadata.gz: b1bf53f56c20e10b82bed5cbf3926335acaaa1603a5ddf0de7cf2dfbcfb2fa82f048bc3050663054f5c68c776e42cfbf193502246a1e0f7ceb70316b72238f5c
7
- data.tar.gz: a0fc622cfc46c04b57b63771d07010ea98e50bbb005e2387482b6dcaf1d4ad46090a02cb6ec9b8435a947350736b6c55f2afdbbe5e74069f2c351c9739ae26be
6
+ metadata.gz: ce9b9cbf7640d3129a8237197774359c2cadef7bfceefb0cb316ec08419e7dc66978c84377160ece738f71ceb13ad098fce96be90fadf4b65e025925a44c6d36
7
+ data.tar.gz: e971b3029f462aeb2a800d0602f5ab561ea84cbca8c31f87c9d143c349669c5817e7f659193fac67274d4bc69bf8390482701baa4abb1cea47da29358de3ac08
data/README.md CHANGED
@@ -43,6 +43,14 @@ Usage: radiosonde [options]
43
43
  --dry-run
44
44
  -e, --export
45
45
  -o, --output FILE
46
+ --show-metrics
47
+ --show-dimensions
48
+ --show-statistics
49
+ --namespace NAMESPACE
50
+ --metric-name NAME
51
+ --start-time TIME
52
+ --end-time TIME
53
+ --statistic STATISTIC
46
54
  --no-color
47
55
  --debug
48
56
  ```
data/bin/radiosonde CHANGED
@@ -3,6 +3,8 @@ $: << File.expand_path("#{File.dirname __FILE__}/../lib")
3
3
  require 'rubygems'
4
4
  require 'radiosonde'
5
5
  require 'optparse'
6
+ require 'optparse/time'
7
+ require 'time'
6
8
 
7
9
  Version = Radiosonde::VERSION
8
10
  DEFAULT_FILENAME = 'Alarmfile'
@@ -17,6 +19,12 @@ options = {
17
19
  :debug => false,
18
20
  }
19
21
 
22
+ show_opts = {
23
+ :start_time => Time.now - 3600,
24
+ :end_time => Time.now,
25
+ :statistic => :average,
26
+ }
27
+
20
28
  ARGV.options do |opt|
21
29
  begin
22
30
  access_key = nil
@@ -24,17 +32,28 @@ ARGV.options do |opt|
24
32
  region = nil
25
33
  profile_name = nil
26
34
 
27
- opt.on('-p', '--profile PROFILE_NAME') {|v| profile_name = v }
28
- opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
29
- opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
30
- opt.on('-r', '--region REGION') {|v| region = v }
31
- opt.on('-a', '--apply') { mode = :apply }
32
- opt.on('-f', '--file FILE') {|v| file = v }
33
- opt.on('', '--dry-run') { options[:dry_run] = true }
34
- opt.on('-e', '--export') { mode = :export }
35
- opt.on('-o', '--output FILE') {|v| output_file = v }
36
- opt.on('' , '--no-color') { options[:color] = false }
37
- opt.on('' , '--debug') { options[:debug] = true }
35
+ opt.on('-p', '--profile PROFILE_NAME') {|v| profile_name = v }
36
+ opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
37
+ opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
38
+ opt.on('-r', '--region REGION') {|v| region = v }
39
+ opt.on('-a', '--apply') { mode = :apply }
40
+ opt.on('-f', '--file FILE') {|v| file = v }
41
+ opt.on('', '--dry-run') { options[:dry_run] = true }
42
+ opt.on('-e', '--export') { mode = :export }
43
+ opt.on('-o', '--output FILE') {|v| output_file = v }
44
+ opt.on('', '--show-metrics') { mode = :show_metrics }
45
+ opt.on('', '--show-dimensions') { mode = :show_dimensions }
46
+ opt.on('', '--show-statistics') { mode = :show_statistics }
47
+ opt.on('', '--namespace NAMESPACE') {|v| show_opts[:namespace] = v }
48
+ opt.on('', '--metric-name NAME') {|v| show_opts[:metric_name] = v }
49
+ opt.on('', '--start-time TIME', Time) {|v| show_opts[:start_time] = v }
50
+ opt.on('', '--end-time TIME', Time) {|v| show_opts[:end_time] = v }
51
+ opt.on('', '--end-time TIME', Time) {|v| show_opts[:end_time] = v }
52
+ opt.on('' , '--statistic STATISTIC', Radiosonde::DSL::Statistic::ALIASES.values) {|v|
53
+ show_opts[:statistic]
54
+ }
55
+ opt.on('' , '--no-color') { options[:color] = false }
56
+ opt.on('' , '--debug') { options[:debug] = true }
38
57
  opt.parse!
39
58
 
40
59
  aws_opts = {}
@@ -97,6 +116,13 @@ begin
97
116
  updated = client.apply(file)
98
117
 
99
118
  logger.info('No change'.intense_blue) unless updated
119
+ when :show_metrics
120
+ puts JSON.pretty_generate(client.metrics(show_opts))
121
+ when :show_dimensions
122
+ puts JSON.pretty_generate(client.metrics(show_opts.merge(:with_dimensions => true)))
123
+ when :show_statistics
124
+ show_opts[:statistics] = [Radiosonde::DSL::Statistic.normalize(show_opts[:statistic])]
125
+ puts JSON.pretty_generate(client.metrics(show_opts.merge(:with_statistics => true)))
100
126
  else
101
127
  raise 'must not happen'
102
128
  end
@@ -17,6 +17,43 @@ class Radiosonde::Client
17
17
  Radiosonde::DSL.convert(exported, @options.merge(opts))
18
18
  end
19
19
 
20
+ def metrics(opts = {})
21
+ namespaces = {}
22
+
23
+ AWS.memoize do
24
+ ms = @cloud_watch.metrics
25
+
26
+ [:namespace, :metric_name].each do |name|
27
+ if (value = opts[name])
28
+ ms = ms.filter(name.to_s, value)
29
+ end
30
+ end
31
+
32
+ ms.sort_by {|m| [m.namespace, m.metric_name] }.each do |m|
33
+ if opts[:with_statistics]
34
+ namespaces[m.namespace] ||= {}
35
+ statistics_ops = {}
36
+ [:start_time, :end_time, :statistics].each do |name|
37
+ statistics_ops[name] = opts[name] if opts[name]
38
+ end
39
+ statistics = m.statistics(statistics_ops)
40
+ namespaces[m.namespace][m.metric_name] = {
41
+ :label => statistics.label,
42
+ :datapoints => statistics.datapoints
43
+ }
44
+ elsif opts[:with_dimensions]
45
+ namespaces[m.namespace] ||= {}
46
+ namespaces[m.namespace][m.metric_name] = m.dimensions
47
+ else
48
+ namespaces[m.namespace] ||= []
49
+ namespaces[m.namespace] << m.metric_name
50
+ end
51
+ end
52
+ end
53
+
54
+ return namespaces
55
+ end
56
+
20
57
  def apply(file)
21
58
  AWS.memoize { walk(file) }
22
59
  end
@@ -1,3 +1,3 @@
1
1
  module Radiosonde
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: radiosonde
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara