I wanted to send monthly uptime report to my clients through email. Will any one help me how to generate monthly report.
-
I know that otherwise I would not have asked that question . I need some suggestions to generate monthly report. – life tree Jan 30 '18 at 11:57
-
I took a 3 days course on jaspersoft and on how to create PDFs from database info. Might be worth investigating if there is something similar near you. That is if the generated info is not good enough. The "tabled" version is also suited to use in Calc or Excel if that is a tool you use more often. – Rinzwind Jan 30 '18 at 12:53
3 Answers
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 underlatest/
directory to/usr/bin/
and make it executablecp 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.

- 299,756
-
Is there any way to calculate uptime from particular date to another date? – life tree Feb 01 '18 at 08:18
-
1@lifetree sure: the data is stored in a database and 1 of the features of a databases is the ability to use dates and manipulate them. Or you could create a script that reads the databases, picks 2 dates and subtract them. If you have specific needs for a report you will need to create that ;) – Rinzwind Feb 01 '18 at 08:21
-
Thanks a lot @rizwind. I am like new born baby in linux. I dont know where the database is stored I mean which folder, and how to manipulate them. I need little more elaboration. – life tree Feb 01 '18 at 08:30
-
2Oh you need to start following the generic Linux rule: start reading the manual ;-) See the link in the question called "tuptime manual". The page it links to at some points states "Define an alternative database file. Default is located in '/var/lib/tuptime/tuptime.db'" ;-) and it has lots of command line parameters and options to pull out data. (the database is not likely to be plain text). There is likely also a generic connector you could use if you can code in python :D Have fun ;-) – Rinzwind Feb 01 '18 at 08:46
-
1You can calculate the uptime from and to another date if you pass the arguments --tsince and --tuntil with the date in epoch format, for example, from 1 Jan 2017 to the end of the year: $ tuptime --tsince 1483225200 --tuntil 1514761199 – rfmoz Feb 01 '18 at 18:10
-
-
-
Strange your answer was 2 days earlier than accepted answer which is basically the same. However with two extra votes you received more points. OK it's three more votes now then ;) – WinEunuuchs2Unix Nov 07 '19 at 03:33
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.

- 156
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.

- 102,282