Skip to content

Commit

Permalink
Format TTL for humans
Browse files Browse the repository at this point in the history
When viewing details of events with a long TTL, it is not
straightforward to check if it is about to expire or not.

Instead of displayer the raw TTL as a number of seconds, format it by
using an appropriate unit of time and fixed precision:
  * 42 => "42 seconds"
  * 420 => "7.0 minutes"
  * 4200 => "70.0 minutes"
  * 42000 => "11.7 hours"
  * 420000 => "4.9 days"
  • Loading branch information
smortex committed Jan 15, 2025
1 parent bd08359 commit c75816a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/riemann/dash/public/eventPane.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
// Pane at the bottom of the dashboard for displaying events in context.

function format_ttl(ttl) {
if (parseInt(ttl) != ttl) {
return ttl;
}

if (ttl > 3600 * 48) {
return (ttl / 3600 / 24).toFixed(1) + " days";
} else if (ttl > 3600 * 2) {
return (ttl / 3600).toFixed(1) + " hours";
} else if (ttl > 60 * 2) {
return (ttl / 60).toFixed(1) + " minutes";
}
return ttl + " seconds";
}
var eventPane = (function() {
var el = $('#event-pane');
var fixedFields = ['host', 'service', 'time', 'state', 'metric', 'ttl', 'description', 'tags'];
Expand All @@ -11,7 +25,7 @@ var eventPane = (function() {
'<span class="state {{-state}}">{{-state}}</span>' +
'<span class="metric">{{-metric}}</span>' +
'<time class="absolute">{{-time}}</time>' +
'<span class="ttl">{{-ttl}}</span>' +
'<span class="ttl">{{-format_ttl(ttl)}}</span>' +
'<span class="tags">{{-tags}}</span>' +
'</div>' +
'<pre class="description">{{-description}}</pre>');
Expand Down

0 comments on commit c75816a

Please sign in to comment.