snowagent 0.0.3 → 0.1.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: 42aacb27b1de008f048ef737649388ede58a7060
4
- data.tar.gz: 8ed7ac6e359b29e47b59b37778cc7cb373c59106
3
+ metadata.gz: 036f78e36bf8fee0461fe56c7d2521af27c95f7d
4
+ data.tar.gz: 0b06485bb20631d213eeec5db48e850c6390ff34
5
5
  SHA512:
6
- metadata.gz: 378d78170e3bc1a75691520bbe71969235295e2754362214643b0fad438667fa64ba2b1b23fd85ac3a839da6a90222b0bbefcabe128dcb924a2ddaaf3cda3714
7
- data.tar.gz: a4045d4bddf3ac31e1b53f988979c0a69114eb6d494d8b5cfc2f43ca11bbf1fb0e2abdc78010acaf80af3bbc9be45124ea9ede55e75a75063f0ad7621623bccd
6
+ metadata.gz: 854f26cf4f28743453277d4f1b65abaa53ee943905c8d0d9633060ed419ed849d389cd62192b564920d08f32a5b5f926f09a3d77c6cfc3ba6836f7b15090dcc5
7
+ data.tar.gz: 53f3a0c4be2c501fc35e1ea861889d9a9e1cc6f0389732c485ca5d5b7c55d507bd96dc00a8eac63b1db3dac8b9c0d138a8b7f8015846648da67997c1cbdae34a
@@ -1,5 +1,9 @@
1
1
  # SnowAgent
2
2
 
3
+ Version 0.1.0 - 2015.09.12
4
+ - Remove support of async strategy
5
+ - Add useful release script
6
+
3
7
  Version 0.0.3 - 2015.06.08
4
8
  - Add `time` and `increment` metrics
5
9
  - `async = true` by default
data/README.md CHANGED
@@ -2,30 +2,41 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/snowagent.svg)](http://badge.fury.io/rb/snowagent) [![Build Status](https://travis-ci.org/snowman-io/snowagent.svg)](https://travis-ci.org/snowman-io/snowagent)
4
4
 
5
+ Gem for sending metrics to [SnowmanIO](http://snowman.io).
6
+
5
7
  ## Installation
6
8
 
7
- Add this line to your application's Gemfile:
9
+ 1. Register new application in your SnowmanIO instance.
10
+ 2. Add `gem 'snowagent'` to application's Gemfile.
11
+ 3. Add two environments variables as described on 'Install' section of application
8
12
 
9
- ```ruby
10
- gem 'snowagent'
11
- ```
13
+ Example of installation instructions page:
14
+
15
+ ![](doc/install.png)
12
16
 
13
- And then execute:
17
+ ## Usage
14
18
 
15
- $ bundle
19
+ The main goal of SnowmanIO is to collect low frequient business metrics and trends. So the agent
20
+ supports only synchronous mode of sending metrics via HTTP/HTTPS.
16
21
 
17
- Or install it yourself as:
22
+ It's strongly recomended **don't send metric directly from request**. Instead use cron tasks, delalyed jobs and other background processes to deliver metrics!
18
23
 
19
- $ gem install snowagent
24
+ Code examples:
25
+ ``` ruby
26
+ # In controller
27
+ SnowAgent.delay.increment("User Login")
20
28
 
21
- ## Usage
29
+ # In scheduled task
30
+ SnowAgent.time("Task Time") do
31
+ # time consumed calculations
32
+ end
22
33
 
23
- TODO: Write usage instructions here
34
+ # Some custom metric
35
+ SnowAgent.metric("Sessions Amount", Session.alive.count, "amount")
36
+ ```
24
37
 
25
38
  ## Contributing
26
39
 
27
- 1. Fork it ( https://github.com/snowman-io/snowagent/fork )
28
- 2. Create your feature branch (`git checkout -b my-new-feature`)
29
- 3. Commit your changes (`git commit -am 'Add some feature'`)
30
- 4. Push to the branch (`git push origin my-new-feature`)
31
- 5. Create a new Pull Request
40
+ 1. Implement a feature (remember about tests and CHANGELOG.md!)
41
+ 2. (optional) Suggest a [blog](https://github.com/snowman-io/blog) mini post about new feature
42
+ 3. :snowman: will be happier
@@ -4,9 +4,7 @@ require 'logger'
4
4
 
5
5
  require "snowagent/version"
6
6
  require "snowagent/agent"
7
- require "snowagent/async_strategy"
8
7
  require "snowagent/sync_strategy"
9
- require "snowagent/sender"
10
8
  require "snowagent/service"
11
9
  require "snowagent/configuration"
12
10
 
@@ -19,6 +17,7 @@ end
19
17
  module SnowAgent
20
18
  class << self
21
19
  attr_writer :configuration
20
+ attr_writer :logger
22
21
 
23
22
  def logger
24
23
  @logger ||= Logger.new(STDOUT)
@@ -36,7 +35,7 @@ module SnowAgent
36
35
  if configuration.configured?
37
36
  agent.metric(*args)
38
37
  else
39
- # logger.debug "Metric was not send due to configuration."
38
+ logger.debug "Metric was not send due to configuration."
40
39
  end
41
40
 
42
41
  nil
@@ -1,7 +1,7 @@
1
1
  module SnowAgent
2
2
  class Agent
3
3
  def initialize(configuration)
4
- strategy_class = configuration.async ? AsyncStrategy : SyncStrategy
4
+ strategy_class = SyncStrategy
5
5
  @strategy = strategy_class.new(configuration)
6
6
  end
7
7
 
@@ -6,32 +6,23 @@ module SnowAgent
6
6
  # Secret access token for authentication with SnowmanIO
7
7
  attr_accessor :secret_token
8
8
 
9
- # Interval for reporting data to the server
10
- attr_accessor :send_interval
11
-
12
9
  # Timeout when waiting for the server to return data in seconds
13
10
  attr_accessor :read_timeout
14
11
 
15
12
  # Timout when opening connection to the server
16
13
  attr_accessor :open_timeout
17
14
 
18
- # Whether send metrics asynchronously or not
19
- attr_accessor :async
20
-
21
15
  def initialize
22
16
  self.server = ENV['SNOWMANIO_SERVER']
23
17
  self.secret_token = ENV['SNOWMANIO_SECRET_TOKEN']
24
- self.send_interval = 15
25
18
 
26
19
  self.read_timeout = 30
27
20
  self.open_timeout = 30
28
-
29
- self.async = false
30
21
  end
31
22
 
32
23
  # Determines if the agent confiured to send metrics.
33
24
  def configured?
34
- !server.nil? # TODO: also check secret_token token
25
+ !server.nil? && !secret_token.nil?
35
26
  end
36
27
  end
37
28
  end
@@ -1,3 +1,3 @@
1
1
  module SnowAgent
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -22,4 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.1"
25
+ spec.add_development_dependency "webmock", "~> 1.21"
26
+ spec.add_development_dependency "timecop", "~> 0.8"
27
+ spec.add_development_dependency "ansi", "~> 1.5"
28
+ spec.add_development_dependency "git", "~> 1.2"
25
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowagent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Vakhov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-08 00:00:00.000000000 Z
12
+ date: 2015-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,6 +53,62 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.1'
56
+ - !ruby/object:Gem::Dependency
57
+ name: webmock
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.21'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.21'
70
+ - !ruby/object:Gem::Dependency
71
+ name: timecop
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.8'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.8'
84
+ - !ruby/object:Gem::Dependency
85
+ name: ansi
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.5'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.5'
98
+ - !ruby/object:Gem::Dependency
99
+ name: git
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '1.2'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '1.2'
56
112
  description: Send metrics to snowman
57
113
  email:
58
114
  - artyom.keydunov@gmail.com
@@ -65,10 +121,8 @@ files:
65
121
  - README.md
66
122
  - lib/snowagent.rb
67
123
  - lib/snowagent/agent.rb
68
- - lib/snowagent/async_strategy.rb
69
124
  - lib/snowagent/configuration.rb
70
125
  - lib/snowagent/railtie.rb
71
- - lib/snowagent/sender.rb
72
126
  - lib/snowagent/service.rb
73
127
  - lib/snowagent/sync_strategy.rb
74
128
  - lib/snowagent/version.rb
@@ -1,17 +0,0 @@
1
- module SnowAgent
2
- class AsyncStrategy
3
- def initialize(configuration)
4
- @queue = Queue.new
5
- run_sender(configuration)
6
- end
7
-
8
- def run_sender(conf)
9
- sender_thread = Thread.new { Sender.new(@queue, conf).run }
10
- sender_thread.abort_on_exception = true
11
- end
12
-
13
- def metric(metric)
14
- @queue.push(metric)
15
- end
16
- end
17
- end
@@ -1,37 +0,0 @@
1
- module SnowAgent
2
- class Sender
3
- def initialize(queue, conf)
4
- @queue = queue
5
- @service = Service.new(conf)
6
- @conf = conf
7
- @metrics = []
8
- @send_at = Time.now.to_i + @conf.send_interval
9
- end
10
-
11
- def run
12
- loop { process }
13
- end
14
-
15
- def process
16
- # Pop metrics from the queue
17
- while !@queue.empty?
18
- @metrics << @queue.pop
19
- end
20
-
21
- if @send_at <= Time.now.to_i
22
- @send_at = Time.now.to_i + @conf.send_interval
23
- send_data if @metrics.any?
24
- end
25
-
26
- sleep 1
27
- end
28
-
29
- def send_data
30
- # TODO:
31
- # * requeue data on failure
32
- @service.post_data({ metrics: @metrics.map(&:to_h) })
33
-
34
- @metrics.clear
35
- end
36
- end
37
- end