aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/jobs/slurm_job_states.rb2
-rw-r--r--lib/longboat/collector.rb4
-rw-r--r--lib/longboat/config.rb9
-rw-r--r--lib/longboat/jobs.rb2
-rwxr-xr-xlongboat2
5 files changed, 12 insertions, 7 deletions
diff --git a/lib/jobs/slurm_job_states.rb b/lib/jobs/slurm_job_states.rb
index 9d4ea94..cef5ed6 100644
--- a/lib/jobs/slurm_job_states.rb
+++ b/lib/jobs/slurm_job_states.rb
@@ -16,7 +16,7 @@ class SlurmJobStates
tally.each do |state, number|
@collector.report!(
- "longboat_slurm_job_states",
+ "slurm_job_states",
number,
help: "Number of jobs in each state",
type: "gauge",
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
diff --git a/longboat b/longboat
index 00e4ce5..ee7bfa9 100755
--- a/longboat
+++ b/longboat
@@ -7,7 +7,7 @@ require 'longboat'
config = Longboat::Config.parse!
# Start collection
-collector = Longboat::Collector.new
+collector = Longboat::Collector.new(config)
jobs = Longboat::Jobs.new(collector, config)
jobs.load!
t = jobs.collect_every