Skip to content

Commit

Permalink
Merge pull request #89 from OSC/fix/slurm-stats
Browse files Browse the repository at this point in the history
Fix SLURM node and processor stats calculation
  • Loading branch information
ericfranz authored Sep 17, 2020
2 parents ca9307e + 7627c99 commit afc16ca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
16 changes: 15 additions & 1 deletion lib/moab_showq_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ def setup
MoabShowqClientNotAvailable.new(cluster_id, cluster_title, e)
end

# Total nodes available
#
# @return [Integer] the total number of nodes up
def available_nodes
nodes_avail
end

# Total number of processors
#
# @return [Integer] the total number of processors
def available_procs
procs_avail
end

# Return moab lib pathname
def moab_lib
Pathname.new(@server['lib'].to_s)
Expand Down Expand Up @@ -110,7 +124,7 @@ def nodes_percent
#
# @return nil or constructed error message
def friendly_error_message
error_message.nil? ? nil : "#{cluster_title} Cluster: #{error_message}"
error_message.nil? ? nil : "#{cluster_title} Cluster: #{error_message}"
end

private
Expand Down
25 changes: 20 additions & 5 deletions lib/slurm_squeue_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def sinfo
return @sinfo if defined?(@sinfo)

cmd = '/usr/bin/sinfo'
args = ["-s", "-h", "-o=\"%C/%A\""]
args = ["-a", "-h", "-o=\"%C/%A/%D\""]

o, e, s = Open3.capture3({}, cmd, *args)

Expand All @@ -77,9 +77,10 @@ def cluster_info

{
procs_used: sinfo_out[0].to_i,
procs_avail: sinfo_out[1].to_i,
procs_avail: sinfo_out[3].to_i,
nodes_used: sinfo_out[4].to_i,
nodes_idle: sinfo_out[5].to_i,
nodes_avail: sinfo_out[6].to_i,
available_jobs: running_jobs.to_i,
pending_jobs: pending_jobs.to_i,
}
Expand All @@ -93,7 +94,7 @@ def setup
self.procs_used = cluster_info[:procs_used]
self.procs_avail = cluster_info[:procs_avail]
self.nodes_used = cluster_info[:nodes_used]
self.nodes_avail = cluster_info[:nodes_idle]
self.nodes_avail = cluster_info[:nodes_avail]

self
rescue => e
Expand All @@ -120,20 +121,34 @@ def eligible_percent
# @return [Integer] the total number of active/eligible jobs
def available_jobs
active_jobs + eligible_jobs
end

# Total nodes available (idle) and total nodes used
#
# @return [Integer] the total number of idle/used jobs
def available_nodes
nodes_avail
end

# Total number of available and in use procs
#
# @return [Integer] the total number of procs
def available_procs
procs_avail
end

# Return the processor usage as percent
#
# @return [Float] The number of processors used as float
def procs_percent
(procs_used.to_f / procs_avail.to_f) * 100
(procs_used.to_f / available_procs.to_f) * 100
end

# Return the node usage as percent
#
# @return [Float] The number of nodes used as float
def nodes_percent
(nodes_used.to_f / nodes_avail.to_f) * 100
(nodes_used.to_f / available_nodes.to_f) * 100
end

# Return cluster title + error message
Expand Down
4 changes: 2 additions & 2 deletions views/_node_status.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!-- node status progressbar -->
<div><%= showqer.nodes_used %> of <%= showqer.nodes_avail %> Nodes Active (<%= showqer.nodes_avail - showqer.nodes_used %> Nodes Free) </div>
<div><%= showqer.nodes_used %> of <%= showqer.available_nodes %> Nodes Active (<%= showqer.available_nodes - showqer.nodes_used %> Nodes Free) </div>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width:<%= showqer.nodes_percent.round(2) %>%">
<%=(showqer.nodes_percent).round(2) %>%
</div>
</div>
<div><%= showqer.procs_used %> of <%= showqer.procs_avail %> Processors Active (<%= showqer.procs_avail - showqer.procs_used %> Processors Free)</div>
<div><%= showqer.procs_used %> of <%= showqer.available_procs %> Processors Active (<%= showqer.available_procs - showqer.procs_used %> Processors Free)</div>
<div class="progress">
<div class="progress-bar" role="progressbar" style="width:<%= showqer.procs_percent.round(2) %>%">
<%= (showqer.procs_percent).round(2) %>%
Expand Down

0 comments on commit afc16ca

Please sign in to comment.