diff options
author | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-03 14:34:14 +0000 |
---|---|---|
committer | Nat Lasseter <nat.lasseter@york.ac.uk> | 2020-03-03 14:34:14 +0000 |
commit | 39f7708bfdfdc92b8710672ba216aab64e27630f (patch) | |
tree | cbe3920f2a31aa8725ce850ebf92b0eaab04dd52 /lib/longboat | |
parent | ab6e28417a9195fe03b8355a808a81276d0435ff (diff) |
Added metric prefix
Diffstat (limited to 'lib/longboat')
-rw-r--r-- | lib/longboat/collector.rb | 4 | ||||
-rw-r--r-- | lib/longboat/config.rb | 9 | ||||
-rw-r--r-- | lib/longboat/jobs.rb | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/lib/longboat/collector.rb b/lib/longboat/collector.rb index c812b05..d1a5d93 100644 --- a/lib/longboat/collector.rb +++ b/lib/longboat/collector.rb @@ -1,10 +1,12 @@ module Longboat class Collector - def initialize + def initialize(config) @metrics = {} + @config = config end def report!(name, value, help: nil, type: nil, labels: {}, timestamp: Time.now) + name = "#{@config[:metric_prefix]}#{name}" @metrics[name] ||= {help: help, type: type} @metrics[name][labels] = {value: value, timestamp: timestamp} end diff --git a/lib/longboat/config.rb b/lib/longboat/config.rb index 874a5be..8f4907c 100644 --- a/lib/longboat/config.rb +++ b/lib/longboat/config.rb @@ -5,11 +5,14 @@ module Longboat def self.parse! Optimist::options do # Collection interval - opt :collect_every, "Collection interval", type: Integer, default: 60 + opt :collect_every, "Collection interval", type: Integer, default: 60 + + # Job data + opt :metric_prefix, "Prefix for metric names", type: String, default: "longboat_" # Sinatra server - opt :server_bind, "Server listening address", type: String, default: "127.0.0.1:8564" - opt :server_path, "Path to metrics", type: String, default: "/metrics" + opt :server_bind, "Server listening address", type: String, default: "127.0.0.1:8564" + opt :server_path, "Path to metrics", type: String, default: "/metrics" end end end diff --git a/lib/longboat/jobs.rb b/lib/longboat/jobs.rb index 86d3c64..f0ada5a 100644 --- a/lib/longboat/jobs.rb +++ b/lib/longboat/jobs.rb @@ -41,7 +41,7 @@ module Longboat private def job_config - @config.slice(:collect_every) + @config.slice(:collect_every, :metric_prefix) end end end |