I noticed a question on serverfault in which the user was interested to discover periods of downtime on an Ubuntu 16.04 server instance. The server has been powered off at various itervals, and presumably was configured to boot automatically. I had a quick crack at an answer, but I think its one of those questions which it would be worth having a standard approach to.

I think there a whole load of solutions to this problem, depending on what tools you already have installed, and what you can reasonably install. I mean, if you are monitoring the server remotely with icynga or xabbix, you should have this information already.

In addition you should be able to see outages in the timeline using splunk or kibana. If you have those tools configured.

An ideal solution to this problem would not involve installing too many new packages unless absolutely necessary.

The following script parses the journal entries, and produces a table into 1 hour blocks. Which should obviously identify if the server was down for that period:

#!/bin/bash

START_STRING="1 week ago"
FORMAT="%Y-%m-%d %H:%M:%S"
next_date=$(date +%s -d "$START_STRING")

while [ "$next_date" -le "$(date +%s)" ]; do
  curr_date=$next_date
  next_date=$(date +%s -d "@$((next_date + 3600))")
  curr_data_iso=$(date +"$FORMAT" -d "@$curr_date")
  next_date_iso=$(date +"$FORMAT" -d "@$next_date")
  echo -n "$curr_data_iso  $next_date_iso "
  count=$(journalctl --quiet \
              --no-pager \
              --since "$curr_data_iso" \
              --until "$next_date_iso" \
                 | wc -l )

  echo -n " $count "
        [ $count -gt 100 ] && nummer=100 || nummer=$count
  printf '=%.0s' $(seq 1 $nummer)
        echo ""
done
echo ""

Produces output like this

2018-02-08 13:58:41  2018-02-08 14:58:41  13 =============
2018-02-08 14:58:41  2018-02-08 15:58:41  18 ==================
2018-02-08 15:58:41  2018-02-08 16:58:41  13 =============
2018-02-08 16:58:41  2018-02-08 17:58:41  19 ===================
2018-02-08 17:58:41  2018-02-08 18:58:41  20 ====================
2018-02-08 18:58:41  2018-02-08 19:58:41  13 =============
2018-02-08 19:58:41  2018-02-08 20:58:41  18 ==================
2018-02-08 20:58:41  2018-02-08 21:58:41  19 ===================
2018-02-08 21:58:41  2018-02-08 22:58:41  13 =============
2018-02-08 22:58:41  2018-02-08 23:58:41  15 ===============
2018-02-08 23:58:41  2018-02-09 00:58:41  13 =============
2018-02-09 00:58:41  2018-02-09 01:58:41  19 ===================
2018-02-09 01:58:41  2018-02-09 02:58:41  16 ================
2018-02-09 02:58:41  2018-02-09 03:58:41  13 =============
2018-02-09 03:58:41  2018-02-09 04:58:41  19 ===================
2018-02-09 04:58:41  2018-02-09 05:58:41  13 =============
2018-02-09 05:58:41  2018-02-09 06:58:41  33 =================================
2018-02-09 06:58:41  2018-02-09 07:58:41  13 =============
2018-02-09 07:58:41  2018-02-09 08:58:41  13 =============
2018-02-09 08:58:41  2018-02-09 09:58:41  15 ===============
2018-02-09 09:58:41  2018-02-09 10:58:41  13 =============
2018-02-09 10:58:41  2018-02-09 11:58:41  13 =============
2018-02-09 11:58:41  2018-02-09 12:58:41  19 ===================
2018-02-09 12:58:41  2018-02-09 13:58:41  13 =============
2018-02-09 13:58:41  2018-02-09 14:58:41  13 =============