librato-logreporter 0.1.0 → 0.2.0
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/CHANGELOG.md +3 -0
- data/README.md +4 -2
- data/lib/librato/logreporter/version.rb +1 -1
- data/lib/librato/logreporter.rb +5 -4
- data/test/unit/logreporter_test.rb +13 -13
- metadata +5 -5
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
librato-logreporter
|
2
2
|
=======
|
3
3
|
|
4
|
-
[](http://travis-ci.org/librato/librato-logreporter) [](https://codeclimate.com/github/librato/librato-logreporter)
|
4
|
+
[](http://badge.fury.io/rb/librato-logreporter) [](http://travis-ci.org/librato/librato-logreporter) [](https://codeclimate.com/github/librato/librato-logreporter)
|
5
5
|
|
6
6
|
NOTE: This library is in active development and is suggested for early-adopter use only.
|
7
7
|
|
8
8
|
`librato-logreporter` provides an easy interface to write metrics ultimately bound for [Librato Metrics](https://metrics.librato.com/) to your logs or another IO stream. It is fully format-compliant with [l2met](https://github.com/ryandotsmith/l2met). If you are running on Heroku it will allow you to easily insert metrics which can be retrieved via a [log drain](https://devcenter.heroku.com/articles/logging#syslog-drains).
|
9
9
|
|
10
|
+
NOTE: Current versions of this library use the [logging conventions](https://github.com/ryandotsmith/l2met/wiki/Usage) established in l2met 2.0 and greater. For use with [older versions](https://github.com/ryandotsmith/l2met/wiki/Usage) of l2met, use v0.1 of this gem.
|
11
|
+
|
10
12
|
This library is ideally suited for custom or short-lived processes where the overhead of in-process collection will be costly and external metric collectors are unavailable.
|
11
13
|
|
12
14
|
If you are considering using `librato-logreporter` for a rails or rack-based web app, first explore [librato-rails](https://github.com/librato/librato-rails) and/or [librato-rack](https://github.com/librato/librato-rack). In most cases one of these libraries will be a better solution for your web applications.
|
@@ -53,7 +55,7 @@ If you don't have a [Librato Metrics](https://metrics.librato.com/) account alre
|
|
53
55
|
There are a few optional environment variables you may find useful:
|
54
56
|
|
55
57
|
* `LIBRATO_SOURCE` - the default source to use for submitted metrics. If not set your metrics will be submitted without a source.
|
56
|
-
* `LIBRATO_PREFIX` - a prefix which will be
|
58
|
+
* `LIBRATO_PREFIX` - a prefix which will be prepended to all metric names
|
57
59
|
|
58
60
|
##### Running on Heroku
|
59
61
|
|
data/lib/librato/logreporter.rb
CHANGED
@@ -44,7 +44,7 @@ module Librato
|
|
44
44
|
#
|
45
45
|
def increment(counter, options={})
|
46
46
|
by = options[:by] || 1
|
47
|
-
log_write(counter => by, :source => options[:source])
|
47
|
+
log_write(counter => by, :l2met_type => 'count', :source => options[:source])
|
48
48
|
end
|
49
49
|
|
50
50
|
# @example Simple measurement
|
@@ -91,7 +91,8 @@ module Librato
|
|
91
91
|
|
92
92
|
# take key/value pairs and return an array of measure strings
|
93
93
|
def add_prefixes(measures)
|
94
|
-
|
94
|
+
type = measures.delete(:l2met_type) || 'measure'
|
95
|
+
measure_prefix = type << '#'
|
95
96
|
measure_prefix << "#{prefix}." if prefix
|
96
97
|
measures.map { |keyval|
|
97
98
|
joined = keyval.join('=')
|
@@ -114,8 +115,8 @@ module Librato
|
|
114
115
|
measures
|
115
116
|
end
|
116
117
|
|
117
|
-
def log_write(
|
118
|
-
measure_chunks = add_prefixes(manage_source(
|
118
|
+
def log_write(data)
|
119
|
+
measure_chunks = add_prefixes(manage_source(data))
|
119
120
|
log.puts measure_chunks.join(' ')
|
120
121
|
end
|
121
122
|
|
@@ -12,10 +12,10 @@ module Librato
|
|
12
12
|
|
13
13
|
def test_increment
|
14
14
|
@reporter.increment :foo
|
15
|
-
assert_last_logged '
|
15
|
+
assert_last_logged 'count#foo=1'
|
16
16
|
|
17
17
|
@reporter.increment 'foo.bar', :by => 2
|
18
|
-
assert_last_logged '
|
18
|
+
assert_last_logged 'count#foo.bar=2'
|
19
19
|
end
|
20
20
|
|
21
21
|
def test_increment_supports_source
|
@@ -23,20 +23,20 @@ module Librato
|
|
23
23
|
|
24
24
|
# default source
|
25
25
|
@reporter.increment 'days.foggy'
|
26
|
-
assert_last_logged '
|
26
|
+
assert_last_logged 'count#days.foggy=1 source=sf'
|
27
27
|
|
28
28
|
# custom source
|
29
29
|
@reporter.increment 'days.foggy', :source => 'seattle'
|
30
|
-
assert_last_logged '
|
30
|
+
assert_last_logged 'count#days.foggy=1 source=seattle'
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_measure
|
34
34
|
@reporter.measure 'documents.rendered', 12
|
35
|
-
assert_last_logged 'measure
|
35
|
+
assert_last_logged 'measure#documents.rendered=12'
|
36
36
|
|
37
37
|
# custom source
|
38
38
|
@reporter.measure 'cycles.wasted', 23, :source => 'cpu_1'
|
39
|
-
assert_last_logged 'measure
|
39
|
+
assert_last_logged 'measure#cycles.wasted=23 source=cpu_1'
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_timing
|
@@ -44,7 +44,7 @@ module Librato
|
|
44
44
|
last = last_logged
|
45
45
|
assert last =~ /\=/, 'should have a measure pair'
|
46
46
|
key, value = last.split('=')
|
47
|
-
assert_equal 'measure
|
47
|
+
assert_equal 'measure#do.stuff', key, 'should have timing key'
|
48
48
|
assert_in_delta 100, value.to_i, 10
|
49
49
|
|
50
50
|
# custom source
|
@@ -64,9 +64,9 @@ module Librato
|
|
64
64
|
|
65
65
|
@buffer.rewind
|
66
66
|
lines = @buffer.readlines
|
67
|
-
assert_equal '
|
68
|
-
assert_equal 'measure
|
69
|
-
assert_equal '
|
67
|
+
assert_equal 'count#pages.total=1', lines[0].chomp
|
68
|
+
assert_equal 'measure#pages.render_time=63', lines[1].chomp
|
69
|
+
assert_equal 'count#pages.public.views=2', lines[2].chomp
|
70
70
|
end
|
71
71
|
|
72
72
|
def test_custom_prefix
|
@@ -74,17 +74,17 @@ module Librato
|
|
74
74
|
|
75
75
|
# increment
|
76
76
|
@reporter.increment 'views'
|
77
|
-
assert_last_logged '
|
77
|
+
assert_last_logged 'count#librato.views=1'
|
78
78
|
|
79
79
|
# measure/timing
|
80
80
|
@reporter.measure 'sql.queries', 6
|
81
|
-
assert_last_logged 'measure
|
81
|
+
assert_last_logged 'measure#librato.sql.queries=6'
|
82
82
|
|
83
83
|
# group
|
84
84
|
@reporter.group :private do |priv|
|
85
85
|
priv.increment 'secret'
|
86
86
|
end
|
87
|
-
assert_last_logged '
|
87
|
+
assert_last_logged 'count#librato.private.secret=1'
|
88
88
|
end
|
89
89
|
|
90
90
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librato-logreporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: minitest
|
@@ -62,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
62
|
version: '0'
|
63
63
|
segments:
|
64
64
|
- 0
|
65
|
-
hash:
|
65
|
+
hash: 2388961816210600874
|
66
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
@@ -71,10 +71,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
71
|
version: '0'
|
72
72
|
segments:
|
73
73
|
- 0
|
74
|
-
hash:
|
74
|
+
hash: 2388961816210600874
|
75
75
|
requirements: []
|
76
76
|
rubyforge_project:
|
77
|
-
rubygems_version: 1.8.
|
77
|
+
rubygems_version: 1.8.23
|
78
78
|
signing_key:
|
79
79
|
specification_version: 3
|
80
80
|
summary: Write Librato metrics to your logs with a convenient interface
|