metrico 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f4776d64decd912f548770131eced35b429d21f0
4
+ data.tar.gz: '07019fd49b1a63c5c3bb444ac8bb78acfde50d17'
5
+ SHA512:
6
+ metadata.gz: 858e79e3e87816629a2ca2828e73f284317ebf4eec0cc4f245db8172998c047040dd1acf730ae66c1aad0730d60b19b2cb96019e665d0799989e21697511467b
7
+ data.tar.gz: 84a25d433efa0efb17757489b195d68d3073b8e52650b290245ef5f92bd545d8535201f59242d744f3eb8908a9f5db13f918a4d7ca3fa6dfd9d884cf2efad4ac
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in metrico.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Ivan Shamatov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Metrico [early MVP] [specs required]
2
+
3
+ > NATS ruby client to write metrics
4
+ > Use it to push in InfluxDB format through NATS
5
+ > `https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_tutorial/`
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'metrico'
13
+ ```
14
+
15
+ ```
16
+ $ bundle install
17
+ ```
18
+
19
+ ```ruby
20
+ # config/initializers/metrico.rb
21
+ Metrico.configure do |config|
22
+ config.app_name = 'Compliance' # required
23
+ config.hostname = 'globalhost' # required
24
+ config.nodes = ['nats://telegraf-0.somenatsnode.com:4222'] # required
25
+ end
26
+ ```
27
+
28
+ ## Usage
29
+ In your app you have to push metrics, passing name, hash of metric/value and hash of tags.
30
+
31
+ Examples:
32
+ ```ruby
33
+ Metrico.push('3rd_party', {response_time: 1300, sidekiq_retry: 2}, {service: :first})
34
+
35
+ Metrico.push(
36
+ 'heartbeat',
37
+ { cpu: 99, memory: 3200 }
38
+ )
39
+ ```
40
+
41
+ ## License
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "metrico"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ module Metrico
2
+ class Client
3
+ attr_reader :transport
4
+
5
+ def initialize
6
+ @transport = NATS::IO::Client.new
7
+ @transport.connect(
8
+ servers: Metrico.config.nodes
9
+ )
10
+ end
11
+
12
+ def push(point)
13
+ transport.publish(Metrico.config.subject, point.to_s)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,12 @@
1
+ module Metrico
2
+ class Config
3
+ attr_accessor :nodes,
4
+ :app_name,
5
+ :hostname,
6
+ :subject
7
+
8
+ def initialize
9
+ @subject = 'metrico'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ module Metrico
2
+ class Point
3
+ attr_accessor :name, :tags, :fields
4
+
5
+ def initialize(name, fields, tags = {})
6
+ @name = name
7
+ @fields = fields
8
+ tags = { hostname: Metrico.config.hostname }.merge(tags)
9
+ @tags = tags
10
+ end
11
+
12
+ # https://docs.influxdata.com/influxdb/v1.2/write_protocols/line_protocol_tutorial/
13
+ # InfluxDB Line Protocol
14
+ def to_s
15
+ message = [
16
+ metric_name,
17
+ metric_props
18
+ ].join(',')
19
+ puts message
20
+ message
21
+ end
22
+
23
+ private def metric_name
24
+ [Metrico.config.app_name, name].join(':')
25
+ end
26
+
27
+ private def metric_props
28
+ [
29
+ comma_equal_flatten(tags),
30
+ comma_equal_flatten(fields),
31
+ timestamp
32
+ ].join(' ')
33
+ end
34
+
35
+ private def timestamp
36
+ (Time.now.to_f * 1_000_000_000).to_i
37
+ end
38
+
39
+ private def comma_equal_flatten(hash)
40
+ hash.map { |k,v| [k,v].join('=') }.join(',')
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module Metrico
2
+ VERSION = "0.1.0"
3
+ end
data/lib/metrico.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'nats/io/client'
2
+ require 'metrico/version'
3
+
4
+ module Metrico
5
+ require 'metrico/client'
6
+ require 'metrico/config'
7
+ require 'metrico/point'
8
+
9
+ class << self
10
+ attr_accessor :config
11
+
12
+ def configure
13
+ self.config ||= Config.new
14
+ yield(config)
15
+ end
16
+
17
+ def client
18
+ @client ||= Client.new
19
+ end
20
+
21
+ def push(name, fields, tags = {})
22
+ point = Point.new(name, fields, tags)
23
+ client.push(point)
24
+ end
25
+ end
26
+ end
data/metrico.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'metrico/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'metrico'
9
+ spec.version = Metrico::VERSION
10
+ spec.authors = ['Ivan Shamatov']
11
+ spec.email = ['status.enable@gmail.com']
12
+
13
+ spec.summary = 'NATS ruby client to write metrics'
14
+ spec.description = 'Use it to write your metrics in InfluxDB format through NATS'
15
+ spec.homepage = 'https://github.com/IvanShamatov/metrico'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+ spec.add_dependency 'nats-pure', '~> 0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.15'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metrico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Shamatov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nats-pure
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Use it to write your metrics in InfluxDB format through NATS
70
+ email:
71
+ - status.enable@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/metrico.rb
86
+ - lib/metrico/client.rb
87
+ - lib/metrico/config.rb
88
+ - lib/metrico/point.rb
89
+ - lib/metrico/version.rb
90
+ - metrico.gemspec
91
+ homepage: https://github.com/IvanShamatov/metrico
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.6.11
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: NATS ruby client to write metrics
115
+ test_files: []