aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Readme.textile31
-rw-r--r--examples/test_config.rb33
-rw-r--r--examples/test_config.yaml3
-rw-r--r--examples/test_fixed.rb20
-rw-r--r--examples/test_histo.rb41
-rw-r--r--examples/test_random.rb63
6 files changed, 161 insertions, 30 deletions
diff --git a/Readme.textile b/Readme.textile
index 320a094..8744307 100644
--- a/Readme.textile
+++ b/Readme.textile
@@ -79,35 +79,6 @@ For summaries, the value is a hash containing:
* @count@: The total number of observations
* @sum@: The sum of all observations
-h4. Example
-
-bc.. class Test
- def initialize(collector, config)
- @collector = collector
- @config = config
- end
-
- def raid
- # Do something useful
- val = 4
-
- # Clean up any previously reported metrics
- # to prevent stale labelsets
- @collector.redact!("value")
-
- # Report new metrics
- @collector.report!(
- "value",
- val,
- help: "A fixed value",
- type: "gauge",
- labels: {
- subvalue: 3
- }
- )
- end
-end
-
h3. Raider config
Longboat offers the @Longboat::Config.for_raider@ primitive to allow raiders to get command line arguments at runtime. It takes a block which is passed wholesale to @Optimist::Parser.new@, and returns a hash of parsed arguments. For more information see the "documentation":https://github.com/ManageIQ/optimist "for":https://www.manageiq.org/optimist/ "Optimist":https://github.com/ManageIQ/optimist/wiki.
@@ -130,4 +101,4 @@ The <code>@my_config</code> hash will look like:
bc. {:myraider_an_argument => true, :myraider_an_argument_given => true}
-Be aware that there's no namespacing between raider arguments, so it's recommended that you prefix your argument with the raider's name, such as @--myraider-an-argument@. Also be aware that the automatic short-options are very likely to clash horribly, so try to avoid using these.
+Be aware that there's no namespacing between raider arguments, so it's recommended that you prefix your argument with the raider's name, such as @--myraider-an-argument@. Also be aware that the automatic short-options are very likely to clash horribly, so try to avoid using these. Finally There is presently no way to get help about raider arguments.
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
diff --git a/examples/test_config.yaml b/examples/test_config.yaml
new file mode 100644
index 0000000..8073a84
--- /dev/null
+++ b/examples/test_config.yaml
@@ -0,0 +1,3 @@
+{
+ "configurable_value": 6
+}
diff --git a/examples/test_fixed.rb b/examples/test_fixed.rb
new file mode 100644
index 0000000..e6be609
--- /dev/null
+++ b/examples/test_fixed.rb
@@ -0,0 +1,20 @@
+class TestFixed
+ def initialize(collector, config)
+ @collector = collector
+ @config = config
+ end
+
+ def raid
+ # Clean up any previously reported metrics
+ # to prevent stale labelsets
+ @collector.redact!("fixed_value")
+
+ # Report new metrics
+ @collector.report!(
+ "fixed_value",
+ 4,
+ help: "A fixed value",
+ type: "gauge"
+ )
+ end
+end
diff --git a/examples/test_histo.rb b/examples/test_histo.rb
new file mode 100644
index 0000000..ed3fb01
--- /dev/null
+++ b/examples/test_histo.rb
@@ -0,0 +1,41 @@
+class TestHisto
+ def initialize(collector, config)
+ @collector = collector
+ @config = config
+ end
+
+ def raid
+ # Clean up any previously reported metrics
+ # to prevent stale labelsets
+ @collector.redact!("histo")
+ @collector.redact!("summ")
+
+ # Report new metrics
+ @collector.report!(
+ "histo",
+ {
+ buckets: {
+ 0.5 => 1,
+ 1 => 2
+ },
+ count: 3,
+ sum: 3
+ },
+ help: "A histogram over the data [0.25, 0.75, 2]",
+ type: "histogram"
+ )
+ @collector.report!(
+ "summ",
+ {
+ quantiles: {
+ 0.5 => 5,
+ 0.95 => 9.5
+ },
+ count: 21,
+ sum: 105
+ },
+ help: "A summary of data (0..10).step(0.5)",
+ type: "summary"
+ )
+ end
+end
diff --git a/examples/test_random.rb b/examples/test_random.rb
new file mode 100644
index 0000000..89a7acd
--- /dev/null
+++ b/examples/test_random.rb
@@ -0,0 +1,63 @@
+class TestRandom
+ def initialize(collector, config)
+ @collector = collector
+ @config = config
+ end
+
+ def raid
+ # Clean up any previously reported metrics
+ # to prevent stale labelsets
+ @collector.redact!("die_roll")
+
+ # Report new metrics
+ @collector.report!(
+ "die_roll",
+ rand(4) + 1,
+ help: "A random value from 1 to 4 inclusive",
+ type: "gauge",
+ labels: { die: "d4" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(6) + 1,
+ help: "A random value from 1 to 6 inclusive",
+ type: "gauge",
+ labels: { die: "d6" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(8) + 1,
+ help: "A random value from 1 to 8 inclusive",
+ type: "gauge",
+ labels: { die: "d8" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(10) + 1,
+ help: "A random value from 1 to 10 inclusive",
+ type: "gauge",
+ labels: { die: "d10" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(12) + 1,
+ help: "A random value from 1 to 12 inclusive",
+ type: "gauge",
+ labels: { die: "d12" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(20) + 1,
+ help: "A random value from 1 to 20 inclusive",
+ type: "gauge",
+ labels: { die: "d20" }
+ )
+ @collector.report!(
+ "die_roll",
+ rand(100) + 1,
+ help: "A random value from 1 to 100 inclusive",
+ type: "gauge",
+ labels: { die: "d%" }
+ )
+ end
+end