checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA1:
3
- metadata.gz: 37a41a4e9ee37b38bd8bc7c7025c60732aa7b5f9
4
- data.tar.gz: 98ccfbd194f736ff97ead53a8fc5ccf12b20f9f1
3
+ metadata.gz: 118617063dde0e331c4daa50346cd14d6d4b2a9e
4
+ data.tar.gz: 3117b906a6c14141acb26b9bc1d1a5d2e57852e9
5
5
SHA512:
6
- metadata.gz: 11c610a52b55816774141a432b0c4e527d3b076b8e6cdef200dcb3b4d0084699dbab2dcf422d497826f9f0f57b24f3e3d141168de5c9dbcf84f86982dd11e5e5
7
- data.tar.gz: 7c958b3d7fce912530951fd10c6ce16cee716528666d01a6a925b2deda8179abe7055e07d1522c82c54958f65bc112e4f71131bd69060a7f132e555cdb69b0db
6
+ metadata.gz: eb9cd3a884df86eb1ff0946f3b7761653a1ebb523fc2704d4594096a2661b9f2417e96366e20c581b045deaf24daeee7a7c8bc5c2383dc402d889c9662f833c4
7
+ data.tar.gz: ac0d13daee07147c78cf29119097632dcb6461acb385b5fc12b3add3a7a86eed3df7897c48429c1a530fbb1bfb822612cfd77b7e392f54208cebaf7697846d88
data/bin/prometheus-config-builder CHANGED
@@ -18,17 +18,6 @@ config[:root] ||= 'test/data'
18
18
config[:every] = 60
19
19
config[:pgrep] = nil
20
20
21
- server = PrometheusExporter::Server::WebServer.new port: 12345
22
- PrometheusExporter::Client.default = PrometheusExporter::LocalClient.new(collector: server.collector)
23
- server.start
24
-
25
- something_changed_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_changes_count", "Number of times configuration has changed.")
26
- error_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_errors_count", "Number of exceptions during evaluation.")
27
- iteration_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_iteration_count", "Number of times configuration has changed.")
28
- iteration_duration = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_last_iteration_duration", "Duration (in seconds) of the last full config iteration")
29
-
30
- error_count.observe(0)
31
-
32
21
# Defaults
33
22
op = OptionParser.new do |o|
34
23
o.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
@@ -50,7 +39,7 @@ op = OptionParser.new do |o|
50
39
config[:verbose] = true
51
40
end
52
41
o.on('--every=[seconds]', 'Rerun every n seconds') do |seconds|
53
- config[:every] = seconds
42
+ config[:every] = seconds.to_i
54
43
end
55
44
o.on('--pgrep=[string]', 'pgrep -f [string] for finding Prometheus process for SIGHUP') do |str|
56
45
config[:pgrep] = str
@@ -63,7 +52,7 @@ if config[:verbose]
63
52
end
64
53
65
54
abort "You need to set --prometheus-src" if !config[:prometheus_src]
66
- abort "You need to set --dst_dir" if !config[:dst_dir]
55
+ abort "You need to set --dst-dir" if !config[:dst_dir]
67
56
68
57
log = Logger.new(STDOUT)
69
58
log.level = config[:verbose] ? Logger::DEBUG : Logger::INFO
@@ -78,9 +67,21 @@ if !File.exist?(config[:dst_dir])
78
67
exit!(1)
79
68
end
80
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
+
81
81
builder = PrometheusConfigBuilder::Builder.new(config[:prometheus_src], config[:dst_dir])
82
82
83
83
config[:paths].each do |path|
84
+ log.info("Adding path #{path} to config discovery list")
84
85
builder.add_path(path)
85
86
end
86
87
@@ -91,7 +92,9 @@ loop do
91
92
something_changed = builder.write_out()
92
93
rescue Exception => e
93
94
log.warn("Error while building config: #{e}")
95
+ puts e.backtrace
94
96
error_count.increment
97
+ sleep(config[:every])
95
98
next
96
99
end
97
100
@@ -99,12 +102,23 @@ loop do
99
102
iteration_count.increment
100
103
101
104
# Send a SIGHUP signal to Prometheus so that it knows to reload config files
102
- if something_changed && config[:pgrep] != nil
103
- pid = `pgrep -f "#{config[:pgrep]}"`.split("\n").first.to_i
104
- if pid
105
- log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
106
- Process.kill "HUP", pid
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
+ if !match
110
+ log.warn("Unable to find Prometheus instance to send SIGHUP for. Matches object: #{matches}"
111
+ else
112
+ pid = match.first.split(" ").first.to_i
113
+ if pid
114
+ log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
115
+ Process.kill "HUP", pid
116
+ end
117
+ end
107
118
end
119
+ rescue Exception => e
120
+ log.warn("Unable to send SIGHUP signal to Prometheus: #{e}")
121
+ puts e.backtrace
108
122
end
109
123
110
124
log.info("Sleeping for #{config[:every]} second and starting then again.")
data/lib/prometheus-config-builder/prometheus-config-builder.rb CHANGED
@@ -217,7 +217,7 @@ module PrometheusConfigBuilder
217
217
files = []
218
218
@paths.each do |path|
219
219
found_files = @discoverer.discover(path)
220
- logger.info("Found #{files.length} files from path #{path}")
220
+ logger.info("Found #{found_files.length} files from path #{path}")
221
221
files.push(*found_files)
222
222
end
223
223
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.12'
6
+ s.version = '0.0.17'
7
7
s.date = Time.now
8
8
9
9
s.summary = %q{Template based config generation}
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.12
4
+ version: 0.0.17
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-11 00:00:00.000000000 Z
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: aws-sdk
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
version: '0'
138
138
requirements: []
139
139
rubyforge_project:
140
- rubygems_version: 2.5.2
140
+ rubygems_version: 2.5.2.3
141
141
signing_key:
142
142
specification_version: 4
143
143
summary: Template based config generation