logstash-codec-prometheus 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6b78c11762b5d2d8402571191124e55b4a34efcfbbe7d835eac871ef7163bad9
4
+ data.tar.gz: f290451b60e77b02591ea3295dbb80fbd88a8375102657a9546c148d589fc485
5
+ SHA512:
6
+ metadata.gz: 38c3a2575b1478f98981278c60d8ab959bf3f8736f0d1cd25ac0aeae8bf2f5a1f3ce7b3822786755e438a0a179084ce60e8fbe3cf5e72a2e554019ffa596a62e
7
+ data.tar.gz: dfdf449288985f78a1f278605398af1ddb0fd73db95fa38a016d2af0095020278cbdcccf2c8816f33ea3ec5c5d4bc245f5bf0450bdd61a3c69c60f2e44e40304
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ - Plugin created with the logstash plugin generator
@@ -0,0 +1,10 @@
1
+ The following is a list of people who have contributed ideas, code, bug
2
+ reports, or in general have helped logstash along its way.
3
+
4
+ Contributors:
5
+ * - Ryan Bartsch
6
+
7
+ Note: If you've sent us patches, bug reports, or otherwise contributed to
8
+ Logstash, and you aren't on the list above and want to be, please let us know
9
+ and we'll make sure you're here. Contributions from folks like you are what make
10
+ open source awesome.
@@ -0,0 +1,2 @@
1
+ # logstash-output-loganalytics
2
+ Example output plugin. This should help bootstrap your effort to write your own output plugin!
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
File without changes
@@ -0,0 +1,45 @@
1
+ # encoding: utf-8
2
+ require "logstash/codecs/base"
3
+ require "logstash/codecs/line"
4
+ require 'json'
5
+
6
+ class LogStash::Codecs::Prometheus < LogStash::Codecs::Base
7
+ config_name "prometheus"
8
+
9
+ public
10
+ def register
11
+ @lines = LogStash::Codecs::Line.new
12
+ end
13
+
14
+ public
15
+ def decode(data)
16
+ @lines.decode(data) do |event|
17
+ unless event.get("message").start_with?("#")
18
+ metric_name, metric_value = event.get("message").split(" ")
19
+ unless metric_name.match(/^.+{.+}$/)
20
+ yield LogStash::Event.new(metric_name => metric_value.to_f)
21
+ else
22
+ outside, inside = metric_name.match(/^(.+){(.+)}$/).captures
23
+ vars = inside.split(",")
24
+ vars.each do |var|
25
+ key, value = var.split("=")
26
+ custom_metric_name = [outside,key,value.gsub!(/^\"|\"?$/, "")].join('_')
27
+ yield LogStash::Event.new(custom_metric_name => metric_value.to_f)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ public
35
+ def encode(event)
36
+ h = {}
37
+ event.to_hash.each do |metric_name,metric_value|
38
+ h[metric_name] = metric_value
39
+ end
40
+ unless h.empty?
41
+ @on_event.call(event, h.to_json)
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'logstash-codec-prometheus'
3
+ s.version = '0.1.0'
4
+ s.licenses = ['Apache-2.0']
5
+ s.summary = 'Reads `prometheus` formatted lines'
6
+ s.description = 'This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program'
7
+ s.homepage = 'https://github.com/yesmarket/logstash-codec-prometheus'
8
+ s.authors = ['Ryan Bartsch']
9
+ s.email = 'rbartsch@adam.com.au'
10
+ s.require_paths = ['lib']
11
+
12
+ # Files
13
+ s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
14
+ # Tests
15
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
16
+
17
+ # Special flag to let us know this is actually a logstash plugin
18
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "codec" }
19
+
20
+ # Gem dependencies
21
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
22
+ s.add_runtime_dependency 'logstash-codec-line'
23
+ s.add_development_dependency 'logstash-devutils'
24
+ end
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
3
+ require "logstash/codecs/prometheus"
4
+ require "logstash/event"
5
+ require "logstash/json"
6
+ require 'json'
7
+ require "insist"
8
+
9
+ describe LogStash::Codecs::Prometheus do
10
+
11
+ let(:codec) { LogStash::Codecs::Prometheus.new }
12
+
13
+ before do
14
+ codec.register
15
+ end
16
+
17
+ context "#decode" do
18
+
19
+ it "should ignore comments" do
20
+ event_returned = false
21
+ codec.decode("#test 1\n") do |event|
22
+ event_returned = true
23
+ end
24
+ insist { !event_returned }
25
+ end
26
+
27
+ it "should return an event from single full prometheus line" do
28
+ codec.decode("test 1\n") do |event|
29
+ insist { event.is_a?(LogStash::Event) }
30
+ insist { event.get("test") } == 1.to_f
31
+ end
32
+ end
33
+
34
+ it "should return an multiple events given multiple prometheus lines" do
35
+ counter = 0
36
+ codec.decode("test 1\ntest 2\n") do |event|
37
+ insist { event.is_a?(LogStash::Event) }
38
+ counter += 1
39
+ end
40
+ insist { counter } == 2
41
+ end
42
+
43
+ it "should return multiple events given a labeled metric" do
44
+ counter = 0
45
+ codec.decode("test{a=\"b\",x=\"y\"} 1\n") do |event|
46
+ insist { event.is_a?(LogStash::Event) }
47
+ counter += 1
48
+ end
49
+ insist { counter } == 2
50
+ end
51
+
52
+ it "should have correct metric name for labeled metric" do
53
+ codec.decode("test{a=\"b\"} 1\n") do |event|
54
+ insist { event.is_a?(LogStash::Event) }
55
+ insist { event.get("test_a_b") } == 1.to_f
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ context "#encode" do
62
+
63
+ it "should return json data" do
64
+ data = {"foo" => 1.0, "bar" => 2.0}
65
+ event = LogStash::Event.new(data)
66
+ got_event = false
67
+ codec.on_event do |event, message|
68
+ insist { message.chomp } == event.to_json
69
+ insist { LogStash::Json.load(message)["foo"] } == data["foo"]
70
+ insist { LogStash::Json.load(message)["bar"] } == data["bar"]
71
+ got_event = true
72
+ end
73
+ codec.encode(event)
74
+ insist { got_event }
75
+ end
76
+
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-codec-prometheus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Bartsch
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ name: logstash-core-plugin-api
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ name: logstash-codec-line
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ name: logstash-devutils
48
+ prerelease: false
49
+ type: :development
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This gem is a Logstash plugin required to be installed on top of the
56
+ Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
57
+ gem is not a stand-alone program
58
+ email: rbartsch@adam.com.au
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - CHANGELOG.md
64
+ - CONTRIBUTORS
65
+ - DEVELOPER.md
66
+ - Gemfile
67
+ - LICENSE
68
+ - README.md
69
+ - lib/logstash/codecs/prometheus.rb
70
+ - logstash-codec-prometheus.gemspec
71
+ - spec/codecs/prometheus_spec.rb
72
+ homepage: https://github.com/yesmarket/logstash-codec-prometheus
73
+ licenses:
74
+ - Apache-2.0
75
+ metadata:
76
+ logstash_plugin: 'true'
77
+ logstash_group: codec
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Reads `prometheus` formatted lines
98
+ test_files:
99
+ - spec/codecs/prometheus_spec.rb