4

I wanted to send monthly uptime report to my clients through email. Will any one help me how to generate monthly report.

life tree
  • 55
  • 1
  • 7

3 Answers3

5

There is a tool called "tuptime" that generates information on "uptime" but with a lot more information compared to the single line "uptime" shows.

From their github page:

Basic Installation and usage

Clone the repo

git clone https://github.com/rfrail3/tuptime.git

Copy the tuptime file located under latest/ directory to /usr/bin/ and make it executable

cp tuptime/src/tuptime /usr/bin/tuptime chmod ugo+x /usr/bin/tuptime

Assure that the system pass the prerequisites

python 3.X 

Run first with a privileged user

tuptime

Extra added by me: change the owner and group of typtime to your user with:

sudo chown $USER:$USER /usr/bin/tuptime

and you can run it without sudo/root access.

From the link one of the keypoints it shows is:

  • It register the times in a sqlite database. Any other software can use it. The specs are in the tuptime-manual.txt. Also, it have the option for output the registers in seconds and epoch (-s) or/and in csv format, easy to pipe it to other commands.

So if you can code you could create your own reports. Or even connect the database to something like jasperstudio and create a template.

Otherwise the command tuptime will show this:

System startups:    1   since   21:54:09 24/09/15
System shutdowns:   0 ok   -   0 bad
System uptime:      100.0 %   -   21 minutes and 30 seconds
System downtime:    0.0 %   -   0 seconds
System life:        21 minutes and 30 seconds

Largest uptime:     21 minutes and 30 seconds   from   21:54:09 24/09/15
Shortest uptime:    21 minutes and 30 seconds   from   21:54:09 24/09/15
Average uptime:     21 minutes and 30 seconds

Largest downtime:   0 seconds
Shortest downtime:  0 seconds
Average downtime:   0 seconds

Current uptime:     21 minutes and 30 seconds   since   21:54:09 24/09/15

or tuptime --table will show a tabled output:

No.      Startup Date                              Uptime       Shutdown Date   End                   Downtime

1   10:15:27 08/08/15                          42 seconds   10:16:09 08/08/15    OK                 16 seconds
2   10:16:26 08/08/15                          49 seconds   10:17:15 08/08/15    OK                 16 seconds
3   10:17:32 08/08/15            5 minutes and 47 seconds   10:23:19 08/08/15    OK                 16 seconds
4   10:23:36 08/08/15                           9 seconds   10:23:45 08/08/15   BAD                 42 seconds
5   10:24:28 08/08/15   2 hours, 9 minutes and 27 seconds   12:33:55 08/08/15    OK  41 minutes and 44 seconds
    . . .

The tuptime manual mentioned has loads of good information.

You can send the output to a file by adding >> /home/$USER/Downloads/tuptime.log to the command. That text file could be sent to clients.

Rinzwind
  • 309,379
3

As a quick note to the excellent reply made by Rinzwind about Tuptime.

The package is available in the offical repository, so you can install with:

# apt-get install tuptime

Supossing that you send the report the day 1 of each month, these are the steps:

Get the timestamp of the first day of one month ago from 00:00 hours:

$ date -d "-1 month 00:00" +%s
1514761200

Get the timestamp of the last day of the previous month from 23:59 hours:

$ date -d "this month -1 second 00:00" +%s
1517439599

Use this numbers with the tsince and tuntil arguments:

$ tuptime --tsince 1514761200 --tuntil 1517439599 
System startups:    25   since   00:00:00 01/01/18   until   23:59:59 31/01/18
System shutdowns:   24 ok   -   1 bad
System uptime:      4.84 %   -   1 day, 12 hours, 0 minutes and 24 seconds
System downtime:    95.16 %   -   29 days, 11 hours, 59 minutes and 36 seconds
System life:        31 days, 0 hours, 0 minutes and 0 seconds

Largest uptime:     3 hours, 37 minutes and 41 seconds   from   19:00:15 16/01/18
Shortest uptime:    1 minute and 5 seconds   from   16:40:13 19/01/18
Average uptime:     1 hour, 26 minutes and 25 seconds

Largest downtime:   4 days, 9 hours, 48 minutes and 21 seconds   from   14:11:38 27/01/18
Shortest downtime:  11 seconds   from   16:40:02 19/01/18
Average downtime:   1 day, 4 hours, 19 minutes and 11 seconds

Current uptime:     48 minutes and 19 seconds   since   18:50:03 01/02/18

Now you can get this report, or one of the others available like the table or list format, and send it to the clients.

rfmoz
  • 156
0

There is no mention anywhere if tuptime takes into account the time system was suspended. If it does not you can use this script to calculate suspend time and subtract it from uptime:

$ suspendtime
Oct 31 05:55:19 to Oct 31 16:54:26 lasting 39,547 seconds
Oct 31 23:21:21 to Nov 01 04:29:12 lasting 18,471 seconds
Nov 01 05:51:27 to Nov 01 17:08:34 lasting 40,627 seconds
Nov 02 00:01:33 to Nov 02 10:28:46 lasting 37,633 seconds
Nov 02 18:15:59 to Nov 02 19:10:14 lasting 3,255 seconds
Nov 02 21:17:33 to Nov 03 05:31:54 lasting 33,261 seconds
Nov 03 12:06:39 to Nov 03 14:22:50 lasting 8,171 seconds
Nov 03 22:28:12 to Nov 04 04:17:13 lasting 20,941 seconds
Nov 04 05:49:40 to Nov 04 16:48:52 lasting 39,552 seconds
Nov 04 21:45:48 to Nov 05 04:19:26 lasting 23,618 seconds
Nov 05 05:52:05 to Nov 05 16:32:38 lasting 38,433 seconds
Nov 05 21:12:18 to Nov 06 04:16:50 lasting 25,472 seconds
Nov 06 05:50:45 to Nov 06 16:22:54 lasting 37,929 seconds

Linux uptime 576,297 seconds (6 Days 16 Hours 4 Minutes 57 Seconds)
13 Suspends 366,910 seconds (4 Days 5 Hours 55 Minutes 10 Seconds)
Real uptime 209,387 seconds (2 Days 10 Hours 9 Minutes 47 Seconds)

Note the script only looks at journalctl for the current boot. You need to turn on jounralctl multi-boot logging:

Also note the linked bash script would need to be modified to calculate previous boots.