monitoring_protocols 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/Gemfile +18 -0
- data/Guardfile +8 -0
- data/LICENSE +22 -0
- data/Rakefile +27 -0
- data/lib/monitoring_protocols.rb +22 -0
- data/lib/monitoring_protocols/builder.rb +10 -0
- data/lib/monitoring_protocols/collectd/builder.rb +96 -0
- data/lib/monitoring_protocols/collectd/msg.rb +106 -0
- data/lib/monitoring_protocols/collectd/parser.rb +175 -0
- data/lib/monitoring_protocols/core.rb +23 -0
- data/lib/monitoring_protocols/data_struct.rb +98 -0
- data/lib/monitoring_protocols/json/builder.rb +41 -0
- data/lib/monitoring_protocols/json/parser.rb +115 -0
- data/lib/monitoring_protocols/msgpack/parser.rb +16 -0
- data/lib/monitoring_protocols/parser.rb +22 -0
- data/lib/monitoring_protocols/struct.rb +97 -0
- data/lib/monitoring_protocols/version.rb +3 -0
- data/monitoring_protocols.gemspec +19 -0
- data/specs/factories.rb +44 -0
- data/specs/spec_helper.rb +15 -0
- data/specs/unit/collectd/builder_spec.rb +58 -0
- data/specs/unit/collectd/msg_spec.rb +93 -0
- data/specs/unit/collectd/parser_spec.rb +212 -0
- data/specs/unit/core_spec.rb +19 -0
- data/specs/unit/data_struct_spec.rb +89 -0
- data/specs/unit/json/builder_spec.rb +49 -0
- data/specs/unit/json/parser_spec.rb +353 -0
- data/specs/unit/msgpack/parser_spec.rb +322 -0
- data/specs/unit/parser_spec.rb +18 -0
- data/specs/unit/struct_spec.rb +83 -0
- metadata +102 -0
@@ -0,0 +1,322 @@
|
|
1
|
+
require File.expand_path('../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'MessagePack Ruby parser' do
|
4
|
+
before do
|
5
|
+
@parser_class = MonitoringProtocols::MsgPack::Parser
|
6
|
+
@now = Time.new.utc
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'first packet' do
|
10
|
+
before do
|
11
|
+
@json = MessagePack.pack({
|
12
|
+
'type' => 'datapoints',
|
13
|
+
'host' => 'hostname',
|
14
|
+
'app_name' => 'system',
|
15
|
+
'time' => @now.iso8601,
|
16
|
+
'first' => true,
|
17
|
+
|
18
|
+
'cpu' => {
|
19
|
+
'user' => 1,
|
20
|
+
}
|
21
|
+
}
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
should 'parse buffer' do
|
26
|
+
msgs = @parser_class.parse(@json)
|
27
|
+
msgs.size.should == 1
|
28
|
+
|
29
|
+
msgs[0].class.should == MonitoringProtocols::DataPoint
|
30
|
+
msgs[0].first == true
|
31
|
+
msgs[0].host.should == 'hostname'
|
32
|
+
msgs[0].time.to_i.should == @now.to_i
|
33
|
+
msgs[0].app_name.should == 'system'
|
34
|
+
msgs[0].res_name.should == 'cpu'
|
35
|
+
msgs[0].metric_name.should == 'user'
|
36
|
+
msgs[0].value.should == 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'with common app_name' do
|
41
|
+
|
42
|
+
describe 'One point in buffer' do
|
43
|
+
before do
|
44
|
+
@json = MessagePack.pack({
|
45
|
+
'type' => 'datapoints',
|
46
|
+
'host' => 'hostname',
|
47
|
+
'app_name' => 'system',
|
48
|
+
'time' => @now.iso8601,
|
49
|
+
|
50
|
+
'cpu' => {
|
51
|
+
'user' => 1,
|
52
|
+
}
|
53
|
+
}
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
should 'parse buffer' do
|
58
|
+
msgs = @parser_class.parse(@json)
|
59
|
+
msgs.size.should == 1
|
60
|
+
|
61
|
+
msgs[0].class.should == MonitoringProtocols::DataPoint
|
62
|
+
msgs[0].host.should == 'hostname'
|
63
|
+
msgs[0].time.to_i.should == @now.to_i
|
64
|
+
msgs[0].app_name.should == 'system'
|
65
|
+
msgs[0].res_name.should == 'cpu'
|
66
|
+
msgs[0].metric_name.should == 'user'
|
67
|
+
msgs[0].value.should == 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
describe 'Multiple points in buffer' do
|
73
|
+
before do
|
74
|
+
@json = MessagePack.pack({
|
75
|
+
'type' => 'datapoints',
|
76
|
+
'host' => 'hostname',
|
77
|
+
'app_name' => 'system',
|
78
|
+
'time' => @now.iso8601,
|
79
|
+
|
80
|
+
'cpu' => {
|
81
|
+
'user' => 1,
|
82
|
+
'sys' => 2
|
83
|
+
},
|
84
|
+
|
85
|
+
'memory' => {
|
86
|
+
'total' => 4,
|
87
|
+
'used' => 1,
|
88
|
+
'free' => 3
|
89
|
+
}
|
90
|
+
}
|
91
|
+
)
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
should 'parse buffer' do
|
96
|
+
msgs = @parser_class.parse(@json)
|
97
|
+
msgs.size.should == 5
|
98
|
+
|
99
|
+
common_check = ->(m){
|
100
|
+
m.class.should == MonitoringProtocols::DataPoint
|
101
|
+
m.host.should == 'hostname'
|
102
|
+
m.time.to_i.should == @now.to_i
|
103
|
+
m.app_name.should == 'system'
|
104
|
+
}
|
105
|
+
|
106
|
+
msgs[0].tap do |m|
|
107
|
+
common_check.call(m)
|
108
|
+
m.res_name.should == 'cpu'
|
109
|
+
m.metric_name.should == 'user'
|
110
|
+
m.value.should == 1
|
111
|
+
end
|
112
|
+
|
113
|
+
msgs[1].tap do |m|
|
114
|
+
common_check.call(m)
|
115
|
+
m.res_name.should == 'cpu'
|
116
|
+
m.metric_name.should == 'sys'
|
117
|
+
m.value.should == 2
|
118
|
+
end
|
119
|
+
|
120
|
+
msgs[2].tap do |m|
|
121
|
+
common_check.call(m)
|
122
|
+
m.res_name.should == 'memory'
|
123
|
+
m.metric_name.should == 'total'
|
124
|
+
m.value.should == 4
|
125
|
+
end
|
126
|
+
|
127
|
+
msgs[3].tap do |m|
|
128
|
+
common_check.call(m)
|
129
|
+
m.res_name.should == 'memory'
|
130
|
+
m.metric_name.should == 'used'
|
131
|
+
m.value.should == 1
|
132
|
+
end
|
133
|
+
|
134
|
+
msgs[4].tap do |m|
|
135
|
+
common_check.call(m)
|
136
|
+
m.res_name.should == 'memory'
|
137
|
+
m.metric_name.should == 'free'
|
138
|
+
m.value.should == 3
|
139
|
+
end
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
describe 'with different app_name' do
|
150
|
+
|
151
|
+
describe 'One point in buffer' do
|
152
|
+
before do
|
153
|
+
@json = MessagePack.pack({
|
154
|
+
'type' => 'datapoints',
|
155
|
+
'host' => 'hostname',
|
156
|
+
'time' => @now.iso8601,
|
157
|
+
|
158
|
+
'system' => {
|
159
|
+
'cpu' => {
|
160
|
+
'user' => 1,
|
161
|
+
}
|
162
|
+
}
|
163
|
+
}
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
should 'parse buffer' do
|
168
|
+
msgs = @parser_class.parse(@json)
|
169
|
+
msgs.size.should == 1
|
170
|
+
|
171
|
+
msgs[0].class.should == MonitoringProtocols::DataPoint
|
172
|
+
msgs[0].host.should == 'hostname'
|
173
|
+
msgs[0].time.to_i.should == @now.to_i
|
174
|
+
msgs[0].app_name.should == 'system'
|
175
|
+
msgs[0].res_name.should == 'cpu'
|
176
|
+
msgs[0].metric_name.should == 'user'
|
177
|
+
msgs[0].value.should == 1
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
describe 'Multiple points in buffer' do
|
183
|
+
before do
|
184
|
+
@now = Time.new.utc
|
185
|
+
@json = MessagePack.pack({
|
186
|
+
'type' => 'datapoints',
|
187
|
+
'host' => 'hostname',
|
188
|
+
'time' => @now.iso8601,
|
189
|
+
|
190
|
+
'system2' => {
|
191
|
+
'cpu' => {
|
192
|
+
'user' => 45,
|
193
|
+
'sys' => 27
|
194
|
+
}
|
195
|
+
},
|
196
|
+
|
197
|
+
'icmp-ping' => {
|
198
|
+
"1.2.3.4" => {
|
199
|
+
"latency" => 0.0,
|
200
|
+
"loss" => 100.0
|
201
|
+
},
|
202
|
+
"192.168.0.32" => {
|
203
|
+
"latency" => 3.45,
|
204
|
+
"loss" => 4.0
|
205
|
+
}
|
206
|
+
},
|
207
|
+
|
208
|
+
'system' => {
|
209
|
+
'cpu' => {
|
210
|
+
'user' => 1,
|
211
|
+
'sys' => 2
|
212
|
+
},
|
213
|
+
|
214
|
+
'memory' => {
|
215
|
+
'total' => 4,
|
216
|
+
'used' => 1,
|
217
|
+
'free' => 3
|
218
|
+
}
|
219
|
+
}
|
220
|
+
}
|
221
|
+
)
|
222
|
+
|
223
|
+
end
|
224
|
+
|
225
|
+
should 'parse buffer' do
|
226
|
+
msgs = @parser_class.parse(@json)
|
227
|
+
msgs.size.should == 11
|
228
|
+
|
229
|
+
common_check = ->(m, app_name = 'system'){
|
230
|
+
m.class.should == MonitoringProtocols::DataPoint
|
231
|
+
m.host.should == 'hostname'
|
232
|
+
m.time.to_i.should == @now.to_i
|
233
|
+
m.app_name.should == app_name
|
234
|
+
}
|
235
|
+
|
236
|
+
index = -1
|
237
|
+
|
238
|
+
msgs[index += 1].tap do |m|
|
239
|
+
common_check.call(m, 'system2')
|
240
|
+
m.res_name.should == 'cpu'
|
241
|
+
m.metric_name.should == 'user'
|
242
|
+
m.value.should == 45
|
243
|
+
end
|
244
|
+
|
245
|
+
msgs[index += 1].tap do |m|
|
246
|
+
common_check.call(m, 'system2')
|
247
|
+
m.res_name.should == 'cpu'
|
248
|
+
m.metric_name.should == 'sys'
|
249
|
+
m.value.should == 27
|
250
|
+
end
|
251
|
+
|
252
|
+
msgs[index += 1].tap do |m|
|
253
|
+
common_check.call(m, 'icmp-ping')
|
254
|
+
m.res_name.should == '1.2.3.4'
|
255
|
+
m.metric_name.should == 'latency'
|
256
|
+
m.value.should == 0.0
|
257
|
+
end
|
258
|
+
|
259
|
+
msgs[index += 1].tap do |m|
|
260
|
+
common_check.call(m, 'icmp-ping')
|
261
|
+
m.res_name.should == '1.2.3.4'
|
262
|
+
m.metric_name.should == 'loss'
|
263
|
+
m.value.should == 100.0
|
264
|
+
end
|
265
|
+
|
266
|
+
msgs[index += 1].tap do |m|
|
267
|
+
common_check.call(m, 'icmp-ping')
|
268
|
+
m.res_name.should == '192.168.0.32'
|
269
|
+
m.metric_name.should == 'latency'
|
270
|
+
m.value.should == 3.45
|
271
|
+
end
|
272
|
+
|
273
|
+
msgs[index += 1].tap do |m|
|
274
|
+
common_check.call(m, 'icmp-ping')
|
275
|
+
m.res_name.should == '192.168.0.32'
|
276
|
+
m.metric_name.should == 'loss'
|
277
|
+
m.value.should == 4.0
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
msgs[index += 1].tap do |m|
|
282
|
+
common_check.call(m)
|
283
|
+
m.res_name.should == 'cpu'
|
284
|
+
m.metric_name.should == 'user'
|
285
|
+
m.value.should == 1
|
286
|
+
end
|
287
|
+
|
288
|
+
msgs[index += 1].tap do |m|
|
289
|
+
common_check.call(m)
|
290
|
+
m.res_name.should == 'cpu'
|
291
|
+
m.metric_name.should == 'sys'
|
292
|
+
m.value.should == 2
|
293
|
+
end
|
294
|
+
|
295
|
+
msgs[index += 1].tap do |m|
|
296
|
+
common_check.call(m)
|
297
|
+
m.res_name.should == 'memory'
|
298
|
+
m.metric_name.should == 'total'
|
299
|
+
m.value.should == 4
|
300
|
+
end
|
301
|
+
|
302
|
+
msgs[index += 1].tap do |m|
|
303
|
+
common_check.call(m)
|
304
|
+
m.res_name.should == 'memory'
|
305
|
+
m.metric_name.should == 'used'
|
306
|
+
m.value.should == 1
|
307
|
+
end
|
308
|
+
|
309
|
+
msgs[index += 1].tap do |m|
|
310
|
+
common_check.call(m)
|
311
|
+
m.res_name.should == 'memory'
|
312
|
+
m.metric_name.should == 'free'
|
313
|
+
m.value.should == 3
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
|
321
|
+
|
322
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'Parser' do
|
4
|
+
|
5
|
+
should 'call parse class method by default' do
|
6
|
+
n = 0
|
7
|
+
|
8
|
+
parser = Class.new(MonitoringProtocols::Parser)
|
9
|
+
parser.define_singleton_method(:parse) do |data|
|
10
|
+
n = 2
|
11
|
+
end
|
12
|
+
|
13
|
+
p = parser.new
|
14
|
+
p.parse("data")
|
15
|
+
n.should == 2
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe 'Generic Network Message' do
|
4
|
+
before do
|
5
|
+
@now = Time.now
|
6
|
+
|
7
|
+
@base_data = {
|
8
|
+
time: @now,
|
9
|
+
host: 'local',
|
10
|
+
app_name: 'app',
|
11
|
+
res_name: 'res',
|
12
|
+
metric_name: 'metric',
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'DataPoint' do
|
17
|
+
before do
|
18
|
+
@p = MonitoringProtocols::DataPoint.new(
|
19
|
+
@base_data.merge(value: 2.45)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'have working factory' do
|
24
|
+
point = FactoryGirl.build(:data_point)
|
25
|
+
point.should.not == nil
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'have all fields' do
|
29
|
+
@p.time.should == @now
|
30
|
+
@p.host.should == 'local'
|
31
|
+
@p.app_name.should == 'app'
|
32
|
+
@p.value.should == 2.45
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can be encoded with msgpack' do
|
36
|
+
data = MessagePack.pack(@p)
|
37
|
+
h = MessagePack.unpack(data)
|
38
|
+
h.class.should == Hash
|
39
|
+
|
40
|
+
h['type'].should == 'datapoint'
|
41
|
+
h['time'].should == @p.time.iso8601()
|
42
|
+
h['host'].should == @p.host
|
43
|
+
h['app_name'].should == @p.app_name
|
44
|
+
h['res_name'].should == @p.res_name
|
45
|
+
h['metric_name'].should == @p.metric_name
|
46
|
+
h['value'].should == 2.45
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe 'Notification' do
|
52
|
+
before do
|
53
|
+
@n = MonitoringProtocols::Notification.new(
|
54
|
+
@base_data.merge(severity: 0, message: 'I saw a horse')
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
should 'have all fields' do
|
59
|
+
@n.time.should == @now
|
60
|
+
@n.host.should == 'local'
|
61
|
+
@n.app_name.should == 'app'
|
62
|
+
@n.severity.should == :info
|
63
|
+
@n.message.should == 'I saw a horse'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can be encoded with msgpack' do
|
67
|
+
data = MessagePack.pack(@n)
|
68
|
+
h = MessagePack.unpack(data)
|
69
|
+
h.class.should == Hash
|
70
|
+
|
71
|
+
h['type'].should == 'notification'
|
72
|
+
h['time'].should == @n.time.iso8601()
|
73
|
+
h['host'].should == @n.host
|
74
|
+
h['app_name'].should == @n.app_name
|
75
|
+
h['res_name'].should == @n.res_name
|
76
|
+
h['metric_name'].should == @n.metric_name
|
77
|
+
h['severity'].should == 'info'
|
78
|
+
h['message'].should == 'I saw a horse'
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monitoring_protocols
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julien Ammous
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: msgpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: "..."
|
42
|
+
email:
|
43
|
+
- schmurfy@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- Guardfile
|
51
|
+
- LICENSE
|
52
|
+
- Rakefile
|
53
|
+
- lib/monitoring_protocols.rb
|
54
|
+
- lib/monitoring_protocols/builder.rb
|
55
|
+
- lib/monitoring_protocols/collectd/builder.rb
|
56
|
+
- lib/monitoring_protocols/collectd/msg.rb
|
57
|
+
- lib/monitoring_protocols/collectd/parser.rb
|
58
|
+
- lib/monitoring_protocols/core.rb
|
59
|
+
- lib/monitoring_protocols/data_struct.rb
|
60
|
+
- lib/monitoring_protocols/json/builder.rb
|
61
|
+
- lib/monitoring_protocols/json/parser.rb
|
62
|
+
- lib/monitoring_protocols/msgpack/parser.rb
|
63
|
+
- lib/monitoring_protocols/parser.rb
|
64
|
+
- lib/monitoring_protocols/struct.rb
|
65
|
+
- lib/monitoring_protocols/version.rb
|
66
|
+
- monitoring_protocols.gemspec
|
67
|
+
- specs/factories.rb
|
68
|
+
- specs/spec_helper.rb
|
69
|
+
- specs/unit/collectd/builder_spec.rb
|
70
|
+
- specs/unit/collectd/msg_spec.rb
|
71
|
+
- specs/unit/collectd/parser_spec.rb
|
72
|
+
- specs/unit/core_spec.rb
|
73
|
+
- specs/unit/data_struct_spec.rb
|
74
|
+
- specs/unit/json/builder_spec.rb
|
75
|
+
- specs/unit/json/parser_spec.rb
|
76
|
+
- specs/unit/msgpack/parser_spec.rb
|
77
|
+
- specs/unit/parser_spec.rb
|
78
|
+
- specs/unit/struct_spec.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses: []
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.5.1
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: "...."
|
102
|
+
test_files: []
|