statsdeify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format specdoc
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statsdeify.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Gorsuch
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # statsdeify
2
+
3
+ An experimental lib to transmute structured logs to `statsd` measurements.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'statsdeify'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install statsdeify
18
+
19
+ ## Conventions
20
+
21
+ ### Gauges
22
+
23
+ Produce a log line that contains the following within it:
24
+
25
+ ```
26
+ measure=foo.bar value=1
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ writer = Statsdeify::Writer.new('udp://localhost:8125')
33
+ measurement = Statsdeify::Measurement.from_line('measure=foo.bar value=12345')
34
+ writer.puts(measurement)
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,6 @@
1
+ require 'socket'
2
+ require 'uri'
3
+
4
+ require 'statsdeify/measurement'
5
+ require 'statsdeify/version'
6
+ require 'statsdeify/writer'
@@ -0,0 +1,33 @@
1
+ module Statsdeify
2
+ class Measurement
3
+ REGEXP = Regexp.new(/(\S+)=(\S+)/)
4
+
5
+ attr_accessor :name, :value
6
+
7
+ def self.from_line(line)
8
+ h = hashify_line(line)
9
+ valid?(h) ? new(h['measure'], h['value']) : nil
10
+ end
11
+
12
+ def self.hashify_line(line)
13
+ line.scan(REGEXP).map do |x|
14
+ Hash[*x]
15
+ end.inject({}) do |h,x|
16
+ h.merge(x)
17
+ end
18
+ end
19
+
20
+ def self.valid?(h)
21
+ h.has_key?('measure') && h.has_key?('value')
22
+ end
23
+
24
+ def initialize(name, value)
25
+ self.name = name
26
+ self.value = value
27
+ end
28
+
29
+ def to_s
30
+ "#{name}:#{value}|g"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Statsdeify
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,22 @@
1
+ module Statsdeify
2
+ class Writer
3
+ attr_accessor :url
4
+
5
+ def initialize(url)
6
+ self.url = url
7
+ end
8
+
9
+ def socket
10
+ unless @socket
11
+ uri = URI.parse(url)
12
+ @socket = UDPSocket.new
13
+ @socket.connect(uri.host, uri.port)
14
+ end
15
+ @socket
16
+ end
17
+
18
+ def puts(measurement)
19
+ socket.write(measurement.to_s, 0)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'statsdeify'
@@ -0,0 +1,9 @@
1
+ describe Statsdeify do
2
+ it 'should have a version number' do
3
+ Statsdeify::VERSION.should_not be_nil
4
+ end
5
+
6
+ it 'should do something useful' do
7
+ false.should be_true
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statsdeify/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "statsdeify"
8
+ gem.version = Statsdeify::VERSION
9
+ gem.authors = ["Michael Gorsuch"]
10
+ gem.email = ["gorsuch@github.com"]
11
+ gem.description = %q{An experimental lib to transmute logs to `statsd` measurements.}
12
+ gem.summary = gem.description
13
+ gem.homepage = "https://github.com/gorsuch/statsdeify"
14
+ gem.license = "MIT"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "rake"
22
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statsdeify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Gorsuch
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: An experimental lib to transmute logs to `statsd` measurements.
31
+ email:
32
+ - gorsuch@github.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rspec
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/statsdeify.rb
44
+ - lib/statsdeify/measurement.rb
45
+ - lib/statsdeify/version.rb
46
+ - lib/statsdeify/writer.rb
47
+ - spec/spec_helper.rb
48
+ - spec/statsdeify_spec.rb
49
+ - statsdeify.gemspec
50
+ homepage: https://github.com/gorsuch/statsdeify
51
+ licenses:
52
+ - MIT
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ segments:
64
+ - 0
65
+ hash: -4527870241418967139
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ segments:
73
+ - 0
74
+ hash: -4527870241418967139
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.23
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: An experimental lib to transmute logs to `statsd` measurements.
81
+ test_files:
82
+ - spec/spec_helper.rb
83
+ - spec/statsdeify_spec.rb