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 +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +26 -15
- data/lib/snowagent.rb +2 -3
- data/lib/snowagent/agent.rb +1 -1
- data/lib/snowagent/configuration.rb +1 -10
- data/lib/snowagent/version.rb +1 -1
- data/snowagent.gemspec +4 -0
- metadata +58 -4
- data/lib/snowagent/async_strategy.rb +0 -17
- data/lib/snowagent/sender.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 036f78e36bf8fee0461fe56c7d2521af27c95f7d
|
4
|
+
data.tar.gz: 0b06485bb20631d213eeec5db48e850c6390ff34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 854f26cf4f28743453277d4f1b65abaa53ee943905c8d0d9633060ed419ed849d389cd62192b564920d08f32a5b5f926f09a3d77c6cfc3ba6836f7b15090dcc5
|
7
|
+
data.tar.gz: 53f3a0c4be2c501fc35e1ea861889d9a9e1cc6f0389732c485ca5d5b7c55d507bd96dc00a8eac63b1db3dac8b9c0d138a8b7f8015846648da67997c1cbdae34a
|
data/CHANGELOG.md
CHANGED
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
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
13
|
+
Example of installation instructions page:
|
14
|
+
|
15
|
+
![](doc/install.png)
|
12
16
|
|
13
|
-
|
17
|
+
## Usage
|
14
18
|
|
15
|
-
|
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
|
-
|
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
|
-
|
24
|
+
Code examples:
|
25
|
+
``` ruby
|
26
|
+
# In controller
|
27
|
+
SnowAgent.delay.increment("User Login")
|
20
28
|
|
21
|
-
|
29
|
+
# In scheduled task
|
30
|
+
SnowAgent.time("Task Time") do
|
31
|
+
# time consumed calculations
|
32
|
+
end
|
22
33
|
|
23
|
-
|
34
|
+
# Some custom metric
|
35
|
+
SnowAgent.metric("Sessions Amount", Session.alive.count, "amount")
|
36
|
+
```
|
24
37
|
|
25
38
|
## Contributing
|
26
39
|
|
27
|
-
1.
|
28
|
-
2.
|
29
|
-
3.
|
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
|
data/lib/snowagent.rb
CHANGED
@@ -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
|
-
|
38
|
+
logger.debug "Metric was not send due to configuration."
|
40
39
|
end
|
41
40
|
|
42
41
|
nil
|
data/lib/snowagent/agent.rb
CHANGED
@@ -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?
|
25
|
+
!server.nil? && !secret_token.nil?
|
35
26
|
end
|
36
27
|
end
|
37
28
|
end
|
data/lib/snowagent/version.rb
CHANGED
data/snowagent.gemspec
CHANGED
@@ -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
|
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-
|
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
|
data/lib/snowagent/sender.rb
DELETED
@@ -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
|