checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA1:
3
- metadata.gz: 3fba25e075f3d0ab7b0a90f69c18f4541d639b9e
4
- data.tar.gz: 289c252c3c5a426dc8ec830c6c3dd8a33e0852b4
3
+ metadata.gz: 7b091e64ec338a673b726872bf72db278470f2dc
4
+ data.tar.gz: 3b2ec91cd1437b01b04cc4f221bacfd6a01f953c
5
5
SHA512:
6
- metadata.gz: ed177e37bade0ad6efb8a22f36d856529f72a8eedc88dffd7b9fac1cd6110ef0f371c3837ee56d760fc09a719df9d957af88cbd7951de29e1b7cc89fe522e492
7
- data.tar.gz: 965acc78063f5cb7364b5e16f4289ea8f4590bc97b2a2615da6a7405bbd1deadb86c49d273e83ec13cd349852469d53c7ddb7d5c5d7f91bdf99a4d72f7f811b6
6
+ metadata.gz: 9d77a5e66080e86f60637b161a4aa5ef8c5880a1af2f43eedce67418ab95cb4d941e675148856510e95f6164217df1567a6ad3eb3bd1f1af55e38822f60a7145
7
+ data.tar.gz: 9e862045c6aa38b43a8312715b8d6f4abc064e36a6f59af19ddbd64b23faffadee9f409b376b43ad2fd92dd68fdf490b3577ca21aec349704d5652bf1e6d08e6
data/bin/prometheus-config-builder CHANGED
@@ -76,11 +76,9 @@ loop do
76
76
77
77
# Send a SIGHUP signal to Prometheus so that it knows to reload config files
78
78
if something_changed && config[:pgrep] != nil
79
- pid = `pgrep -f "#{config[pgrep]}"`.split("\n").first.to_i
79
+ pid = `pgrep -f "#{config[:pgrep]}"`.split("\n").first.to_i
80
80
if pid
81
- if first_run
81
+ log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
82
- log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
83
- end
84
82
Process.kill "HUP", pid
85
83
end
86
84
end
data/lib/prometheus-config-builder/prometheus-config-builder.rb CHANGED
@@ -176,7 +176,7 @@ module PrometheusConfigBuilder
176
176
end
177
177
178
178
if @rules_dir != nil && !data["rule_files"].include?(@rules_dir)
179
- data["rule_files"] << File.expand_path(@rules_dir)
179
+ data["rule_files"] << File.expand_path(@rules_dir) + "/*.yaml"
180
180
end
181
181
182
182
File.open(destination, "w") do |file|
@@ -200,20 +200,25 @@ module PrometheusConfigBuilder
200
200
@dst_dir = dst_dir
201
201
202
202
@discoverer = ConfigDiscover.new
203
- @files = []
203
+ @paths = []
204
204
@last_hash = ""
205
205
end
206
206
207
207
def add_path(path)
208
- files = @discoverer.discover(path)
208
+ @paths << path
209
- logger.info("Found #{files.length} files from path #{path}")
210
- @files.push(*files)
211
209
end
212
210
213
211
def write_out
214
212
hash = ""
215
213
cfs = ConfigFiles.new(@prometheus_src)
216
- @files.each do |file|
214
+ files = []
215
+ @paths.each do |path|
216
+ found_files = @discoverer.discover(path)
217
+ logger.info("Found #{files.length} files from path #{path}")
218
+ files.push(*found_files)
219
+ end
220
+
221
+ files.each do |file|
217
222
cf = ConfigFile.new
218
223
cf.load(file)
219
224
cfs.add(cf)
data/lib/prometheus-config-builder/scrape_ecs.rb CHANGED
@@ -25,32 +25,49 @@ module PrometheusConfigBuilder
25
25
tasks = get_tasks(config["cluster"], config["service"])
26
26
ips = get_task_ips(config["cluster"], tasks)
27
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
+
28
37
data = [
29
38
{
30
- "targets" => ips,
39
+ "targets" => targets,
31
40
"labels" => config["labels"]
32
41
}
33
42
]
34
43
35
- if !config["name"]
36
- logger.warn("File #{basename}: the scrape_configs of type:ecs-tasks doesn't have \"name\" field set. Ignoring!")
44
+ if !config["job_name"]
45
+ logger.warn("File #{basename}: the scrape_configs of type:ecs-tasks doesn't have \"job_name\" field set. Ignoring!")
37
46
return nil
38
47
end
39
48
40
- file = File.expand_path(dst_prefix + "_" + config["name"] + ".json")
49
+ file = File.expand_path(dst_prefix + "_" + config["job_name"] + ".json")
41
50
File.open(file, "w") do |file|
42
51
file.write(data.to_json)
43
52
end
44
53
45
- return {
46
- "job_name" => config["name"],
47
- "metrics_path" => config["metrics_path"],
48
- "file_sd_configs":{
49
- "files" => [
50
- file
51
- ]
52
- }
53
- }
54
+ # Make copy of the settings and remove our custom properties from it.
55
+ # The rest user can set just as he wants according to the Prometheus schema.
56
+ # See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
57
+ settings = config.clone
58
+ settings.delete("type")
59
+ settings.delete("cluster")
60
+ settings.delete("service")
61
+ settings.delete("metrics_port")
62
+ settings.delete("labels")
63
+ settings.delete("region")
64
+ settings["file_sd_configs"] = [
65
+ "files" => [
66
+ file
67
+ ]
68
+ ]
69
+
70
+ return settings
54
71
end
55
72
56
73
def self.get_tasks(cluster, service_name)
data/lib/prometheus-config-builder/scrape_passthrough.rb CHANGED
@@ -2,7 +2,9 @@ module PrometheusConfigBuilder
2
2
3
3
class ScrapeConfigPassthrough
4
4
def self.handle(config)
5
- return config["config"]
5
+ settings = config.clone
6
+ settings.delete("type")
7
+ return settings
6
8
end
7
9
end
8
10
data/prometheus-config-builder.gemspec CHANGED
@@ -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'
6
+ s.version = '0.0.11'
7
7
s.date = Time.now
8
8
9
9
s.summary = %q{Template based config generation}
data/test/data/test1.yaml CHANGED
@@ -1,9 +1,8 @@
1
1
scrape_configs:
2
2
- type: passthrough
3
- config:
4
- job_name: discovery 1
5
- static_configs:
3
+ job_name: discovery 1
4
+ static_configs:
5
+ - targets: ['localhost:9090']
6
- - targets: ['localhost:9090']
7
6
8
7
9
8
config_rules:
data/test/data/test2.yaml CHANGED
@@ -1,9 +1,8 @@
1
1
scrape_configs:
2
2
- type: passthrough
3
- config:
4
- job_name: discovery 2
5
- static_configs:
3
+ job_name: discovery 2
4
+ static_configs:
5
+ - targets: ['localhost:9090']
6
- - targets: ['localhost:9090']
7
6
8
7
9
8
config_rules:
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.6
4
+ version: 0.0.11
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-09-09 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: aws-sdk