fluent-plugin-prometheus-pull 0.2.1 → 0.4.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.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/Gemfile.lock +6 -2
- data/README.md +55 -19
- data/fluent-plugin-prometheus-pull.gemspec +3 -1
- data/lib/fluent/plugin/in_prometheus_pull.rb +27 -6
- data/lib/fluent/plugin/prometheus_pull/labeled_url.rb +31 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bf56d6a19e8eb5e8e032434ebc12267e845cb539ee6b0ceeedd29f8c83e8e1f
|
4
|
+
data.tar.gz: df7deb6aee0408f7f8200d852b2ad63ce969cb9f74fba75ac9c3dc7eb5907693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab1ee690706221a9b3943cea0218da2e529f103c309f3dfed01f1de5f879de20c6b196a63dd7628b20c215b100430c36dc583b25262b66b83ae2d6c652f7512f
|
7
|
+
data.tar.gz: 72bb075b1a1e15f441a1b2d0d4ef82e89072c5227ff35a337c9c0fe9af4799a1fb3f4bf41d0898d466bd6118552f08881edf3df724702852d5f28ddbe9787381
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.7.
|
1
|
+
2.7.8
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-prometheus-pull (0.
|
4
|
+
fluent-plugin-prometheus-pull (0.4.0)
|
5
5
|
fluentd (>= 0.14.10, < 2)
|
6
6
|
|
7
7
|
GEM
|
@@ -27,6 +27,8 @@ GEM
|
|
27
27
|
http_parser.rb (0.8.0)
|
28
28
|
json (2.6.3)
|
29
29
|
kwalify (0.7.2)
|
30
|
+
mocha (2.4.5)
|
31
|
+
ruby2_keywords (>= 0.0.5)
|
30
32
|
msgpack (1.6.0)
|
31
33
|
parallel (1.22.1)
|
32
34
|
parser (3.2.0.0)
|
@@ -55,6 +57,7 @@ GEM
|
|
55
57
|
rubocop-rake (0.6.0)
|
56
58
|
rubocop (~> 1.0)
|
57
59
|
ruby-progressbar (1.11.0)
|
60
|
+
ruby2_keywords (0.0.5)
|
58
61
|
serverengine (2.3.1)
|
59
62
|
sigdump (~> 0.2.2)
|
60
63
|
sigdump (0.2.4)
|
@@ -77,6 +80,7 @@ DEPENDENCIES
|
|
77
80
|
bundler (~> 2.3)
|
78
81
|
byebug (~> 11.1, >= 11.1.3)
|
79
82
|
fluent-plugin-prometheus-pull!
|
83
|
+
mocha (~> 2.4, >= 2.4.5)
|
80
84
|
rake (~> 13.0.6)
|
81
85
|
reek (~> 6.1, >= 6.1.4)
|
82
86
|
rubocop (~> 1.44, >= 1.44.1)
|
@@ -84,4 +88,4 @@ DEPENDENCIES
|
|
84
88
|
test-unit (~> 3.5.3)
|
85
89
|
|
86
90
|
BUNDLED WITH
|
87
|
-
2.4.
|
91
|
+
2.4.22
|
data/README.md
CHANGED
@@ -1,43 +1,79 @@
|
|
1
1
|
# fluent-plugin-prometheus-pull
|
2
2
|
|
3
|
-
[Fluentd](https://fluentd.org/) input plugin to
|
3
|
+
[Fluentd](https://fluentd.org/) input plugin to pull prometheus http endpoint.
|
4
4
|
|
5
|
-
TODO: write description for you plugin.
|
6
5
|
|
7
|
-
##
|
6
|
+
## plugins
|
7
|
+
|
8
|
+
### input - prometheus_pull
|
9
|
+
|
10
|
+
Pull http prometheus metric endpoint.
|
11
|
+
|
12
|
+
with options:
|
8
13
|
|
9
|
-
|
14
|
+
| options | default | usage |
|
15
|
+
|---------------------|---------|------------------------------------------------------|
|
16
|
+
| | | |
|
17
|
+
| event_url_key | nil | define the key that will store the fetched url |
|
18
|
+
| event_url_label_key | nil | define the key that will store the fetched url label |
|
19
|
+
|
20
|
+
Example:
|
10
21
|
|
11
22
|
```
|
12
|
-
|
23
|
+
<source>
|
24
|
+
@type prometheus_pull
|
25
|
+
urls http://app/metrics,http://app2/metrics
|
26
|
+
interval 300s
|
27
|
+
|
28
|
+
tag metric
|
29
|
+
|
30
|
+
<parse>
|
31
|
+
@type prometheus_text
|
32
|
+
label_prefix tags_
|
33
|
+
add_type false
|
34
|
+
</parse>
|
35
|
+
</source>
|
13
36
|
```
|
14
37
|
|
15
|
-
###
|
38
|
+
### parser - prometheus_text
|
16
39
|
|
17
|
-
|
40
|
+
Take a "text" (string) of prometheus content, fetched by any mechanism you want,
|
41
|
+
then it parses it, transforming each line in 1 event.
|
18
42
|
|
19
|
-
|
20
|
-
|
21
|
-
|
43
|
+
with options:
|
44
|
+
* ...
|
45
|
+
* ...
|
22
46
|
|
23
|
-
|
47
|
+
Example:
|
24
48
|
|
25
49
|
```
|
26
|
-
|
50
|
+
<parse>
|
51
|
+
@type prometheus_text
|
52
|
+
label_prefix tags_
|
53
|
+
add_type false
|
54
|
+
</parse>
|
27
55
|
```
|
28
56
|
|
29
|
-
##
|
57
|
+
## Installation
|
58
|
+
|
59
|
+
Manual install, by executing:
|
30
60
|
|
31
|
-
|
61
|
+
$ gem install fluent-plugin-prometheus-pull
|
32
62
|
|
33
|
-
|
34
|
-
|
35
|
-
|
63
|
+
Add to Gemfile with:
|
64
|
+
|
65
|
+
$ bundle add fluent-plugin-prometheus-pull
|
66
|
+
|
67
|
+
|
68
|
+
## Compatibility
|
69
|
+
|
70
|
+
plugin will work with:
|
71
|
+
- ruby >= 2.7.7
|
72
|
+
- td-agent >= 4.0.0
|
36
73
|
|
37
|
-
You can copy and paste generated documents here.
|
38
74
|
|
39
75
|
## Copyright
|
40
76
|
|
41
|
-
* Copyright(c) 2023- Thomas Tych
|
77
|
+
* Copyright(c) 2023-2024 Thomas Tych
|
42
78
|
* License
|
43
79
|
* Apache License, Version 2.0
|
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'fluent-plugin-prometheus-pull'
|
8
|
-
spec.version = '0.
|
8
|
+
spec.version = '0.4.0'
|
9
9
|
spec.authors = ['Thomas Tych']
|
10
10
|
spec.email = ['thomas.tych@gmail.com']
|
11
11
|
|
@@ -34,6 +34,8 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'rubocop', '~> 1.44', '>= 1.44.1'
|
35
35
|
spec.add_development_dependency 'rubocop-rake', '~> 0.6.0'
|
36
36
|
spec.add_development_dependency 'test-unit', '~> 3.5.3'
|
37
|
+
spec.add_development_dependency 'mocha', '~> 2.4', '>= 2.4.5'
|
38
|
+
|
37
39
|
|
38
40
|
spec.add_runtime_dependency 'fluentd', ['>= 0.14.10', '< 2']
|
39
41
|
end
|
@@ -20,6 +20,8 @@ require 'uri'
|
|
20
20
|
|
21
21
|
require 'fluent/plugin/input'
|
22
22
|
|
23
|
+
require_relative 'prometheus_pull/labeled_url'
|
24
|
+
|
23
25
|
module Fluent
|
24
26
|
module Plugin
|
25
27
|
# input / source
|
@@ -27,6 +29,8 @@ module Fluent
|
|
27
29
|
class PrometheusPullInput < Fluent::Plugin::Input
|
28
30
|
Fluent::Plugin.register_input('prometheus_pull', self)
|
29
31
|
|
32
|
+
attr_reader :labeled_urls
|
33
|
+
|
30
34
|
helpers :timer, :parser, :compat_parameters
|
31
35
|
|
32
36
|
desc 'The tag of the event'
|
@@ -63,31 +67,44 @@ module Fluent
|
|
63
67
|
desc 'CA file path'
|
64
68
|
config_param :ca_file, :string, default: nil
|
65
69
|
|
70
|
+
desc 'Event URL key'
|
71
|
+
config_param :event_url_key, :string, default: nil
|
72
|
+
desc 'Event URL label key'
|
73
|
+
config_param :event_url_label_key, :string, default: nil
|
74
|
+
|
66
75
|
def configure(conf)
|
67
76
|
compat_parameters_convert(conf, :parser)
|
68
77
|
|
69
78
|
parser_config = conf.elements('parse').first
|
70
79
|
# raise Fluent::ConfigError, '<parse> section is required.' unless parser_config
|
71
|
-
parser_config
|
80
|
+
unless parser_config
|
81
|
+
parser_config ||= Fluent::Config::Element.new('parse', '', { '@type' => 'prometheus_text' }, [])
|
82
|
+
conf.elements.append(parser_config)
|
83
|
+
end
|
72
84
|
|
73
85
|
super
|
74
86
|
|
87
|
+
@labeled_urls = urls.map { |url| parse_url(url) }
|
88
|
+
|
75
89
|
@parser = parser_create(conf: parser_config)
|
76
90
|
end
|
77
91
|
|
78
92
|
def start
|
79
93
|
super
|
80
94
|
|
81
|
-
timer_execute(:
|
95
|
+
timer_execute(:in_prometheus_pull_timer, @interval, &method(:pull))
|
82
96
|
end
|
83
97
|
|
84
98
|
def pull
|
85
|
-
|
99
|
+
labeled_urls.each do |url|
|
86
100
|
pull_time = Fluent::EventTime.now
|
87
|
-
raw_metrics = fetch(url)
|
101
|
+
raw_metrics = fetch(url.url)
|
88
102
|
parser.parse(raw_metrics) do |time, record|
|
89
103
|
begin
|
90
104
|
time ||= pull_time
|
105
|
+
record[event_url_key] = url.url if event_url_key
|
106
|
+
record[event_url_label_key] = url.label if event_url_label_key && url.label
|
107
|
+
|
91
108
|
router.emit(tag, time, record)
|
92
109
|
rescue StandardError => e
|
93
110
|
error("error #{e}, while emitting #{record}")
|
@@ -127,8 +144,8 @@ module Fluent
|
|
127
144
|
def fetch(url, redirect_limit = 5)
|
128
145
|
raise 'Max number of redirects reached' if redirect_limit <= 0
|
129
146
|
|
130
|
-
|
131
|
-
http(
|
147
|
+
fetch_uri = URI.parse(url)
|
148
|
+
http(fetch_uri) do |http, uri|
|
132
149
|
req = request(uri)
|
133
150
|
response = http.request(req)
|
134
151
|
|
@@ -150,6 +167,10 @@ module Fluent
|
|
150
167
|
|
151
168
|
log.error(message)
|
152
169
|
end
|
170
|
+
|
171
|
+
def parse_url(labeled_url)
|
172
|
+
PrometheusPull::LabeledUrl.parse_labeled_url(labeled_url)
|
173
|
+
end
|
153
174
|
end
|
154
175
|
end
|
155
176
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Fluent
|
4
|
+
module Plugin
|
5
|
+
module PrometheusPull
|
6
|
+
class LabeledUrl
|
7
|
+
LABELED_URL_RE = /^(?:@(?<label>[^@]*)@)?(?<url>.*)$/.freeze
|
8
|
+
|
9
|
+
attr_reader :url, :label
|
10
|
+
|
11
|
+
def initialize(url:, label: nil)
|
12
|
+
@url = url
|
13
|
+
@label = label
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
url
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.parse_labeled_url(url)
|
21
|
+
match_data = LABELED_URL_RE.match(url)
|
22
|
+
|
23
|
+
raise Fluent::ConfigError, "unable to use url '#{url}'" unless match_data
|
24
|
+
|
25
|
+
new(url: match_data[:url],
|
26
|
+
label: match_data[:label])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-prometheus-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Tych
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -140,6 +140,26 @@ dependencies:
|
|
140
140
|
- - "~>"
|
141
141
|
- !ruby/object:Gem::Version
|
142
142
|
version: 3.5.3
|
143
|
+
- !ruby/object:Gem::Dependency
|
144
|
+
name: mocha
|
145
|
+
requirement: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - "~>"
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '2.4'
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 2.4.5
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
155
|
+
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.4'
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 2.4.5
|
143
163
|
- !ruby/object:Gem::Dependency
|
144
164
|
name: fluentd
|
145
165
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,6 +199,7 @@ files:
|
|
179
199
|
- fluent-plugin-prometheus-pull.gemspec
|
180
200
|
- lib/fluent/plugin/in_prometheus_pull.rb
|
181
201
|
- lib/fluent/plugin/parser_prometheus_text.rb
|
202
|
+
- lib/fluent/plugin/prometheus_pull/labeled_url.rb
|
182
203
|
homepage: https://gitlab.com/ttych/fluent-plugin-prometheus-pull.git
|
183
204
|
licenses:
|
184
205
|
- Apache-2.0
|