From 96b8a92fc11d094eedc24bf9b3f76a230d654416 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 16 Nov 2020 12:25:42 +0000 Subject: Better examples --- examples/test_config.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/test_config.rb (limited to 'examples/test_config.rb') 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 -- cgit v1.2.1