fluent-plugin-prometheus-pull 0.3.0 → 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/Gemfile.lock +1 -1
- data/README.md +6 -6
- data/fluent-plugin-prometheus-pull.gemspec +1 -1
- data/lib/fluent/plugin/in_prometheus_pull.rb +17 -3
- data/lib/fluent/plugin/prometheus_pull/labeled_url.rb +31 -0
- metadata +3 -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/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -11,11 +11,11 @@ Pull http prometheus metric endpoint.
|
|
11
11
|
|
12
12
|
with options:
|
13
13
|
|
14
|
-
| options
|
15
|
-
|
16
|
-
|
|
17
|
-
| event_url_key
|
18
|
-
|
|
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
19
|
|
20
20
|
Example:
|
21
21
|
|
@@ -74,6 +74,6 @@ plugin will work with:
|
|
74
74
|
|
75
75
|
## Copyright
|
76
76
|
|
77
|
-
* Copyright(c) 2023- Thomas Tych
|
77
|
+
* Copyright(c) 2023-2024 Thomas Tych
|
78
78
|
* License
|
79
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
|
|
@@ -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'
|
@@ -65,6 +69,8 @@ module Fluent
|
|
65
69
|
|
66
70
|
desc 'Event URL key'
|
67
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
|
68
74
|
|
69
75
|
def configure(conf)
|
70
76
|
compat_parameters_convert(conf, :parser)
|
@@ -78,6 +84,8 @@ module Fluent
|
|
78
84
|
|
79
85
|
super
|
80
86
|
|
87
|
+
@labeled_urls = urls.map { |url| parse_url(url) }
|
88
|
+
|
81
89
|
@parser = parser_create(conf: parser_config)
|
82
90
|
end
|
83
91
|
|
@@ -88,13 +96,15 @@ module Fluent
|
|
88
96
|
end
|
89
97
|
|
90
98
|
def pull
|
91
|
-
|
99
|
+
labeled_urls.each do |url|
|
92
100
|
pull_time = Fluent::EventTime.now
|
93
|
-
raw_metrics = fetch(url)
|
101
|
+
raw_metrics = fetch(url.url)
|
94
102
|
parser.parse(raw_metrics) do |time, record|
|
95
103
|
begin
|
96
104
|
time ||= pull_time
|
97
|
-
record[event_url_key] = url if event_url_key
|
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
|
+
|
98
108
|
router.emit(tag, time, record)
|
99
109
|
rescue StandardError => e
|
100
110
|
error("error #{e}, while emitting #{record}")
|
@@ -157,6 +167,10 @@ module Fluent
|
|
157
167
|
|
158
168
|
log.error(message)
|
159
169
|
end
|
170
|
+
|
171
|
+
def parse_url(labeled_url)
|
172
|
+
PrometheusPull::LabeledUrl.parse_labeled_url(labeled_url)
|
173
|
+
end
|
160
174
|
end
|
161
175
|
end
|
162
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: 2024-10-
|
11
|
+
date: 2024-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bump
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- fluent-plugin-prometheus-pull.gemspec
|
200
200
|
- lib/fluent/plugin/in_prometheus_pull.rb
|
201
201
|
- lib/fluent/plugin/parser_prometheus_text.rb
|
202
|
+
- lib/fluent/plugin/prometheus_pull/labeled_url.rb
|
202
203
|
homepage: https://gitlab.com/ttych/fluent-plugin-prometheus-pull.git
|
203
204
|
licenses:
|
204
205
|
- Apache-2.0
|