show uptime on index page
This commit is contained in:
parent
aa7e179601
commit
20027b5cdc
|
@ -19,7 +19,7 @@
|
|||
"There might be moths here",
|
||||
"< 6 security vulnerabilities (for 2 of which a CVE is pending!)",
|
||||
"Overengineered Hellspawn",
|
||||
"Home of <b>The Intrinsic</b>",
|
||||
"Home of <b>The Intrinsic</b> and <b>Enigmatic</b>",
|
||||
"home of ㏒",
|
||||
"wake up, take a shit, novosibirsk",
|
||||
"The catalyst of ball itching",
|
||||
|
@ -42,7 +42,7 @@
|
|||
</p>
|
||||
</div>
|
||||
<div class="dim">
|
||||
Crystal <%= Crystal::VERSION %> <pre><%= Crystal::BUILD_COMMIT %></pre> running on <pre><%= System.hostname %></pre>
|
||||
Crystal <%= Crystal::VERSION %> <pre><%= Crystal::BUILD_COMMIT %></pre> running on <pre><%= System.hostname %></pre> for <%= CrystalGauntlet.uptime_s %>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -48,6 +48,21 @@ module CrystalGauntlet
|
|||
@@endpoints = Hash(String, (HTTP::Server::Context -> String)).new
|
||||
@@template_endpoints = Hash(String, (HTTP::Server::Context -> String)).new
|
||||
|
||||
@@up_at = nil
|
||||
|
||||
def self.uptime
|
||||
if !@@up_at
|
||||
return Time::Span::ZERO
|
||||
else
|
||||
return Time.utc - @@up_at.not_nil!
|
||||
end
|
||||
end
|
||||
|
||||
def self.uptime_s
|
||||
span = uptime
|
||||
Format.fmt_timespan_long(span)
|
||||
end
|
||||
|
||||
def self.endpoints
|
||||
@@endpoints
|
||||
end
|
||||
|
@ -233,6 +248,7 @@ module CrystalGauntlet
|
|||
LOG.warn { " #{" " * min_length}#{"^" * (max_length - min_length)}"}
|
||||
end
|
||||
|
||||
@@up_at = Time.utc
|
||||
LOG.notice { "Listening on #{listen_on.to_s.colorize(:white)}" }
|
||||
server.listen
|
||||
end
|
||||
|
|
|
@ -30,6 +30,21 @@ module CrystalGauntlet::Format
|
|||
end
|
||||
end
|
||||
|
||||
def fmt_timespan_bit(n : Int, s : String) : String | Nil
|
||||
if n > 0
|
||||
return "#{n} #{s}#{n == 1 ? "" : "s"}"
|
||||
end
|
||||
end
|
||||
|
||||
def fmt_timespan_long(s : Time::Span) : String
|
||||
[
|
||||
{s.days, "day"},
|
||||
{s.hours, "hour"},
|
||||
{s.minutes, "minute"},
|
||||
{s.seconds, "second"}
|
||||
].map { |n, s| fmt_timespan_bit(n.floor().to_i, s) }.compact.join(" ")
|
||||
end
|
||||
|
||||
def fmt_time(s : Time, colon_safe=false) : String
|
||||
s.to_s(colon_safe ? TIME_FORMAT_USER_FRIENDLY : TIME_FORMAT_GD_FRIENDLY)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue