Skip to content

Commit 27f7083

Browse files
committed
Format TTL for humans
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"
1 parent bd08359 commit 27f7083

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lib/riemann/dash/public/eventPane.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
// Pane at the bottom of the dashboard for displaying events in context.
22

3+
function format_ttl(ttl) {
4+
if (parseInt(ttl) != ttl) {
5+
return ttl;
6+
}
7+
8+
if (ttl > 3600 * 48) {
9+
return (ttl / 3600 / 24).toFixed(1) + " days";
10+
} else if (ttl > 3600 * 2) {
11+
return (ttl / 3600).toFixed(1) + " hours";
12+
} else if (ttl > 60 * 2) {
13+
return (ttl / 60).toFixed(1) + " minutes";
14+
}
15+
return ttl + " seconds";
16+
}
317
var eventPane = (function() {
418
var el = $('#event-pane');
519
var fixedFields = ['host', 'service', 'time', 'state', 'metric', 'ttl', 'description', 'tags'];
@@ -11,7 +25,7 @@ var eventPane = (function() {
1125
'<span class="state {{-state}}">{{-state}}</span>' +
1226
'<span class="metric">{{-metric}}</span>' +
1327
'<time class="absolute">{{-time}}</time>' +
14-
'<span class="ttl">{{-ttl}}</span>' +
28+
'<span class="ttl">{{-format_ttl(ttl)}}</span>' +
1529
'<span class="tags">{{-tags}}</span>' +
1630
'</div>' +
1731
'<pre class="description">{{-description}}</pre>');

0 commit comments

Comments
 (0)