From d166a073ad3a32af77152bf4b16206c32f9890b6 Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Tue, 17 Mar 2020 10:14:18 +0000 Subject: Initial commit: broke out from longboat --- .gitignore | 1 + LICENSE | 11 +++++++++++ Readme.textile | 3 +++ slurm_job_states.rb | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Readme.textile create mode 100644 slurm_job_states.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1377554 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.swp diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3f1412f --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +Copyright 2020 University of York + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Readme.textile b/Readme.textile new file mode 100644 index 0000000..ee9354c --- /dev/null +++ b/Readme.textile @@ -0,0 +1,3 @@ +h1. Viking Raiders + +p. This repo contains the "longboat":https://bitbucket.org/nl987/longboat raiders for Viking at the UoY. diff --git a/slurm_job_states.rb b/slurm_job_states.rb new file mode 100644 index 0000000..20b69c8 --- /dev/null +++ b/slurm_job_states.rb @@ -0,0 +1,41 @@ +class SlurmJobStates + def initialize(collector, config) + @collector = collector + @interval = config[:raid_every] + end + + def raid + start_time = (Time.now - @interval).strftime("%H:%M:%S") + + # Get raw data from sacct, + # read jobs into an array, + # remove any whitespace from the ends of each string, + # drop the header, + # and split each line into state and partition + raw = `sacct -a -P -o State,Partition -S #{start_time}`. + lines. + map(&:strip)[1..-1]. + map{|l|l.split("|")} + + # Make a tally of each state/partition combo + tally = Hash.new{0} + raw.each do |job| + tally[job] += 1 + end + + # Clean up any previously reported metrics + # to prevent stale labelsets + @collector.redact!("slurm_job_states") + + # Report new metrics + tally.each do |labelset, number| + @collector.report!( + "slurm_job_states", + number, + help: "Number of jobs in each state", + type: "gauge", + labels: {state: labelset[0], partition: labelset[1]} + ) + end + end +end -- cgit v1.2.1