carbonator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +36 -0
- data/Rakefile +5 -0
- data/bin/carbonator +5 -0
- data/carbonator.gemspec +22 -0
- data/lib/carbonator/cli.rb +16 -0
- data/lib/carbonator/parser.rb +26 -0
- data/lib/carbonator/version.rb +3 -0
- data/lib/carbonator.rb +7 -0
- data/spec/carbonator/parser_spec.rb +30 -0
- data/spec/spec_helper.rb +8 -0
- metadata +103 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
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
|
+
[](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
data/bin/carbonator
ADDED
data/carbonator.gemspec
ADDED
@@ -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,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
|
data/lib/carbonator.rb
ADDED
@@ -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
|
data/spec/spec_helper.rb
ADDED
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
|