diff options
author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-11-16 12:25:42 +0000 |
---|---|---|
committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-11-16 12:25:42 +0000 |
commit | 96b8a92fc11d094eedc24bf9b3f76a230d654416 (patch) | |
tree | 4788565ba5ce65cd40d0aa9f967eb44c4d63c665 /examples/test_config.rb | |
parent | 622a1770df1baa13c02f155cde3301306c8f8be0 (diff) |
Better examples
Diffstat (limited to 'examples/test_config.rb')
-rw-r--r-- | examples/test_config.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/test_config.rb b/examples/test_config.rb new file mode 100644 index 0000000..b5a1418 --- /dev/null +++ b/examples/test_config.rb @@ -0,0 +1,33 @@ +require 'yaml' + +class TestConfig + def initialize(collector, config) + @collector = collector + @config = config + @config.merge!(Longboat::Config.for_raider do + opt :test_config, "Config file for test_config", type: String + end) + + @name = "configurable_value" + @config_file = {} + @config_file = YAML.load_file(@config[:test_config]) if @config[:test_config] + end + + def raid + # Clean up any previously reported metrics + # to prevent stale labelsets + @collector.redact!(@name) + + # Report new metrics + value = @config_file["configurable_value"] || 4 + @collector.report!( + @name, + value, + help: "A value specified on the command line at runtime", + type: "gauge", + labels: { + given: @config[:test_config_given] ? 1 : 0 + } + ) + end +end |