Class: PrometheusConfigBuilder::Builder
- Inherits:
-
Object
- Object
- PrometheusConfigBuilder::Builder
- Includes:
- PrometheusConfigBuilderLogger
- Defined in:
- lib/prometheus-config-builder/prometheus-config-builder.rb
Instance Method Summary collapse
- #add_path(path) ⇒ Object
-
#initialize(prometheus_src, dst_dir) ⇒ Builder
constructor
A new instance of Builder.
- #write_out ⇒ Object
Methods included from PrometheusConfigBuilderLogger
Constructor Details
#initialize(prometheus_src, dst_dir) ⇒ Builder
Returns a new instance of Builder.
198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 198 def initialize(prometheus_src, dst_dir) @prometheus_src = prometheus_src @dst_dir = dst_dir @discoverer = ConfigDiscover.new @paths = [] @last_hash = "" @@config_files = PrometheusExporter::Client.default.register(:gauge, "prometheusconfigbuilder_config_files", "Number of found config files") end |
Instance Method Details
#add_path(path) ⇒ Object
210 211 212 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 210 def add_path(path) @paths << path end |
#write_out ⇒ Object
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 214 def write_out hash = "" cfs = ConfigFiles.new(@prometheus_src) files = [] @paths.each do |path| found_files = @discoverer.discover(path) logger.info("Found #{found_files.length} files from path #{path}") files.push(*found_files) end files.each do |file| cf = ConfigFile.new cf.load(file) cfs.add(cf) end @@config_files.observe(files.length) rules_dir = @dst_dir + "/rules" scrape_files_dir = @dst_dir + "/scrape_files" cfs.set_rules_dir(rules_dir) cfs.set_scrape_files_dir(scrape_files_dir) hash += cfs.write_prometheus_yaml(@dst_dir + "/prometheus.yaml", scrape_files_dir) FileUtils.mkdir_p(rules_dir) unless File.exist?(rules_dir) FileUtils.mkdir_p(scrape_files_dir) unless File.exist?(scrape_files_dir) hash += cfs.write_rules(rules_dir) # Determine if something had changed since the last write_out based on the generated hashes if hash != @last_hash @last_hash = hash return true else return false end end |