logstash-output-graphite 0.1.7 → 0.1.8
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.
- checksums.yaml +4 -4
- data/logstash-output-graphite.gemspec +1 -1
- data/spec/outputs/graphite_spec.rb +85 -225
- data/spec/spec_helper.rb +8 -0
- data/spec/support/server.rb +7 -19
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6d50a691df186d1f6b3c9a19c496308afe70d39
|
4
|
+
data.tar.gz: 8e734363fe5ecca3ab719235691b2a1d0e6c3bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b83527c9bc1003809fd2e99a942a24e3317c336bec19a8e4a9ca178fa5fac84ebb45474f10b9c25a3c1dc5985c554e9f32789f845ec3e400cc8f939c92365515
|
7
|
+
data.tar.gz: 76b8223c213425a7ca8628f2ae1c77f2652841b463392b12f25392cdf1250bf4de3f2105065333ae1e66f84fa996fa21487fe4bb2e8c620bf04466b33bcc740d
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-output-graphite'
|
4
|
-
s.version = '0.1.
|
4
|
+
s.version = '0.1.8'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
6
|
s.summary = "This output allows you to pull metrics from your logs and ship them to Graphite"
|
7
7
|
s.description = "This gem is a logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program"
|
@@ -3,208 +3,107 @@ require_relative '../spec_helper'
|
|
3
3
|
describe LogStash::Outputs::Graphite do
|
4
4
|
|
5
5
|
let(:port) { 4939 }
|
6
|
-
let(:
|
7
|
-
input {
|
8
|
-
generator {
|
9
|
-
message => "foo=fancy bar=42"
|
10
|
-
count => 1
|
11
|
-
type => "generator"
|
12
|
-
}
|
13
|
-
}
|
14
|
-
|
15
|
-
filter {
|
16
|
-
kv { }
|
17
|
-
}
|
18
|
-
|
19
|
-
output {
|
20
|
-
graphite {
|
21
|
-
host => "localhost"
|
22
|
-
port => #{port}
|
23
|
-
metrics => [ "hurray.%{foo}", "%{bar}" ]
|
24
|
-
}
|
25
|
-
}
|
26
|
-
CONFIG
|
27
|
-
end
|
28
|
-
|
29
|
-
let(:pipeline) { LogStash::Pipeline.new(config) }
|
30
|
-
let(:server) { Mocks::Server.new(port) }
|
6
|
+
let(:server) { subject.socket }
|
31
7
|
|
32
|
-
before do
|
33
|
-
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
after do
|
38
|
-
server.stop
|
8
|
+
before :each do
|
9
|
+
subject.register
|
10
|
+
subject.receive(event)
|
39
11
|
end
|
40
12
|
|
41
13
|
context "with a default run" do
|
42
14
|
|
15
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost", "port" => port, "metrics" => [ "hurray.%{foo}", "%{bar}" ]) }
|
16
|
+
let(:event) { LogStash::Event.new("foo" => "fancy", "bar" => 42) }
|
17
|
+
|
43
18
|
it "generate one element" do
|
44
19
|
expect(server.size).to eq(1)
|
45
20
|
end
|
46
21
|
|
47
22
|
it "include all metrics" do
|
48
|
-
|
49
|
-
expect(
|
23
|
+
line = server.pop
|
24
|
+
expect(line).to match(/^hurray.fancy 42.0 \d{10,}\n$/)
|
50
25
|
end
|
51
|
-
|
52
26
|
end
|
53
27
|
|
54
28
|
context "if fields_are_metrics => true" do
|
55
29
|
context "when metrics_format => ..." do
|
30
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
31
|
+
"port" => port,
|
32
|
+
"fields_are_metrics" => true,
|
33
|
+
"include_metrics" => ["foo"],
|
34
|
+
"metrics_format" => "foo.bar.sys.data.*") }
|
56
35
|
|
57
|
-
|
58
|
-
let(:config) do <<-CONFIG
|
59
|
-
input {
|
60
|
-
generator {
|
61
|
-
message => "foo=123"
|
62
|
-
count => 1
|
63
|
-
type => "generator"
|
64
|
-
}
|
65
|
-
}
|
66
|
-
|
67
|
-
filter {
|
68
|
-
kv { }
|
69
|
-
}
|
70
|
-
|
71
|
-
output {
|
72
|
-
graphite {
|
73
|
-
host => "localhost"
|
74
|
-
port => #{port}
|
75
|
-
fields_are_metrics => true
|
76
|
-
include_metrics => ["foo"]
|
77
|
-
metrics_format => "foo.bar.sys.data.*"
|
78
|
-
debug => true
|
79
|
-
}
|
80
|
-
}
|
81
|
-
CONFIG
|
82
|
-
end
|
36
|
+
let(:event) { LogStash::Event.new("foo" => "123") }
|
83
37
|
|
38
|
+
context "match one key" do
|
84
39
|
it "generate one element" do
|
85
40
|
expect(server.size).to eq(1)
|
86
41
|
end
|
87
42
|
|
88
43
|
it "match the generated key" do
|
89
|
-
|
90
|
-
expect(
|
44
|
+
line = server.pop
|
45
|
+
expect(line).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
|
91
46
|
end
|
92
|
-
|
93
47
|
end
|
48
|
+
end
|
94
49
|
|
95
|
-
|
96
|
-
|
97
|
-
let(:config) do <<-CONFIG
|
98
|
-
input {
|
99
|
-
generator {
|
100
|
-
message => "foo=123 bar=42"
|
101
|
-
count => 1
|
102
|
-
type => "generator"
|
103
|
-
}
|
104
|
-
}
|
105
|
-
|
106
|
-
filter {
|
107
|
-
kv { }
|
108
|
-
}
|
109
|
-
|
110
|
-
output {
|
111
|
-
graphite {
|
112
|
-
host => "localhost"
|
113
|
-
port => #{port}
|
114
|
-
fields_are_metrics => true
|
115
|
-
include_metrics => [".*"]
|
116
|
-
metrics_format => "foo.bar.sys.data.*"
|
117
|
-
debug => true
|
118
|
-
}
|
119
|
-
}
|
120
|
-
CONFIG
|
121
|
-
end
|
50
|
+
context "match all keys" do
|
122
51
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
dict[key] = line
|
129
|
-
end
|
130
|
-
dict
|
131
|
-
end
|
52
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
53
|
+
"port" => port,
|
54
|
+
"fields_are_metrics" => true,
|
55
|
+
"include_metrics" => [".*"],
|
56
|
+
"metrics_format" => "foo.bar.sys.data.*") }
|
132
57
|
|
133
|
-
|
134
|
-
expect(lines['foo.bar.sys.data.foo']).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
|
135
|
-
end
|
58
|
+
let(:event) { LogStash::Event.new("foo" => "123", "bar" => "42") }
|
136
59
|
|
137
|
-
|
138
|
-
|
60
|
+
let(:lines) do
|
61
|
+
dict = {}
|
62
|
+
while(!server.empty?)
|
63
|
+
line = server.pop
|
64
|
+
key = line.split(' ')[0]
|
65
|
+
dict[key] = line
|
139
66
|
end
|
67
|
+
dict
|
68
|
+
end
|
140
69
|
|
70
|
+
it "match the generated foo key" do
|
71
|
+
expect(lines['foo.bar.sys.data.foo']).to match(/^foo.bar.sys.data.foo 123.0 \d{10,}\n$/)
|
141
72
|
end
|
142
73
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
generator {
|
148
|
-
message => "foo=123 bar=42"
|
149
|
-
count => 1
|
150
|
-
type => "generator"
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
filter {
|
155
|
-
kv { }
|
156
|
-
}
|
157
|
-
|
158
|
-
output {
|
159
|
-
graphite {
|
160
|
-
host => "localhost"
|
161
|
-
port => #{port}
|
162
|
-
fields_are_metrics => true
|
163
|
-
include_metrics => ["notmatchinganything"]
|
164
|
-
metrics_format => "foo.bar.sys.data.*"
|
165
|
-
debug => true
|
166
|
-
}
|
167
|
-
}
|
168
|
-
CONFIG
|
169
|
-
end
|
74
|
+
it "match the generated bar key" do
|
75
|
+
expect(lines['foo.bar.sys.data.bar']).to match(/^foo.bar.sys.data.bar 42.0 \d{10,}\n$/)
|
76
|
+
end
|
77
|
+
end
|
170
78
|
|
171
|
-
|
172
|
-
|
173
|
-
|
79
|
+
context "no match" do
|
80
|
+
|
81
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
82
|
+
"port" => port,
|
83
|
+
"fields_are_metrics" => true,
|
84
|
+
"include_metrics" => ["notmatchinganything"],
|
85
|
+
"metrics_format" => "foo.bar.sys.data.*") }
|
86
|
+
|
87
|
+
let(:event) { LogStash::Event.new("foo" => "123", "bar" => "42") }
|
88
|
+
|
89
|
+
it "generate no event" do
|
90
|
+
expect(server.empty?).to eq(true)
|
174
91
|
end
|
92
|
+
end
|
175
93
|
|
176
|
-
|
177
|
-
|
178
|
-
let(:config) do <<-CONFIG
|
179
|
-
input {
|
180
|
-
generator {
|
181
|
-
message => "foo=123"
|
182
|
-
count => 1
|
183
|
-
type => "generator"
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
|
-
filter {
|
188
|
-
kv { }
|
189
|
-
}
|
190
|
-
|
191
|
-
output {
|
192
|
-
graphite {
|
193
|
-
host => "localhost"
|
194
|
-
port => #{port}
|
195
|
-
fields_are_metrics => true
|
196
|
-
include_metrics => ["foo"]
|
197
|
-
metrics_format => "invalidformat"
|
198
|
-
debug => true
|
199
|
-
}
|
200
|
-
}
|
201
|
-
CONFIG
|
202
|
-
end
|
94
|
+
context "match a key with invalid metric_format" do
|
203
95
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
96
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
97
|
+
"port" => port,
|
98
|
+
"fields_are_metrics" => true,
|
99
|
+
"include_metrics" => ["foo"],
|
100
|
+
"metrics_format" => "invalidformat") }
|
101
|
+
|
102
|
+
let(:event) { LogStash::Event.new("foo" => "123") }
|
103
|
+
|
104
|
+
it "match the foo key" do
|
105
|
+
line = server.pop
|
106
|
+
expect(line).to match(/^foo 123.0 \d{10,}\n$/)
|
208
107
|
end
|
209
108
|
end
|
210
109
|
end
|
@@ -213,75 +112,36 @@ describe LogStash::Outputs::Graphite do
|
|
213
112
|
context "metrics_format not set" do
|
214
113
|
context "match one key with metrics list" do
|
215
114
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
}
|
224
|
-
|
225
|
-
filter {
|
226
|
-
kv { }
|
227
|
-
}
|
228
|
-
|
229
|
-
output {
|
230
|
-
graphite {
|
231
|
-
host => "localhost"
|
232
|
-
port => #{port}
|
233
|
-
fields_are_metrics => false
|
234
|
-
include_metrics => ["foo"]
|
235
|
-
metrics => [ "custom.foo", "%{foo}" ]
|
236
|
-
debug => true
|
237
|
-
}
|
238
|
-
}
|
239
|
-
CONFIG
|
240
|
-
end
|
115
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
116
|
+
"port" => port,
|
117
|
+
"fields_are_metrics" => false,
|
118
|
+
"include_metrics" => ["foo"],
|
119
|
+
"metrics" => [ "custom.foo", "%{foo}" ]) }
|
120
|
+
|
121
|
+
let(:event) { LogStash::Event.new("foo" => "123") }
|
241
122
|
|
242
123
|
it "match the custom.foo key" do
|
243
|
-
|
244
|
-
expect(
|
124
|
+
line = server.pop
|
125
|
+
expect(line).to match(/^custom.foo 123.0 \d{10,}\n$/)
|
245
126
|
end
|
246
|
-
|
247
127
|
end
|
248
128
|
end
|
249
129
|
end
|
250
130
|
|
251
131
|
context "timestamp_field used is timestamp_new" do
|
252
|
-
|
253
|
-
let(:
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
filter {
|
263
|
-
ruby {
|
264
|
-
code => "event['timestamp_new'] = Time.at(#{timestamp_new})"
|
265
|
-
}
|
266
|
-
}
|
267
|
-
|
268
|
-
output {
|
269
|
-
graphite {
|
270
|
-
host => "localhost"
|
271
|
-
port => #{port}
|
272
|
-
timestamp_field => "timestamp_new"
|
273
|
-
metrics => ["foo", "1"]
|
274
|
-
debug => true
|
275
|
-
}
|
276
|
-
}
|
277
|
-
CONFIG
|
278
|
-
end
|
132
|
+
|
133
|
+
let(:timestamp_new) { (Time.now + 3).to_i }
|
134
|
+
|
135
|
+
subject { LogStash::Outputs::Graphite.new("host" => "localhost",
|
136
|
+
"port" => port,
|
137
|
+
"timestamp_field" => "timestamp_new",
|
138
|
+
"metrics" => ["foo", "1"]) }
|
139
|
+
|
140
|
+
let(:event) { LogStash::Event.new("foo" => "123", "timestamp_new" => timestamp_new) }
|
279
141
|
|
280
142
|
it "timestamp matches timestamp_new" do
|
281
|
-
|
282
|
-
expect(
|
143
|
+
line = server.pop
|
144
|
+
expect(line).to match(/^foo 1.0 #{timestamp_new}\n$/)
|
283
145
|
end
|
284
|
-
|
285
146
|
end
|
286
|
-
|
287
147
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/support/server.rb
CHANGED
@@ -1,24 +1,8 @@
|
|
1
1
|
module Mocks
|
2
2
|
class Server
|
3
3
|
|
4
|
-
def initialize
|
5
|
-
@queue =
|
6
|
-
@port = port
|
7
|
-
end
|
8
|
-
|
9
|
-
def start
|
10
|
-
@server = TCPServer.new("127.0.0.1", @port)
|
11
|
-
@queue.clear
|
12
|
-
Thread.new do
|
13
|
-
client = @server.accept
|
14
|
-
while true
|
15
|
-
if !client.eof?
|
16
|
-
line = client.readline
|
17
|
-
@queue << line
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
self
|
4
|
+
def initialize
|
5
|
+
@queue = Array.new
|
22
6
|
end
|
23
7
|
|
24
8
|
def size
|
@@ -30,12 +14,16 @@ module Mocks
|
|
30
14
|
end
|
31
15
|
|
32
16
|
def stop
|
33
|
-
@server.close
|
34
17
|
end
|
35
18
|
|
36
19
|
def empty?
|
37
20
|
@queue.empty?
|
38
21
|
end
|
39
22
|
|
23
|
+
def puts(data)
|
24
|
+
data.split("\n").each do |line|
|
25
|
+
@queue << "#{line}\n"
|
26
|
+
end
|
27
|
+
end
|
40
28
|
end
|
41
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-graphite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Elastic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.4.5
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: This output allows you to pull metrics from your logs and ship them to Graphite
|