formatted-metrics 0.2.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a34c6fd59ded3203162150ac1f63aa982c750da9
4
+ data.tar.gz: 68cb58c7cf99c4d777e38ea70916442ab74205f5
5
+ SHA512:
6
+ metadata.gz: f162ebda0be8a2939a314530fe828c279a18941a7d7a2cbb3db660f13e00406d6e511143bba9574e58b9b602a5fe4760ce552ff8108a25dbc47fdd900d30a567
7
+ data.tar.gz: 4c8114e6f9b1ca5c2dc3491b871f2148c58ba2546cdb554352db94495fa093c04e20d24f9ef173e48fa7c88f075b1dfe3557b523ae1682044fd7562856e77676
@@ -1,10 +1,14 @@
1
1
  module Metrics::Formatters
2
+ PRECISION = 3
3
+
2
4
  class L2Met < Base
5
+ # Example
6
+ # source=web.2 sample#load_avg_1m=0.31 sample#load_avg_5m=0.10 sample#load_avg_15m=0.05
3
7
  def lines
4
8
  groups.map do |source, instrumenters|
5
9
  [
6
10
  "source=#{full_source(source)}",
7
- instrumenters.map { |instrumenter| "measure.#{instrumenter.metric}=#{instrumenter.value}#{instrumenter.units}" }.join(' ')
11
+ instrumenters.map { |instrumenter| measurement(instrumenter) }.join(' ')
8
12
  ].flatten.join(' ')
9
13
  end
10
14
  end
@@ -24,5 +28,11 @@ module Metrics::Formatters
24
28
  configuration.source
25
29
  end
26
30
  end
31
+
32
+ def measurement(instrumenter)
33
+ value = instrumenter.value
34
+ value = value.round(PRECISION) if value.is_a?(Float)
35
+ "#{instrumenter.type}##{instrumenter.metric}=#{value}#{instrumenter.units}"
36
+ end
27
37
  end
28
38
  end
@@ -1,7 +1,11 @@
1
1
  module Metrics
2
2
  # Public: Responsible for sampling a measurement of something.
3
3
  #
4
- # metric - The name of the metric to measure (e.g. rack.request.time)
4
+ # metric - The name of the metric to measure (e.g. rack.request.time)
5
+ # options - Hash of options (default: {}):
6
+ # unit: Unit of measurement [ms, MB, GB, ...] (optional)
7
+ # type: Method type of the measurement [measure, sample, count]
8
+ # (optional, default: measure)
5
9
  #
6
10
  # Returns a new Metrics::Instrumenter.
7
11
  class Instrumenter
@@ -34,6 +38,10 @@ module Metrics
34
38
  timing? ? TIME_UNITS : options[:units]
35
39
  end
36
40
 
41
+ def type
42
+ options[:type] || 'measure'
43
+ end
44
+
37
45
  def source
38
46
  options[:source]
39
47
  end
@@ -1,3 +1,3 @@
1
1
  module FormattedMetrics
2
- VERSION = '0.2.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -8,15 +8,15 @@ describe Metrics::Formatters::L2Met do
8
8
  end
9
9
 
10
10
  def instrumenter(values)
11
- double Metrics::Instrumenter, { source: nil }.merge(values)
11
+ double Metrics::Instrumenter, { source: nil, type: 'measure' }.merge(values)
12
12
  end
13
13
 
14
14
  describe '.lines' do
15
15
  subject(:format) { formatter.lines }
16
16
 
17
17
  context 'with a single instrumenter' do
18
- let(:instrumenters) { [ instrumenter(metric: 'rack.request.time', value: 10, units: 'ms') ] }
19
- it { should eq ['source=app measure.rack.request.time=10ms'] }
18
+ let(:instrumenters) { [ instrumenter(metric: 'rack.request.time', value: 10.3333, units: 'ms', type: 'sample') ] }
19
+ it { should eq ['source=app sample#rack.request.time=10.333ms'] }
20
20
  end
21
21
 
22
22
  context 'with multiple instrumenters' do
@@ -25,17 +25,17 @@ describe Metrics::Formatters::L2Met do
25
25
  instrumenter(metric: 'jobs.busy', value: 10, units: 'jobs') ]
26
26
  end
27
27
 
28
- it { should eq ['source=app measure.rack.request.time=10ms measure.jobs.busy=10jobs'] }
28
+ it { should eq ['source=app measure#rack.request.time=10ms measure#jobs.busy=10jobs'] }
29
29
  end
30
30
 
31
31
  context 'with multiple metrics from different sources' do
32
32
  let(:instrumenters) do
33
- [ instrumenter(metric: 'rack.request.time', value: 10, units: 'ms'),
34
- instrumenter(metric: 'jobs.queued', value: 15, units: 'jobs', source: 'foo'),
35
- instrumenter(metric: 'jobs.busy', value: 10, units: 'jobs', source: 'foo') ]
33
+ [ instrumenter(metric: 'rack.request.time', value: 10, units: 'ms', type: 'sample'),
34
+ instrumenter(metric: 'jobs.queued', value: 15, units: 'jobs', source: 'foo', type: 'count'),
35
+ instrumenter(metric: 'jobs.busy', value: 10, units: 'jobs', source: 'foo', type: 'count') ]
36
36
  end
37
37
 
38
- it { should eq ['source=app measure.rack.request.time=10ms', 'source=app.foo measure.jobs.queued=15jobs measure.jobs.busy=10jobs'] }
38
+ it { should eq ['source=app sample#rack.request.time=10ms', 'source=app.foo count#jobs.queued=15jobs count#jobs.busy=10jobs'] }
39
39
  end
40
40
  end
41
41
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatted-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Eric J. Holmes
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-08 00:00:00.000000000 Z
11
+ date: 2013-09-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,23 +27,20 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -96,33 +89,26 @@ files:
96
89
  homepage: http://github.com/remind101/formatted-metrics
97
90
  licenses:
98
91
  - MIT
92
+ metadata: {}
99
93
  post_install_message:
100
94
  rdoc_options: []
101
95
  require_paths:
102
96
  - lib
103
97
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
98
  requirements:
106
- - - ! '>='
99
+ - - '>='
107
100
  - !ruby/object:Gem::Version
108
101
  version: '0'
109
- segments:
110
- - 0
111
- hash: 147122982979217444
112
102
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
103
  requirements:
115
- - - ! '>='
104
+ - - '>='
116
105
  - !ruby/object:Gem::Version
117
106
  version: '0'
118
- segments:
119
- - 0
120
- hash: 147122982979217444
121
107
  requirements: []
122
108
  rubyforge_project:
123
- rubygems_version: 1.8.23
109
+ rubygems_version: 2.0.3
124
110
  signing_key:
125
- specification_version: 3
111
+ specification_version: 4
126
112
  summary: Easily output formatted metrics to stdout
127
113
  test_files:
128
114
  - spec/metrics/formatters/l2met_spec.rb