mettric 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a2285181b588c6f4765443ae11ee4bd9803ee32
4
+ data.tar.gz: 2d626f504da61119a9b675444a05473af7732a1d
5
+ SHA512:
6
+ metadata.gz: 4d1cf9921a93de477cfcef6161e93217660419d931ed364aff2074bf9c29af16218e397a32d53fa1cb2445a8ed6d412d34f717f950be8f34268e2612ba5e3f87
7
+ data.tar.gz: 90b51b739c39ad34f701c8b730cdf1de28fed30b2b0620298914bde789a1b187a4c3cf624a3ec3443adc9838fc8c7e00617b0d97b679796fd5e7df3ccabef558
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at jannis@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mettric.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ guard :rspec, all_on_start: true, cmd: "bundle exec rspec" do
2
+ watch(%r{^spec/.+\.rb$}) { "spec" }
3
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jannis Hermanns
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.
@@ -0,0 +1,22 @@
1
+ # Mettric
2
+
3
+ Track to riemann.
4
+
5
+ ## Configuration
6
+
7
+ ```ruby
8
+ Mettric.config = {
9
+ host: 'my-riemann-server',
10
+ port: 5555,
11
+
12
+ reporting_host: 'override' # Defaults to system hostname
13
+ app: 'my_app' # Defaults to rails app (if in rails)
14
+ poll_intervall: 100 # Defaults to 50ms
15
+ }
16
+ ```
17
+
18
+ ## Track metrics
19
+
20
+ ```ruby
21
+ 🌡 service: 'Rails req/s', metric: 400, state: 'normal'
22
+ ```
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mettric"
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
@@ -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,10 @@
1
+ require 'bundler'
2
+ Bundler.require
3
+
4
+ require 'mettric/version'
5
+ require 'mettric/errors'
6
+ require 'mettric/client'
7
+ require 'mettric/worker'
8
+ require 'mettric/mettric'
9
+ require 'mettric/thermometer'
10
+
@@ -0,0 +1,73 @@
1
+ require 'active_support/inflector'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'riemann/client'
5
+
6
+ class Mettric::Client
7
+ attr_reader :app, :host
8
+
9
+ def initialize(config = ::Mettric.config)
10
+ @config = config || {}
11
+ @riemann = Riemann::Client.new(
12
+ host: @config[:host] || 'localhost',
13
+ port: @config[:port] || 5555,
14
+ timeout: @config[:timeout] || 5
15
+ )
16
+
17
+ self.app = (@config[:app] || rails_app_name).to_s.underscore
18
+ self.host = (@config[:reporting_host] || host_name).to_s.underscore
19
+
20
+
21
+ if block_given?
22
+ begin
23
+ yield self
24
+ ensure
25
+ close
26
+ end
27
+ end
28
+ end
29
+
30
+ def app=(app_name)
31
+ raise Mettric::MissingAppName, app.inspect if app_name.blank?
32
+ @app = app_name
33
+ end
34
+
35
+ def host=(host_name)
36
+ raise Mettric::MissingHostName if host_name.blank?
37
+ @host = host_name
38
+ end
39
+
40
+ def <<(payload)
41
+ @riemann.tcp << standardize_payload(payload)
42
+ end
43
+
44
+ def [](*args)
45
+ @riemann[*args]
46
+ end
47
+
48
+ def close
49
+ @riemann.close
50
+ end
51
+
52
+ def connected?
53
+ @riemann.connected?
54
+ end
55
+
56
+ private
57
+
58
+ def standardize_payload(payload)
59
+ out = payload.symbolize_keys
60
+ out[:host] = host
61
+ out[:service] = "#{app}.#{out[:service]}"
62
+ out
63
+ end
64
+
65
+ def rails_app_name
66
+ return unless Kernel.const_defined?(:Rails)
67
+ Rails.application.class.parent.to_s.underscore
68
+ end
69
+
70
+ def host_name
71
+ (ENV['METTRIC_REPORTING_HOST'] || `hostname`).to_s.chomp.underscore
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ class Mettric::CouldNotStartWorkerThread < StandardError; end
2
+ class Mettric::MissingAppName < StandardError; end
3
+ class Mettric::MissingHostName < StandardError; end
@@ -0,0 +1,46 @@
1
+ class Mettric
2
+ QUEUE = Queue.new
3
+ LOCK = Mutex.new
4
+
5
+ def self.config
6
+ @config
7
+ end
8
+
9
+ def self.config=(config)
10
+ config_test = Client.new(config)
11
+ config_test.close
12
+ @config = config
13
+ end
14
+
15
+ def self.track(payload)
16
+ ensure_worker_running
17
+ QUEUE << payload
18
+ end
19
+
20
+ def self.ensure_worker_running
21
+ return if worker_running?
22
+ LOCK.synchronize do
23
+ return if worker_running?
24
+ start_worker
25
+ end
26
+ end
27
+
28
+ def self.worker_running?
29
+ @worker_thread and @worker_thread.alive?
30
+ end
31
+
32
+ def self.start_worker
33
+ exception = nil
34
+ worker = Mettric::Worker.new(QUEUE, @config)
35
+ @worker_thread = Thread.new do
36
+ begin
37
+ worker.start
38
+ rescue => e
39
+ exception = e
40
+ end
41
+ end
42
+ sleep 0.5
43
+ raise Mettric::CouldNotStartWorkerThread, exception unless @worker_thread.alive?
44
+ end
45
+ end
46
+
@@ -0,0 +1,4 @@
1
+ # SCNR
2
+ def 🌡 (payload)
3
+ Mettric.track(payload)
4
+ end
@@ -0,0 +1,3 @@
1
+ class Mettric
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,32 @@
1
+ class Mettric::Worker
2
+ def initialize(queue, config = Mettric.config)
3
+ @queue = queue
4
+ @config = config
5
+ @stop = false
6
+ @started = false
7
+ end
8
+
9
+ def start
10
+ return false if @started
11
+ @started = true
12
+ loop
13
+ end
14
+
15
+ def loop
16
+ Mettric::Client.new(@config) do |client|
17
+ while payload = @queue.pop
18
+ deliver(client, payload)
19
+ end
20
+ end
21
+ end
22
+
23
+ def stop
24
+ @started = false
25
+ end
26
+
27
+ private
28
+
29
+ def deliver(client, payload)
30
+ client << payload
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mettric/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mettric"
8
+ spec.version = Mettric::VERSION
9
+ spec.authors = ["Jannis Hermanns"]
10
+ spec.email = ["jannis@moviepilot.com"]
11
+
12
+ spec.summary = %q{Count metrics}
13
+ spec.description = %q{Mittwoch ist Metttag}
14
+ spec.homepage = "https://github.com/moviepilot/mettric"
15
+ spec.license = "All rights reserved"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "activesupport"
23
+ spec.add_dependency "riemann-client", "~> 0.2.6"
24
+
25
+ spec.add_development_dependency "pry"
26
+ spec.add_development_dependency "bundler", "~> 1.12"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "coveralls"
31
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mettric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jannis Hermanns
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
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: riemann-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.2.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Mittwoch ist Metttag
126
+ email:
127
+ - jannis@moviepilot.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CODE_OF_CONDUCT.md
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/mettric.rb
144
+ - lib/mettric/client.rb
145
+ - lib/mettric/errors.rb
146
+ - lib/mettric/mettric.rb
147
+ - lib/mettric/thermometer.rb
148
+ - lib/mettric/version.rb
149
+ - lib/mettric/worker.rb
150
+ - mettric.gemspec
151
+ homepage: https://github.com/moviepilot/mettric
152
+ licenses:
153
+ - All rights reserved
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.1
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Count metrics
175
+ test_files: []
176
+ has_rdoc: