Skip to content

Commit

Permalink
Display per-job metrics on Job Detail page
Browse files Browse the repository at this point in the history
This adds a "Job metrics" card to the Job Detail page for users with one
or more roles. This card displays CPU and memory usage statistics, when
available (see below).

In addition to mean and peak, which are displayed here, Job Runner
collects sample and cumsum for both CPU and memory usage statistics
(opensafely-core/job-runner#686). However, I don't think sample and
cumsum usage statistics are useful to users: sample, because we (and so
they) don't know when the sample was taken; cumsum, because we (and so
they) don't know how many samples were taken (and if we did, then all we
would be able to compute would be the mean, which Job Runner has
computed for us).

As #3998 states, usage statistics are not available for historic jobs
(i.e. prior to 17/01/2024). In this case, `job.metrics == None`. They
are also not available for some other types of job. In these cases,
`job.metrics == {}`. We don't distinguish these cases, displaying "-" to
users in both cases.

Closes #3998
  • Loading branch information
iaindillingham committed Jan 26, 2024
1 parent bcf1a47 commit 20e8e67
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions templates/job/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,50 @@ <h1 class="min-w-0 text-3xl break-words md:text-4xl font-bold text-slate-900">
</dl>
{% /card %}

{% if request.user.all_roles %}
{% #card title="Job metrics" subtitle="Computed for the time spent running on the backend" %}
<dl class="border-t border-slate-200 sm:divide-y sm:divide-slate-200">
{% #description_item title="Mean CPU usage" %}
{% if job.metrics %}
<span class="relative group cursor-pointer">
{{ job.metrics.cpu_mean|floatformat:"0" }}%
{% tooltip content="Values are reported across all CPU cores" %}
</span>
{% else %}
-
{% endif %}
{% /description_item %}

{% #description_item title="Peak CPU usage" %}
{% if job.metrics %}
<span class="relative group cursor-pointer">
{{ job.metrics.cpu_peak|floatformat:"0" }}%
{% tooltip content="Values are reported across all CPU cores" %}
</span>
{% else %}
-
{% endif %}
{% /description_item %}

{% #description_item title="Mean memory usage" %}
{% if job.metrics %}
{{ job.metrics.mem_mb_mean|floatformat:"0g" }} MB
{% else %}
-
{% endif %}
{% /description_item %}

{% #description_item title="Peak memory usage" %}
{% if job.metrics %}
{{ job.metrics.mem_mb_peak|floatformat:"0g" }} MB
{% else %}
-
{% endif %}
{% /description_item %}
</dl>
{% /card %}
{% endif %}

{% if honeycomb_links %}
{% #card title="Monitoring" subtitle="Honeycomb login required" container %}
<ul class="flex flex-col gap-y-1.5 list-disc text-sm">
Expand Down

0 comments on commit 20e8e67

Please sign in to comment.