prometheus-config-builder 0.0.11 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79736d31f0e67d9f52e5984c2f887d38325d1af2
|
4
|
+
data.tar.gz: 541b8ee3704b00ff4c6a2a4762ac92002947b2dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48b24013a8f292a47502785712d1eedba4fbde8dc0b14cf6815a22b9bafea04a31e05237a6495362a3c75b6e46c96368e9c140e90a0ff323ea0e351a63896b2b
|
7
|
+
data.tar.gz: 1d89de2b684488ec8aebe7e585998a72f3a6664417f4c0e1d534dd9d1e8c27edc219736f5f570dfacb2e153c1a8b203530e571a341c13dcb669e45fbf1239e11
|
@@ -8,6 +8,9 @@ require 'prometheus-config-builder'
|
|
8
8
|
require 'pp'
|
9
9
|
require 'yaml'
|
10
10
|
require 'json'
|
11
|
+
require 'prometheus_exporter'
|
12
|
+
require 'prometheus_exporter/client'
|
13
|
+
require 'prometheus_exporter/server'
|
11
14
|
|
12
15
|
config = {}
|
13
16
|
config[:paths] ||= []
|
@@ -49,7 +52,7 @@ if config[:verbose]
|
|
49
52
|
end
|
50
53
|
|
51
54
|
abort "You need to set --prometheus-src" if !config[:prometheus_src]
|
52
|
-
abort "You need to set --
|
55
|
+
abort "You need to set --dst-dir" if !config[:dst_dir]
|
53
56
|
|
54
57
|
log = Logger.new(STDOUT)
|
55
58
|
log.level = config[:verbose] ? Logger::DEBUG : Logger::INFO
|
@@ -64,23 +67,54 @@ if !File.exist?(config[:dst_dir])
|
|
64
67
|
exit!(1)
|
65
68
|
end
|
66
69
|
|
70
|
+
server = PrometheusExporter::Server::WebServer.new port: 12345
|
71
|
+
PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
|
72
|
+
server.start
|
73
|
+
|
74
|
+
something_changed_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_changes_count", "Number of times configuration has changed.")
|
75
|
+
error_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_errors_count", "Number of exceptions during evaluation.")
|
76
|
+
iteration_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_iteration_count", "Number of times configuration has changed.")
|
77
|
+
iteration_duration = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_last_iteration_duration", "Duration (in seconds) of the last full config iteration")
|
78
|
+
|
79
|
+
error_count.observe(0)
|
80
|
+
|
67
81
|
builder = PrometheusConfigBuilder::Builder.new(config[:prometheus_src], config[:dst_dir])
|
68
82
|
|
69
83
|
config[:paths].each do |path|
|
84
|
+
log.info("Adding path #{path} to config discovery list")
|
70
85
|
builder.add_path(path)
|
71
86
|
end
|
72
87
|
|
73
88
|
|
74
89
|
loop do
|
75
|
-
|
90
|
+
starting = Time.now
|
91
|
+
begin
|
92
|
+
something_changed = builder.write_out()
|
93
|
+
rescue Exception => e
|
94
|
+
log.warn("Error while building config: #{e}")
|
95
|
+
puts e.backtrace
|
96
|
+
error_count.increment
|
97
|
+
sleep(config[:every])
|
98
|
+
next
|
99
|
+
end
|
100
|
+
|
101
|
+
something_changed_count.increment if something_changed
|
102
|
+
iteration_count.increment
|
76
103
|
|
77
104
|
# Send a SIGHUP signal to Prometheus so that it knows to reload config files
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
105
|
+
begin
|
106
|
+
if something_changed && config[:pgrep] != nil
|
107
|
+
matches = `pgrep -a -f "#{config[:pgrep]}"`.split("\n")
|
108
|
+
match = matches.select {|e| !e.include?("prometheus-config-builder")}
|
109
|
+
pid = match.first.split(" ").first.to_i
|
110
|
+
if pid
|
111
|
+
log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
|
112
|
+
Process.kill "HUP", pid
|
113
|
+
end
|
83
114
|
end
|
115
|
+
rescue Exception => e
|
116
|
+
log.warn("Unable to send SIGHUP signal to Prometheus: #{e}")
|
117
|
+
puts e.backtrace
|
84
118
|
end
|
85
119
|
|
86
120
|
log.info("Sleeping for #{config[:every]} second and starting then again.")
|
@@ -89,5 +123,8 @@ loop do
|
|
89
123
|
log.level = Logger::WARN
|
90
124
|
end
|
91
125
|
|
126
|
+
ending = Time.now
|
127
|
+
iteration_duration.observe(ending-starting)
|
128
|
+
|
92
129
|
sleep(config[:every])
|
93
130
|
end
|
@@ -14,8 +14,8 @@ require 'logger'
|
|
14
14
|
require_relative './logger.rb'
|
15
15
|
require_relative './scrape_passthrough.rb'
|
16
16
|
require_relative './scrape_ecs.rb'
|
17
|
-
|
18
|
-
|
17
|
+
require 'prometheus_exporter'
|
18
|
+
require 'prometheus_exporter/client'
|
19
19
|
|
20
20
|
module PrometheusConfigBuilder
|
21
21
|
|
@@ -202,6 +202,9 @@ module PrometheusConfigBuilder
|
|
202
202
|
@discoverer = ConfigDiscover.new
|
203
203
|
@paths = []
|
204
204
|
@last_hash = ""
|
205
|
+
|
206
|
+
@@config_files = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_config_files", "Number of found config files")
|
207
|
+
|
205
208
|
end
|
206
209
|
|
207
210
|
def add_path(path)
|
@@ -214,7 +217,7 @@ module PrometheusConfigBuilder
|
|
214
217
|
files = []
|
215
218
|
@paths.each do |path|
|
216
219
|
found_files = @discoverer.discover(path)
|
217
|
-
logger.info("Found #{
|
220
|
+
logger.info("Found #{found_files.length} files from path #{path}")
|
218
221
|
files.push(*found_files)
|
219
222
|
end
|
220
223
|
|
@@ -224,6 +227,8 @@ module PrometheusConfigBuilder
|
|
224
227
|
cfs.add(cf)
|
225
228
|
end
|
226
229
|
|
230
|
+
@@config_files.observe(files.length)
|
231
|
+
|
227
232
|
rules_dir = @dst_dir + "/rules"
|
228
233
|
scrape_files_dir = @dst_dir + "/scrape_files"
|
229
234
|
cfs.set_rules_dir(rules_dir)
|
@@ -23,23 +23,7 @@ module PrometheusConfigBuilder
|
|
23
23
|
})
|
24
24
|
$VERBOSE = x
|
25
25
|
tasks = get_tasks(config["cluster"], config["service"])
|
26
|
-
|
27
|
-
|
28
|
-
targets = []
|
29
|
-
ips.each do |ip|
|
30
|
-
if config["metrics_port"]
|
31
|
-
targets << ip + ":" + config["metrics_port"].to_s
|
32
|
-
else
|
33
|
-
targets << ip
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
data = [
|
38
|
-
{
|
39
|
-
"targets" => targets,
|
40
|
-
"labels" => config["labels"]
|
41
|
-
}
|
42
|
-
]
|
26
|
+
endpoints = get_task_endpoints(config["cluster"], tasks, config["labels"], config["metrics_port"])
|
43
27
|
|
44
28
|
if !config["job_name"]
|
45
29
|
logger.warn("File #{basename}: the scrape_configs of type:ecs-tasks doesn't have \"job_name\" field set. Ignoring!")
|
@@ -48,7 +32,7 @@ module PrometheusConfigBuilder
|
|
48
32
|
|
49
33
|
file = File.expand_path(dst_prefix + "_" + config["job_name"] + ".json")
|
50
34
|
File.open(file, "w") do |file|
|
51
|
-
file.write(
|
35
|
+
file.write(endpoints.to_json)
|
52
36
|
end
|
53
37
|
|
54
38
|
# Make copy of the settings and remove our custom properties from it.
|
@@ -96,8 +80,8 @@ module PrometheusConfigBuilder
|
|
96
80
|
return tasks
|
97
81
|
end
|
98
82
|
|
99
|
-
def self.
|
100
|
-
|
83
|
+
def self.get_task_endpoints(cluster, tasks, common_labels, metrics_port)
|
84
|
+
endpoints = []
|
101
85
|
task_chunk = tasks.pop(100)
|
102
86
|
loop do
|
103
87
|
begin
|
@@ -110,7 +94,16 @@ module PrometheusConfigBuilder
|
|
110
94
|
result.tasks.each do |task|
|
111
95
|
# FIXME: This assumes somewhat on the ip structure.
|
112
96
|
ip = task.containers[0].network_interfaces[0].private_ipv_4_address
|
113
|
-
|
97
|
+
|
98
|
+
if metrics_port
|
99
|
+
ip = ip + ":" + metrics_port.to_s
|
100
|
+
end
|
101
|
+
labels = common_labels.clone
|
102
|
+
labels["ecs_arn"] = task.task_arn
|
103
|
+
endpoints << {
|
104
|
+
"targets" => [ip],
|
105
|
+
"labels" => labels
|
106
|
+
}
|
114
107
|
end
|
115
108
|
end
|
116
109
|
rescue Aws::ECS::Errors::ServiceError => e
|
@@ -121,7 +114,7 @@ module PrometheusConfigBuilder
|
|
121
114
|
break if tasks.length == 0
|
122
115
|
task_chunk = tasks.pop(100)
|
123
116
|
end
|
124
|
-
return
|
117
|
+
return endpoints
|
125
118
|
end
|
126
119
|
|
127
120
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'prometheus-config-builder'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.16'
|
7
7
|
s.date = Time.now
|
8
8
|
|
9
9
|
s.summary = %q{Template based config generation}
|
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_ruby_version = '>= 2.0.0'
|
17
17
|
|
18
18
|
s.add_dependency 'aws-sdk', '~> 3'
|
19
|
+
s.add_dependency 'prometheus_exporter', '>= 0.4.13'
|
19
20
|
|
20
21
|
s.add_development_dependency 'rubygems-tasks', '~> 0.2'
|
21
22
|
s.add_development_dependency 'minitest', '~> 5.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prometheus-config-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juho Mäkinen juho.makinen@gmail.com
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: prometheus_exporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.13
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.13
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubygems-tasks
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
137
|
version: '0'
|
124
138
|
requirements: []
|
125
139
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.5.2
|
140
|
+
rubygems_version: 2.5.2.3
|
127
141
|
signing_key:
|
128
142
|
specification_version: 4
|
129
143
|
summary: Template based config generation
|