Skip to content

Commit

Permalink
Top: modifying largemem page to be similar to the top compute and gpu…
Browse files Browse the repository at this point in the history
… pages, one row per user.
  • Loading branch information
guilbaults committed Jun 28, 2024
1 parent a8da5a7 commit 367193c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 64 deletions.
2 changes: 1 addition & 1 deletion top/templates/top/compute.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ <h1>{% translate "Top compute users" %}</h1>
},
{ render: function(data, type, row){
if ( type === 'display' || type === 'filter' ) {
ratio = data/row[3];
ratio = data/row[4];
if (ratio < 0.1) {
return '<span class="badge badge-danger">' + filesize(data) + '</span>';
}
Expand Down
52 changes: 17 additions & 35 deletions top/templates/top/largemem.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ <h1>{% translate "Users on largemem" %}</h1>
<thead class="thead-dark">
<tr>
<th scope="col">{% translate "Username" %}</th>
<th scope="col">{% translate "Job ID" %}</th>
<th scope="col">{% translate "Account" %}</th>
<th scope="col">{% translate "Start time" %}</th>
<th scope="col">{% translate "Allocated cores" %}</th>
<th scope="col">{% translate "Used cores" %}</th>
<th scope="col">{% translate "Allocated memory" %}</th>
Expand All @@ -40,63 +38,47 @@ <h1>{% translate "Users on largemem" %}</h1>
</tr>
</thead>
<tbody>
{% for job in jobs %}
{% for user in by_users %}
<tr>
<td><a href="{{settings.BASE_URL}}secure/jobstats/{{job.user}}">{{job.user | anonymize}}
{% if job.user_flag %}
<td><a href="{{settings.BASE_URL}}secure/jobstats/{{user.user}}">{{user.user | anonymize}}
{% if user.note_flag %}
<span class="badge badge-primary"><span data-feather="alert-circle" title="User has a note"></span></span>
{% endif %}</a>
</td>
<td><a href="{{settings.BASE_URL}}secure/jobstats/{{job.user}}/{{job.job_id}}">{{job.job_id}}</a>
{% if job.job_flag %}
<span class="badge badge-primary"><span data-feather="alert-circle" title="Job has a note"></span></span>
{% endif %}</a>
</td>
<td><a href="{{settings.BASE_URL}}secure/accountstats/{{job.account}}">{{job.account | anonymize}}</a></td>
<td>{{job.time_start_dt | date:"U"}}</td>
<td>{{job.cpu_asked | floatformat}}</td>
<td><a href="{{settings.BASE_URL}}secure/accountstats/{{user.account}}">{{user.account | anonymize}}</a></td>
<td>{{user.cpu_asked | floatformat}}</td>
<td>
{% if job.cpu_ratio < 0.75 %}
<span class="badge badge-danger">{{job.cpu_used | floatformat:-2}}</span>
{% elif job.cpu_ratio < 0.90 %}
<span class="badge badge-warning">{{job.cpu_used | floatformat:-2}}</span>
{% if user.cpu_ratio < 0.75 %}
<span class="badge badge-danger">{{user.cpu_used | floatformat:-1}}</span>
{% elif user.cpu_ratio < 0.90 %}
<span class="badge badge-warning">{{user.cpu_used | floatformat:-1}}</span>
{% else %}
<span class="badge badge-success">{{job.cpu_used | floatformat:-2}}</span>
{{user.cpu_used | floatformat:-1}}
{% endif %}
</td>
<td>{{job.mem_asked | floatformat:0 }}</td>
<td>{{job.mem_max | floatformat:0 }}</td>
<td>{{user.mem_asked | floatformat:0 }}</td>
<td>{{user.mem_max | floatformat:0 }}</td>
<td>
{% for badge in job.waste_badges %}
{% for badge in user.waste_badges %}
<span class="badge badge-{{badge.0}}">{{badge.1}}</span>
{% empty %}
<span class="badge badge-success">OK</span>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>

<script>
$(document).ready(function () {
luxon.Settings.defaultLocale = "{{LANGUAGE_CODE}}"; // Luxon autodetect seems broken
function parse_time(data, type) {
if (type == 'display' || type === 'filter'){
return DateTime.fromSeconds(parseInt(data)).toLocaleString(DateTime.DATETIME_MED);
}
else{
return data;
}
}

$('#largemem').DataTable({
"paging": false,
"order": [[ 6, "desc" ]],
"order": [[ 4, "desc" ]],
columns: [
{ },
{ },
{ },
{ render: parse_time },
{ },
{ },
{ render: function(data, type, row){
if ( type === 'display' || type === 'filter' ) {
Expand All @@ -109,7 +91,7 @@ <h1>{% translate "Users on largemem" %}</h1>
},
{ render: function(data, type, row){
if ( type === 'display' || type === 'filter' ) {
ratio = data/row[5];
ratio = data/row[4];
if (ratio < 0.1) {
return '<span class="badge badge-danger">' + filesize(data) + '</span>';
}
Expand Down
68 changes: 40 additions & 28 deletions top/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,25 @@ def largemem(request):
stats_mem_max = metrics_to_job(prom.query_last(query_mem_max))

context['jobs'] = []
by_users = {}
for job in jobs_running:
try:
job_id = str(job.id_job)

mem_ratio = stats_mem_max[job_id] / stats_mem_asked[job_id]
cpu_ratio = stats_cpu_used[job_id] / stats_cpu_asked[job_id]
stats = {
'user': uid_to_username(job.id_user),
'job_id': job.id_job,
'account': job.account,
'time_start_dt': job.time_start_dt,
'cpu_asked': stats_cpu_asked[job_id],
'cpu_used': stats_cpu_used[job_id],
'mem_asked': stats_mem_asked[job_id],
'mem_max': stats_mem_max[job_id],
'mem_ratio': mem_ratio,
'cpu_ratio': cpu_ratio,
'min_ratio': min(mem_ratio, cpu_ratio),
}
waste_badges = []
if stats['mem_ratio'] < 0.1:
waste_badges.append(('danger', _('Memory')))
elif stats['mem_ratio'] < 0.5:
waste_badges.append(('warning', _('Memory')))
if stats['cpu_ratio'] < 0.75:
waste_badges.append(('danger', _('Cores')))
elif stats['cpu_ratio'] < 0.9:
waste_badges.append(('warning', _('Cores')))

stats['waste_badges'] = waste_badges
context['jobs'].append(stats)
user = uid_to_username(job.id_user)
account = job.account

if (user, account) not in by_users:
by_users[(user, account)] = {
'cpu_asked': stats_cpu_asked[job_id],
'cpu_used': stats_cpu_used[job_id],
'mem_asked': stats_mem_asked[job_id],
'mem_max': stats_mem_max[job_id],
}
else:
by_users[(user, account)]['cpu_asked'] += stats_cpu_asked[job_id]
by_users[(user, account)]['cpu_used'] += stats_cpu_used[job_id]
by_users[(user, account)]['mem_asked'] += stats_mem_asked[job_id]
by_users[(user, account)]['mem_max'] += stats_mem_max[job_id]
except KeyError:
pass

Expand Down Expand Up @@ -315,6 +303,30 @@ def largemem(request):
if job['job_id'] in note_per_jobid:
job['job_flag'] = True

# convert dict to list
context['by_users'] = []
for (user, account), stats in by_users.items():
if user in note_per_user:
stats['user_flag'] = True
stats['user'] = user
stats['account'] = account
stats['cpu_ratio'] = stats['cpu_used'] / stats['cpu_asked']
stats['mem_ratio'] = stats['mem_max'] / stats['mem_asked']
stats['min_ratio'] = min(stats['cpu_ratio'], stats['mem_ratio'])

waste_badges = []
if stats['mem_ratio'] < 0.1:
waste_badges.append(('danger', _('Memory')))
elif stats['mem_ratio'] < 0.5:
waste_badges.append(('warning', _('Memory')))
if stats['cpu_ratio'] < 0.75:
waste_badges.append(('danger', _('Cores')))
elif stats['cpu_ratio'] < 0.9:
waste_badges.append(('warning', _('Cores')))
stats['waste_badges'] = waste_badges

context['by_users'].append(stats)

return render(request, 'top/largemem.html', context)


Expand Down

0 comments on commit 367193c

Please sign in to comment.