checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA1:
3
- metadata.gz: 340fb2c178ee3bf0c32782ba335a46500dbdafd4
4
- data.tar.gz: 327af98c341fdcdfecadfe29ac00716f12fda348
3
+ metadata.gz: bfa7f8b751a05fb855f1b09da6903620025d56cb
4
+ data.tar.gz: 6500d5cc5e0afa9ba17d9fafc629efa095214db4
5
5
SHA512:
6
- metadata.gz: d32eb0c5cf9a5c657dab7305490f1f73d2101151670da96822c1581c4de6362fca2109018d1af1cb5dbea081a41145f7aec40d62866f4b4a834201e133d7ce0d
7
- data.tar.gz: bd94a8ea5f20bd18305b1e7a075484fb0287805f425df8df04f469923de74b69db6dab3778918b3aa6c599df1f5b0220780c3f0d1ec86bdb96766d0981b48afb
6
+ metadata.gz: 88f680b791fe6aa290e11fd23512ef5e2808728d26989cadb4c6de8131fbffe4e5f552e78ecc1cdb6b2476a44c43762c5e517fb8b4e112c9bb0622bcd1a1d0a1
7
+ data.tar.gz: 753b906d6d578f68020a4d83deb8e7c9d21c6f05e5f2766eedf185b8739a8480744e7be35f1bbaf364f4caf3e2b133b0382915b1626414565166fb6ff3a9632f
data/bin/prometheus-config-builder CHANGED
@@ -39,7 +39,7 @@ op = OptionParser.new do |o|
39
39
config[:verbose] = true
40
40
end
41
41
o.on('--every=[seconds]', 'Rerun every n seconds') do |seconds|
42
- config[:every] = seconds
42
+ config[:every] = seconds.to_i
43
43
end
44
44
o.on('--pgrep=[string]', 'pgrep -f [string] for finding Prometheus process for SIGHUP') do |str|
45
45
config[:pgrep] = str
@@ -52,7 +52,7 @@ if config[:verbose]
52
52
end
53
53
54
54
abort "You need to set --prometheus-src" if !config[:prometheus_src]
55
- abort "You need to set --dst_dir" if !config[:dst_dir]
55
+ abort "You need to set --dst-dir" if !config[:dst_dir]
56
56
57
57
log = Logger.new(STDOUT)
58
58
log.level = config[:verbose] ? Logger::DEBUG : Logger::INFO
@@ -75,12 +75,14 @@ something_changed_count = PrometheusExporter::Client.default.register(:counter,
75
75
error_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_errors_count", "Number of exceptions during evaluation.")
76
76
iteration_count = PrometheusExporter::Client.default.register(:counter, "prometheusconfigbuilder_iteration_count", "Number of times configuration has changed.")
77
77
iteration_duration = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_last_iteration_duration", "Duration (in seconds) of the last full config iteration")
78
+ config_has_errors = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_config_has_errors", "This value is 0 if the config has no errors.")
78
79
79
80
error_count.observe(0)
80
81
81
82
builder = PrometheusConfigBuilder::Builder.new(config[:prometheus_src], config[:dst_dir])
82
83
83
84
config[:paths].each do |path|
85
+ log.info("Adding path #{path} to config discovery list")
84
86
builder.add_path(path)
85
87
end
86
88
@@ -89,7 +91,9 @@ loop do
89
91
starting = Time.now
90
92
begin
91
93
something_changed = builder.write_out()
94
+ config_has_errors.set(0)
92
95
rescue Exception => e
96
+ config_has_errors.set(1)
93
97
log.warn("Error while building config: #{e}")
94
98
puts e.backtrace
95
99
error_count.increment
@@ -101,12 +105,23 @@ loop do
101
105
iteration_count.increment
102
106
103
107
# Send a SIGHUP signal to Prometheus so that it knows to reload config files
104
- if something_changed && config[:pgrep] != nil
105
- pid = `pgrep -f "#{config[:pgrep]}"`.split("\n").first.to_i
106
- if pid
107
- log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
108
- Process.kill "HUP", pid
108
+ begin
109
+ if something_changed && config[:pgrep] != nil
110
+ matches = `pgrep -a -f "#{config[:pgrep]}"`.split("\n")
111
+ match = matches.select {|e| !e.include?("prometheus-config-builder")}
112
+ if !match
113
+ log.warn("Unable to find Prometheus instance to send SIGHUP for. Matches object: #{matches}")
114
+ else
115
+ pid = match.first.split(" ").first.to_i
116
+ if pid
117
+ log.info("Sending SIGHUP signal to Prometheus at pid #{pid}.")
118
+ Process.kill "HUP", pid
119
+ end
120
+ end
109
121
end
122
+ rescue Exception => e
123
+ log.warn("Unable to send SIGHUP signal to Prometheus: #{e}")
124
+ puts e.backtrace
110
125
end
111
126
112
127
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.13'
6
+ s.version = '0.0.19'
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.13
4
+ version: 0.0.19
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