metrico 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +49 -0
- data/README.md +10 -2
- data/lib/metrico/client.rb +10 -3
- data/lib/metrico/config.rb +6 -4
- data/lib/metrico/point.rb +1 -1
- data/lib/metrico/version.rb +1 -1
- data/lib/metrico.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a8644b7e9a984a6345ade83ca30e2ed8ebfc0c2
|
4
|
+
data.tar.gz: 247607784d7957334bcaa52e9693a52829858a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33d6aec3386624f37a0a5313f88f294a9b0ac8f5d62c76de25f3664d9e05d0156105f9b03a94872e580fde779fb851a965b5b5e30ea1a74fa8bf5346e12db1e4
|
7
|
+
data.tar.gz: ddc966ae1109ed7e266f364143e54bc5a494d703aba96600981eff11d881fe2a0e2060cd70ba5d5f8792acfd9cc6ea6ebbf00b2d647e26602aea9084c6c2f810
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-06-22 17:25:28 +0300 using RuboCop version 0.49.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
# Cop supports --auto-correct.
|
11
|
+
Layout/SpaceAfterComma:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/metrico/point.rb'
|
14
|
+
|
15
|
+
# Offense count: 1
|
16
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
17
|
+
# URISchemes: http, https
|
18
|
+
Metrics/LineLength:
|
19
|
+
Max: 85
|
20
|
+
|
21
|
+
# Offense count: 4
|
22
|
+
Style/Documentation:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/**/*'
|
25
|
+
- 'test/**/*'
|
26
|
+
- 'lib/metrico.rb'
|
27
|
+
- 'lib/metrico/client.rb'
|
28
|
+
- 'lib/metrico/config.rb'
|
29
|
+
- 'lib/metrico/point.rb'
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Cop supports --auto-correct.
|
33
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
34
|
+
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
35
|
+
Style/HashSyntax:
|
36
|
+
Exclude:
|
37
|
+
- 'Rakefile'
|
38
|
+
|
39
|
+
# Offense count: 11
|
40
|
+
# Cop supports --auto-correct.
|
41
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
42
|
+
# SupportedStyles: single_quotes, double_quotes
|
43
|
+
Style/StringLiterals:
|
44
|
+
Exclude:
|
45
|
+
- 'Gemfile'
|
46
|
+
- 'Rakefile'
|
47
|
+
- 'bin/console'
|
48
|
+
- 'spec/metrico_spec.rb'
|
49
|
+
- 'spec/spec_helper.rb'
|
data/README.md
CHANGED
@@ -19,11 +19,19 @@ $ bundle install
|
|
19
19
|
```ruby
|
20
20
|
# config/initializers/metrico.rb
|
21
21
|
Metrico.configure do |config|
|
22
|
-
config.app_name = '
|
22
|
+
config.app_name = 'app_name' # required
|
23
23
|
config.hostname = 'globalhost' # required
|
24
|
-
config.
|
24
|
+
config.nats_connect_options = {
|
25
|
+
servers: ['nats://telegraf-0.somenatsnode.com:4222']
|
26
|
+
}
|
27
|
+
# define lambdas for these callbacks if you need some
|
28
|
+
config.on_error = ->{}
|
29
|
+
config.on_reconnect = ->{}
|
30
|
+
config.on_disconnect = ->{}
|
31
|
+
config.on_close = ->{}
|
25
32
|
end
|
26
33
|
```
|
34
|
+
For more nats connect options see [https://github.com/nats-io/pure-ruby-nats/blob/master/lib/nats/io/client.rb#L154](https://github.com/nats-io/pure-ruby-nats/blob/master/lib/nats/io/client.rb#L154). You also can define most of all connection config via ENV variables.
|
27
35
|
|
28
36
|
## Usage
|
29
37
|
In your app you have to push metrics, passing name, hash of metric/value and hash of tags.
|
data/lib/metrico/client.rb
CHANGED
@@ -4,13 +4,20 @@ module Metrico
|
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@transport = NATS::IO::Client.new
|
7
|
-
@transport.connect(
|
8
|
-
|
9
|
-
)
|
7
|
+
@transport.connect(Metrico.config.nats_connect_options)
|
8
|
+
transport_callbacks
|
10
9
|
end
|
11
10
|
|
12
11
|
def push(point)
|
13
12
|
transport.publish(Metrico.config.subject, point.to_s)
|
14
13
|
end
|
14
|
+
|
15
|
+
private def transport_callbacks
|
16
|
+
%w[on_error on_reconnect on_disconnect on_close].each do |callback|
|
17
|
+
if Metrico.config.send(callback)
|
18
|
+
@transport.send(callback, &Metrico.config.send(callback))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
data/lib/metrico/config.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
module Metrico
|
2
2
|
class Config
|
3
|
-
attr_accessor
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
attr_accessor(
|
4
|
+
:enabled, :app_name, :hostname,
|
5
|
+
:subject, :nats_connect_options,
|
6
|
+
:on_error, :on_reconnect,
|
7
|
+
:on_disconnect, :on_close
|
8
|
+
)
|
7
9
|
|
8
10
|
def initialize
|
9
11
|
@subject = 'metrico'
|
data/lib/metrico/point.rb
CHANGED
data/lib/metrico/version.rb
CHANGED
data/lib/metrico.rb
CHANGED
@@ -18,9 +18,13 @@ module Metrico
|
|
18
18
|
@client ||= Client.new
|
19
19
|
end
|
20
20
|
|
21
|
+
def enabled?
|
22
|
+
self.config && self.config.enabled
|
23
|
+
end
|
24
|
+
|
21
25
|
def push(name, fields, tags = {})
|
22
26
|
point = Point.new(name, fields, tags)
|
23
|
-
client.push(point)
|
27
|
+
client.push(point) if enabled?
|
24
28
|
end
|
25
29
|
end
|
26
30
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metrico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Shamatov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nats-pure
|
@@ -75,6 +75,7 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
77
|
- ".rspec"
|
78
|
+
- ".rubocop.yml"
|
78
79
|
- ".travis.yml"
|
79
80
|
- Gemfile
|
80
81
|
- LICENSE.txt
|