rfmoz / tuptime

Report historical and statistical real time of the system, keeping it between restarts. Like uptime command but with more interesting output.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need help in excluding certain date from tuptime

kumaresan078 opened this issue · comments

Hi All,

Good day!

We have requirement to provide server availability hence using tuptime command to achieve.But there is an issue to exclude certain date downtime as we perform maintenance activity.

Example Output:

System startups: 4 since 04:06:57 PM 03/12/2022
System shutdowns: 0 ok + 3 bad
System life: 46d 23h 56m 38s

System uptime: 99.99% = 46d 23h 47m 19s
System downtime: 0.01% = 9m 19s

Average uptime: 11d 17h 56m 50s
Average downtime: 3m 6s

Current uptime: 3d 1h 47m 24s since 02:16:11 PM 04/25/2022

tuptime -t

From below output we would like to exclude march 12th downtime and calculate the System uptime:

No. Startup T. Uptime Shutdown T. End Downtime

1 04:06:57 PM 03/12/2022 43d 21h 48m 47s 01:55:44 PM 04/25/2022 BAD 1m 5s
2 01:56:49 PM 04/25/2022 5m 20s 02:02:09 PM 04/25/2022 BAD 3m 30s
3 02:05:39 PM 04/25/2022 5m 48s 02:11:27 PM 04/25/2022 BAD 4m 44s
4 02:16:11 PM 04/25/2022 3d 1h 47m 31s

Regards
Kumar

Hi Kumar,

As the startup registers are located in a Sqlite database on /var/lib/tuptime/tuptime.db, you can delete them with a simple SQL statement.

For example, make a backup file and delete register number 1:

# cp /var/lib/tuptime/tuptime.db /var/lib/tuptime/tuptime.db.backup
# sqlite3 /var/lib/tuptime/tuptime.db 'delete from tuptime where rowid =1'
# sqlite3 /var/lib/tuptime/tuptime.db 'vacuum'

Don't forguet the vacuum line, it fixes the startup numbers, assigning the new position.

Regards,

Hi Rfrail,

Thanks for the support. The given commands seems working on based on the registered numbers.

Is there way we can remove by specifying date as the registered no can't be same on all servers?

Regards
Kumar

Hi Kumar,

You need to do an extra step to identify the date that match inside an startup number. As a readable example:

$ tuptime --tat `date -d "JAN-18-2022" +%s`

The same, but to get the number directly:

$ tuptime --tat `date -d "JAN-18-2022" +%s` --csv | head -1 | awk -F\" '{print $12}'

And later on, use this number into the SQLite query.

Regards,

Hi Rfrail,

If i understand correctly from below output to exclude April 25th using below provided command however the command shows register number for future date also not sure how it's works.

#tuptime -t
No. Startup T. Uptime Shutdown T. End Downtime

1 04:06:57 PM 03/12/2022 43d 21h 48m 47s 01:55:44 PM 04/25/2022 BAD 1m 5s
2 01:56:49 PM 04/25/2022 5m 20s 02:02:09 PM 04/25/2022 BAD 3m 30s
3 02:16:11 PM 04/25/2022 4d 6h 29m 47s

To exclude April 25th the registered no shows 1 however from above the register no 1 belong to March12th.

#tuptime --tat date -d "APR-25-2022" +%s --csv
"Timestamp status","UP","at","12:00:00 AM 04/25/2022","on","1"
"elapsed in","98.68%","43d 7h 53m 3s"
"remaining in","1.32%","13h 55m 44s"

If i specify the future date which doesn't present in tuptime output getting registered no not sure how this works.

tuptime --tat date -d "APR-27-2022" +%s --csv
"Timestamp status","UP","at","12:00:00 AM 04/27/2022","on","3"
"elapsed in","32.9%","1d 9h 43m 49s"
"remaining in","67.1%","2d 20h 48m 11s"

Regards
Kumar

The register "1" starts at "04:06:57 PM 03/12/2022" and ends at "01:55:44 PM 04/25/2022".

If you request the date "APR-25-2022" with no hour, by default it inherits the midday hour, applying "12:00:00 AM 04/27/2022", it is printed in the output.

The "12:00:00 AM 04/27/2022" is inside register "1" because it's before their end "01:55:44 PM 04/25/2022".

Please, define the date plus hour like this example:

$ tuptime --tat `date -d "2018-01-20 16:21:42" +%s` --csv

Hi Rfrail3,

Could you help with to delete the entry between 1:15PM to 1:30PM on 05/09/2022 date?

Also it's compulsory to delete the entry or is there way to calculate System uptime percentage without deleting the entry?

tuptime -t
No. Startup T. Uptime Shutdown T. End Downtime

1 04:06:57 PM 03/12/2022 43d 21h 48m 47s 01:55:44 PM 04/25/2022 BAD 1m 5s
2 01:56:49 PM 04/25/2022 5m 20s 02:02:09 PM 04/25/2022 BAD 3m 30s
3 02:16:11 PM 04/25/2022 13d 22h 48m 37s 01:04:48 PM 05/09/2022 OK 11m 43s
4 01:16:31 PM 05/09/2022 14m 35s 01:31:06 PM 05/09/2022 OK 16s
5 01:31:22 PM 05/09/2022 1m 37s 01:32:59 PM 05/09/2022 OK 2m 9s
6 01:35:08 PM 05/09/2022 18m 42s

Regards
Kumar

As your time range correspond to the startup number 4, delete it as I already pointed a few messages earlier in #69 (comment)

About your second question, since Tuptime 5.1.1 (currently under development) there is an option to exclude startup numbers on the report. If you want to try it, install the new version with:

# wget https://raw.githubusercontent.com/rfrail3/tuptime/dev/src/tuptime -O /usr/bin/tuptime

Check the new version:

# tuptime -V
tuptime version 5.1.1

Get the report without startup 4:

# tuptime -E 4

Thanks Rfrail3 for the exclude option in newer version.

The issue with fetching exact register number is challenging as the time may vary between servers.For example the server got rebooted 4times in a day but want only exclude any reboot between 1PM to 3PM is that possible?

Regards
Kumar

In that case, you need to look for the startup events on that time date range:

$ tuptime --tsince `date -d "MAY-12-2022 13:00" +%s` --tuntil `date -d "MAY-12-2022 15:00" +%s` -l --csv | grep 'Startup' | grep 'at' | awk -F\" '{print $4}'
4
5
6

Note that, with the previous command, you are grepping 'Startup' to get the startup matching lines and the 'at' to get the ones that have a startup event on it.

After that, use the numbers to delete them on the database or exclude them only on the report:

$ tuptime -E '4,5,6'

Thanks Rfrail3.The commands working as expected.

However as per below output trying to exclude from 13th May 6:56PM till 13th May 7:10PM getting registered numbers 2 & 3 but this also has to return register no 1?

From the command you've provided fetching "Startup" values.

No. Startup T. Uptime Shutdown T. End Downtime

1 04:06:40 PM 03/12/2022 62d 2h 49m 39s 06:56:19 PM 05/13/2022 OK 17s
2 06:56:36 PM 05/13/2022 55s 06:57:31 PM 05/13/2022 OK 10m 35s
3 07:08:06 PM 05/13/2022 2m 47s 07:10:53 PM 05/13/2022 OK 3m 8s
4 07:14:01 PM 05/13/2022 2h 3m 35s

tuptime --tsince date -d "MAY-13-2022 18:56" +%s --tuntil date -d "MAY-13-2022 19:10" +%s -l --csv | grep 'Startup' | grep 'at' | awk -F" '{print $4}'

2
3

Regards
Kumar

If you need all the events, not only the ones that have a startup inside the range, it's simple:

$ tuptime --tsince `date -d "MAY-12-2022 13:00" +%s` --tuntil `date -d "MAY-12-2022 15:00" +%s` -l --csv | grep 'Startup' | awk -F\" '{print $4}'