carbonator 0.0.1

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.
data/.gitignore ADDED
@@ -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
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carbinator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 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.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Carbonator
2
+
3
+ [![Build Status](https://secure.travis-ci.org/gorsuch/carbonator.png)](http://travis-ci.org/gorsuch/carbonator)
4
+
5
+ Carbonator is a simple toolkit for transforming `key=value` text streams into Carbon compatable inputs.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'carbonator'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install carbonator
20
+
21
+ ## Usage
22
+
23
+ ```bash
24
+ $ echo base=foo a=1 b=2 c=3 | carbonator
25
+ foo.a 1
26
+ foo.b 2
27
+ foo.c 3
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/bin/carbonator ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'carbonator'
4
+
5
+ Carbonator::CLI.new.run
@@ -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 'carbonator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "carbonator"
8
+ gem.version = Carbonator::VERSION
9
+ gem.authors = ["Michael Gorsuch"]
10
+ gem.email = ["michael.gorsuch@gmail.com"]
11
+ gem.description = %q{A simple toolkit for transforming key=value text streams into Carbon compatable inputs.}
12
+ gem.summary = gem.description
13
+ gem.homepage = 'https://github.com/gorsuch/carbonator'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_development_dependency('rake')
20
+ gem.add_development_dependency('rspec')
21
+ gem.add_dependency('kv')
22
+ end
@@ -0,0 +1,16 @@
1
+ module Carbonator
2
+ class CLI
3
+ attr_reader :parser
4
+
5
+ def initialize
6
+ @parser = Parser.new
7
+ end
8
+
9
+ def run
10
+ ARGF.each_line do |l|
11
+ data = KV.parse(l)
12
+ parser.parse(data).each { |x| puts x }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Carbonator
2
+ class Parser
3
+ def metricname(data, k, opts)
4
+ base_key = opts[:base_key] || 'base'
5
+ base = data[base_key] || 'carbinator'
6
+
7
+ name = [base, k].join('.')
8
+
9
+ prefix = opts[:prefix]
10
+ prefix ? "#{prefix}.#{name}" : name
11
+ end
12
+
13
+ def filter_numeric(data)
14
+ data.select { |k,v| v.kind_of?(Numeric) }
15
+ end
16
+
17
+ def parse(data, opts={})
18
+ base_key = opts[:base_key] || 'base'
19
+ base = data[base_key]
20
+
21
+ filter_numeric(data).map do |k,v|
22
+ "#{metricname(data, k, opts)} #{v}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Carbonator
2
+ VERSION = "0.0.1"
3
+ end
data/lib/carbonator.rb ADDED
@@ -0,0 +1,7 @@
1
+ STDOUT.sync = true
2
+
3
+ require 'kv'
4
+
5
+ require 'carbonator/cli'
6
+ require 'carbonator/parser'
7
+ require 'carbonator/version'
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Carbonator::Parser do
4
+ let(:data) { {'base' => 'foo', 'http_code' => 200, 'connect_time' => 0.2} }
5
+ let(:parser) { Carbonator::Parser.new }
6
+
7
+ describe '#parse' do
8
+ it 'it should return an array' do
9
+ parser.parse(data).should be_kind_of(Array)
10
+ end
11
+
12
+ it 'should handle a simple dataset' do
13
+ parser.parse(data).should eq(['foo.http_code 200', 'foo.connect_time 0.2'])
14
+ end
15
+
16
+ it 'should prefix the data if asked' do
17
+ parser.parse(data, :prefix => 'test').should eq(['test.foo.http_code 200', 'test.foo.connect_time 0.2'])
18
+ end
19
+
20
+ it 'should use a different base name if asked' do
21
+ expected = ['other.http_code 200', 'other.connect_time 0.2']
22
+ parser.parse(data.merge('alt' => 'other'), :base_key => 'alt').should eq(expected)
23
+ end
24
+
25
+ it 'substitutes a default base if one is not provided' do
26
+ expected = ['carbinator.http_code 200']
27
+ parser.parse({'http_code' => 200}).should eq(expected)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,8 @@
1
+ require 'carbonator'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carbonator
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: 2012-09-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70243807250980 !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: *70243807250980
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70243807250360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70243807250360
36
+ - !ruby/object:Gem::Dependency
37
+ name: kv
38
+ requirement: &70243807249700 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70243807249700
47
+ description: A simple toolkit for transforming key=value text streams into Carbon
48
+ compatable inputs.
49
+ email:
50
+ - michael.gorsuch@gmail.com
51
+ executables:
52
+ - carbonator
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - Gemfile
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - bin/carbonator
63
+ - carbonator.gemspec
64
+ - lib/carbonator.rb
65
+ - lib/carbonator/cli.rb
66
+ - lib/carbonator/parser.rb
67
+ - lib/carbonator/version.rb
68
+ - spec/carbonator/parser_spec.rb
69
+ - spec/spec_helper.rb
70
+ homepage: https://github.com/gorsuch/carbonator
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: -2170040801361934229
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ segments:
92
+ - 0
93
+ hash: -2170040801361934229
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.10
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: A simple toolkit for transforming key=value text streams into Carbon compatable
100
+ inputs.
101
+ test_files:
102
+ - spec/carbonator/parser_spec.rb
103
+ - spec/spec_helper.rb