-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved metrics widget code and templates
- Loading branch information
Showing
14 changed files
with
249 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ [email protected] | |
OOD_DASHBOARD_SUPPORT_URL=[email protected] | ||
OOD_APP_CATALOG_URL=https://link.to.online/app/catalog | ||
ENABLE_NATIVE_VNC=true | ||
OOD_ANNOUNCEMENT_PATH=/var/www/ood/public/announcements | ||
OOD_CONFIG_D_DIRECTORY_BAK=/etc/ood/config | ||
OOD_LOAD_EXTERNAL_CONFIG=true | ||
OOD_APP_CONFIG_ROOT=/etc/ood/config/apps/ood | ||
OOD_DATAROOT=~/ondemand/data/sys/dashboard | ||
OOD_XDMOD_HOST=https://localhost:4443 | ||
OOD_XDMOD_HOST_BAK=https://localhost:33000 |
55 changes: 0 additions & 55 deletions
55
config/local/app_overrides/lib/slurm_metrics/metrics_cache.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
config/local/app_overrides/lib/slurm_metrics/metrics_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# frozen_string_literal: true | ||
|
||
module SlurmMetrics | ||
# Service to manages retrieving and storing the user metrics within the user settings store. | ||
# It uses a 24hours cache for theSlurm data. | ||
class MetricsService | ||
include UserSettingStore | ||
METRICS_PERIOD = 7.days | ||
|
||
attr_reader :cluster | ||
|
||
def initialize | ||
@cluster = Configuration.job_clusters.select(&:slurm?).first | ||
end | ||
|
||
def read_metrics | ||
slurm_metrics = user_settings.fetch(:slurm_metrics, {}) | ||
slurm_metrics = refresh_metrics if expired?(slurm_metrics[:timestamp]) | ||
|
||
SlurmMetrics::MetricsSummary.new(slurm_metrics[:metrics]) | ||
end | ||
|
||
def read_fairshare | ||
slurm_fairshare = user_settings.fetch(:slurm_fairshare, {}) | ||
slurm_fairshare = refresh_fairshare if expired?(slurm_fairshare[:timestamp]) | ||
fairshare = slurm_fairshare[:fairshare] | ||
fairshare[:from] = Time.at(fairshare[:from]) | ||
|
||
OpenStruct.new(fairshare) | ||
end | ||
|
||
private | ||
|
||
def refresh_metrics | ||
from = Time.now - METRICS_PERIOD | ||
to = Time.now | ||
job_data = cluster.job_adapter.metrics(from: from.strftime('%Y-%m-%dT00:00:00'), to: to.strftime('%Y-%m-%dT23:59:59')) | ||
processor = SlurmMetrics::MetricsProcessor.new | ||
metrics_summary = processor.calculate_metrics(from, to, job_data) | ||
|
||
set_metrics(metrics_summary) | ||
end | ||
|
||
def refresh_fairshare | ||
data = cluster.job_adapter.fairshare | ||
fair_share = { | ||
from: Time.now.to_i, | ||
data: data | ||
} | ||
set_fairshare(fair_share) | ||
end | ||
|
||
def set_metrics(metrics) | ||
slurm_metrics = { | ||
timestamp: Time.now.strftime('%Y-%m-%dT%H:%M:%S'), | ||
metrics: metrics.to_hash | ||
} | ||
update_user_settings({ slurm_metrics: slurm_metrics }) | ||
slurm_metrics | ||
end | ||
|
||
def set_fairshare(fairshare) | ||
slurm_fairshare = { | ||
timestamp: Time.now.strftime('%Y-%m-%dT%H:%M:%S'), | ||
fairshare: fairshare | ||
} | ||
update_user_settings({ slurm_fairshare: slurm_fairshare }) | ||
slurm_fairshare | ||
end | ||
|
||
def expired?(date_string) | ||
return true if date_string.blank? | ||
|
||
# Parse the date string and compare the time difference with 24 hours (in seconds) | ||
Time.now - Time.parse(date_string) > 24 * 60 * 60 | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 36 additions & 35 deletions
71
config/local/app_overrides/views/widgets/metrics/_fairshare.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,44 @@ | ||
<% | ||
metrics_cache = SlurmMetrics::MetricsCache.new | ||
timestamp, fairshare = metrics_cache.get_fairshare | ||
if true || fairshare.blank? | ||
cluster = Configuration.job_clusters.select(&:slurm?).first | ||
fairshare = cluster.job_adapter.fairshare | ||
timestamp = Time.now | ||
metrics_cache.set_fairshare(timestamp, fairshare) | ||
end | ||
metrics_service = SlurmMetrics::MetricsService.new | ||
slurm_faishare = metrics_service.read_fairshare | ||
timestamp = slurm_faishare.from | ||
fairshare = slurm_faishare.data | ||
|
||
metrics_helper = SlurmMetrics::MetricsHelper.new | ||
%> | ||
<div class="card mt-3"> | ||
<div class="card-header" title="Fairshare calculated at <%= timestamp.strftime('%Y-%m-%dT%H:%M:%S') %>"> | ||
<small class="float-end float-right"><%= timestamp.strftime('%Y-%m-%d') %></small> | ||
<h3>Fairshare</h3> | ||
</div> | ||
<div class="card-body"> | ||
<% unless fairshare.empty? %> | ||
<table class="table table-sm table-striped table-condensed metrics"> | ||
<thead> | ||
<tr> | ||
<th>Account <span class="float-end float-right">Fairshare</span></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% fairshare.each do |fairshare_data| %> | ||
<div class="metrics-widget-component"> | ||
<div class="card mt-3"> | ||
<div class="card-header" title="Fairshare calculated at <%= timestamp.strftime('%Y-%m-%dT%H:%M:%S') %>"> | ||
<small class="float-end float-right"><%= timestamp.strftime('%Y-%m-%d') %></small> | ||
<h3>Fairshare</h3> | ||
</div> | ||
<div class="card-body"> | ||
<% unless fairshare.blank? %> | ||
<table class="table table-sm table-striped table-condensed metrics"> | ||
<thead> | ||
<tr> | ||
<td> | ||
<%= fairshare_data[:account] %> | ||
<span class="badge <%= metrics_helper.fairshare_class(fairshare_data[:fairshare]) %> float-end float-right"><%= fairshare_data[:fairshare].to_s.to_f.round(4) %></span> | ||
</td> | ||
<th>Account <span class="float-end float-right">Fairshare</span></th> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<div class="no-fairshare-data"> | ||
No fairshare data available for user <span><%= @user.name %></span> | ||
</div> | ||
<% end %> | ||
</thead> | ||
<tbody> | ||
<% fairshare.each do |fairshare_data| %> | ||
<tr> | ||
<td title="<%= fairshare_data[:fairshare].to_s.to_f.round(4) %> fairshare for account <%= fairshare_data[:account] %>"> | ||
<%= fairshare_data[:account] %> | ||
<span class="badge <%= metrics_helper.fairshare_class(fairshare_data[:fairshare]) %> float-end float-right"><%= fairshare_data[:fairshare].to_s.to_f.round(4) %></span> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<p class="no-fairshare-data"> | ||
No fairshare data available for user <span><%= @user.name %></span> | ||
</p> | ||
<% end %> | ||
<small class="float-end float-right metrics-note" title="FASRC information on how fairshare is calculated and it affects your jobs."> | ||
<a target="_blank" href="https://docs.rc.fas.harvard.edu/kb/fairshare/">FASRC Fairshare info</a> | ||
</small> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.