From 39f7708bfdfdc92b8710672ba216aab64e27630f Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Tue, 3 Mar 2020 14:34:14 +0000 Subject: Added metric prefix --- lib/jobs/slurm_job_states.rb | 2 +- lib/longboat/collector.rb | 4 +++- lib/longboat/config.rb | 9 ++++++--- lib/longboat/jobs.rb | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) (limited to 'lib') 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 -- cgit v1.2.1