alephant-logger-cloudwatch 0.0.1 → 1.0.0

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: 49bb3b54d068eea1862e525fe1ba3ada05305326
4
- data.tar.gz: 7b7bf0276a14d2e2021d845a05e9c9666181795a
3
+ metadata.gz: 81122f72cb26f4f21e45ee98bfbc281c2c2373f5
4
+ data.tar.gz: 7367511b1243204d05c6192ca6ea794b0eca353f
5
5
  SHA512:
6
- metadata.gz: 6cd72a663832174e1e59c0918bd0abebf794626bdf0c50e9938eea17d57429022c0131b21be014c8413c5e4607c2ba041533ddb37ea1fe2ef95384175e19825a
7
- data.tar.gz: 093c48246808be12c90ab54c332be5cda0f4efacd2546cbd7f93897387d8d14f2eb2d87ccc3b4bcd60dddc9869d3b9fff451e737b342c42c8517a96f28eeaa57
6
+ metadata.gz: 3784052f95209ae004993c6727d79b3583aff1fda82dc156f702ad7d09ac331a97183c461ceeb6a628a90773ca94f9739883e0f1b8948b3adada59d7fd8a03aa
7
+ data.tar.gz: 4fb871e9b4828188b10e84351b43d9cdc413957e570a02e21347009571fbc97c77323b86974966d014421b72f9088354712017b641ed24e9a99cdf01caaa0a23
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in alephant-logger-cloudwatch.gemspec
4
3
  gemspec
data/README.md CHANGED
@@ -30,7 +30,7 @@ require "alephant/logger/cloudwatch"
30
30
 
31
31
  cloudwatch_driver = Alephant::Logger::CloudWatch.new "my_namespace"
32
32
 
33
- logger = Alephant::Logger.create([cloudwatch_driver])
33
+ logger = Alephant::Logger.setup cloudwatch_driver
34
34
  logger.metric(:name => "FooBar", :unit => "Count", :value => 1)
35
35
  ```
36
36
 
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/rspec"
2
3
 
4
+ task :default => :spec
@@ -1,7 +1,8 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'alephant/logger/cloudwatch/version'
5
+ require "alephant/logger/cloudwatch/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "alephant-logger-cloudwatch"
@@ -21,6 +22,8 @@ Gem::Specification.new do |spec|
21
22
  spec.add_development_dependency "bundler", "~> 1.7"
22
23
  spec.add_development_dependency "rake", "~> 10.0"
23
24
  spec.add_development_dependency "rspec", "~> 3"
24
- spec.add_development_dependency "aws-sdk"
25
+ spec.add_development_dependency "aws-sdk", "~> 1"
25
26
  spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "rake-rspec"
28
+ spec.add_development_dependency "rspec-nc"
26
29
  end
@@ -3,30 +3,28 @@ require "aws-sdk"
3
3
  module Alephant
4
4
  module Logger
5
5
  class CloudWatch
6
- def initialize(namespace)
7
- @namespace = namespace
6
+ def initialize(opts)
8
7
  @cloudwatch = AWS::CloudWatch.new
8
+ @defaults = process_defaults opts
9
9
  end
10
10
 
11
11
  def metric(opts)
12
- name, value, unit, dimensions = opts.values_at(:name, :value, :unit, :dimensions)
13
-
14
- Thread.new do
15
- cloudwatch.put_metric_data(
16
- :namespace => namespace,
17
- :metric_data => [{
18
- :metric_name => name,
19
- :value => value,
20
- :unit => unit || "None",
21
- :dimensions => parse(dimensions || {})
22
- }]
23
- )
24
- end
12
+ send_metric(*opts.values_at(:name, :value, :unit, :dimensions))
25
13
  end
26
14
 
27
15
  private
28
16
 
29
- attr_reader :cloudwatch, :namespace
17
+ attr_reader :cloudwatch, :defaults
18
+
19
+ def process_defaults(opts)
20
+ preset_defaults.reduce({}) do |acc, (key, value)|
21
+ acc.tap { |h| h[key] = opts.fetch(key, value) }
22
+ end.merge :namespace => opts.fetch(:namespace)
23
+ end
24
+
25
+ def preset_defaults
26
+ { :unit => "Count", :value => 1, :dimensions => {} }
27
+ end
30
28
 
31
29
  def parse(dimensions)
32
30
  dimensions.map do |name, value|
@@ -36,7 +34,20 @@ module Alephant
36
34
  }
37
35
  end
38
36
  end
37
+
38
+ def send_metric(name, value, unit, dimensions)
39
+ Thread.new do
40
+ cloudwatch.put_metric_data(
41
+ :namespace => defaults[:namespace],
42
+ :metric_data => [{
43
+ :metric_name => name,
44
+ :value => value || defaults[:value],
45
+ :unit => unit || defaults[:unit],
46
+ :dimensions => parse(dimensions || defaults[:dimensions])
47
+ }]
48
+ )
49
+ end
50
+ end
39
51
  end
40
52
  end
41
53
  end
42
-
@@ -1,7 +1,7 @@
1
1
  module Alephant
2
2
  module Logger
3
3
  module Cloudwatch
4
- VERSION = "0.0.1"
4
+ VERSION = "1.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,31 +1,43 @@
1
1
  require "alephant/logger/cloudwatch"
2
2
 
3
3
  describe Alephant::Logger::CloudWatch do
4
- subject { described_class.new("namespace") }
4
+ subject { described_class.new(:namespace => "namespace") }
5
5
 
6
6
  let(:namespace) { "namespace" }
7
7
 
8
8
  describe "#metric" do
9
9
  let(:opts) do
10
- { :name => "a",
11
- :value => "b",
12
- :unit => "c",
13
- :dimensions => { "dimension" => "value" } }
10
+ {
11
+ :name => "a",
12
+ :value => "b",
13
+ :unit => "c",
14
+ :dimensions => {
15
+ "dimension" => "value"
16
+ }
17
+ }
14
18
  end
15
19
 
16
20
  let(:metric_data) do
17
- { :metric_name => "a",
18
- :value => "b",
19
- :unit => "c",
20
- :dimensions => [ { :name => "dimension",
21
- :value => "value" } ] }
21
+ {
22
+ :metric_name => "a",
23
+ :value => "b",
24
+ :unit => "c",
25
+ :dimensions => [
26
+ {
27
+ :name => "dimension",
28
+ :value => "value"
29
+ }
30
+ ]
31
+ }
22
32
  end
23
33
 
24
34
  specify do
25
35
  expect_any_instance_of(AWS::CloudWatch)
26
36
  .to receive(:put_metric_data)
27
- .with(:namespace => namespace,
28
- :metric_data => [metric_data])
37
+ .with(
38
+ :namespace => namespace,
39
+ :metric_data => [metric_data]
40
+ )
29
41
 
30
42
  subject.metric(opts).join
31
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-logger-cloudwatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-30 00:00:00.000000000 Z
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,6 +54,20 @@ dependencies:
54
54
  version: '3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aws-sdk
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - '>='
@@ -67,7 +81,21 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
- name: pry
84
+ name: rake-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-nc
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - '>='
@@ -122,3 +150,4 @@ specification_version: 4
122
150
  summary: Cloudwatch driver for Alephant::Logger
123
151
  test_files:
124
152
  - spec/cloudwatch_spec.rb
153
+ has_rdoc: