Class: PrometheusConfigBuilder::ConfigFile
- Inherits:
-
Object
- Object
- PrometheusConfigBuilder::ConfigFile
- Includes:
- PrometheusConfigBuilderLogger
- Defined in:
- lib/prometheus-config-builder/prometheus-config-builder.rb
Instance Attribute Summary collapse
-
#basename ⇒ Object
readonly
Returns the value of attribute basename.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#runbook_url ⇒ Object
readonly
Returns the value of attribute runbook_url.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #config_rules ⇒ Object
- #get_scrape_configs(dst_prefix) ⇒ Object
- #load(file) ⇒ Object
- #open(filename) ⇒ Object
- #scrape_configs ⇒ Object
- #write_rules(path) ⇒ Object
Methods included from PrometheusConfigBuilderLogger
Instance Attribute Details
#basename ⇒ Object (readonly)
Returns the value of attribute basename.
31 32 33 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 31 def basename @basename end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
33 34 35 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 33 def owner @owner end |
#runbook_url ⇒ Object (readonly)
Returns the value of attribute runbook_url.
34 35 36 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 34 def runbook_url @runbook_url end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
32 33 34 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 32 def source @source end |
Instance Method Details
#config_rules ⇒ Object
64 65 66 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 64 def config_rules @data['config_rules'] end |
#get_scrape_configs(dst_prefix) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 72 def get_scrape_configs(dst_prefix) configs = [] @data['scrape_configs'].each do |config| case config["type"] when "passthrough" configs << ScrapeConfigPassthrough::handle(config) when "ecs-tasks" configs << ScrapeConfigECS::handle(@basename, config, dst_prefix) else raise "Unknown scrape_config type #{config["type"]} in file #{@basename}" end end return configs end |
#load(file) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 46 def load(file) @source = file[:source] @basename = file[:filename] begin @data = YAML.load(file[:contents]) rescue Exception => e logger.error("Error while decoding YAML from file #{file[:source]}") if match = e..match(/mapping values are not allowed in this context at line ([0-9]+)/i) linenumber = match.captures[0] logger.error("This error is most often because your intentation is at the wrong level. Check the file #{file[:filename]} around line #{linenumber}") end raise e end @owner = @data['owner'] @runbook_url = @data['runbook_url'] end |
#open(filename) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 36 def open(filename) @filename = File.(filename) @source = "file://#{filename}" @basename = File.basename(filename) @data = YAML.load_file(filename) @owner = @data['owner'] @runbook_url = @data['runbook_url'] end |
#scrape_configs ⇒ Object
68 69 70 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 68 def scrape_configs @data['scrape_configs'] end |
#write_rules(path) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/prometheus-config-builder/prometheus-config-builder.rb', line 89 def write_rules(path) filename = path + "/" + @basename File.open(filename, "w") do |file| file.write("# AUTOGENERATED FILE, DO NOT MODIFY\n") file.write("#\n") file.write("# This file was automatically generated by prometheus-config-from-s3 at #{Time.now.utc.iso8601}\n") file.write("# based on #{@source}\n") file.write("#\n\n") file.write(config_rules.to_yaml) end return Digest::SHA256.digest config_rules.to_yaml end |