-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web: add "last synced" column to tables
this uses prometheus data, just like grafana, so users who don't have JS enabled can just go there to get this info if they so choose.
- Loading branch information
1 parent
6020e02
commit 7c6c02d
Showing
4 changed files
with
77 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
function parseAge(raw) { | ||
var v = parseFloat(raw); | ||
if (v >= 20*24*60*60) { // 20 days | ||
return '<td class="time-muted">a long time ago</td>'; | ||
} else if (v >= 24*60*60) { // 24 hours | ||
return '<td class="time-red">' + (v/(24*60*60)).toFixed(1) + " days</td>" | ||
} else if (v >= 19*60*60) { // 19 hours | ||
return '<td class="time-yellow">' + (v/(60*60)).toFixed(1) + " hours</td>" | ||
} else if (v >= 60*60) { // 1 hour | ||
return '<td class="time-green">' + (v/(60*60)).toFixed(1) + " hours</td>" | ||
} else { // less than an hour | ||
return '<td class="time-green">' + (v/60).toFixed(0) + " minutes</td>" | ||
} | ||
} | ||
|
||
$(function() { | ||
$.getJSON( | ||
"https://prometheus.voidlinux.org/api/v1/query?query=(time()-repo_origin_time%7Bzone=%22external%22%7D)", | ||
function(data) { | ||
var mirrors = {}; | ||
$.each(data["data"]["result"], function(i, val) { | ||
mirrors[val["metric"]["instance"].replace(/current$/, "")] = parseAge(val["value"][1]); | ||
}); | ||
console.log(mirrors); | ||
$(".mirrortbl thead tr").append('<th>Last Synced</th>'); | ||
$(".mirrortbl tbody tr").each(function() { | ||
var k = $(this).children(":first")[0].innerText.trim().replace(/https?:\/\//, ""); | ||
$(this).append(mirrors[k] || '<td class="time-muted">unreachable</td>'); | ||
}); | ||
} | ||
); | ||
}); | ||
|
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
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
|
||
tabletmpl = """ | ||
<table> | ||
<table class="mirrortbl"> | ||
<thead> | ||
<tr> | ||
<th>Mirror</th> | ||
|
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