commit 1a0d04d8b7d4cdd8e2266e16e128f963afabe23a
parent 15a4e2e4f937be2194a06f8e80b46b57149f0a4d
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Wed, 9 Oct 2019 16:52:37 -0400
Add uptime statistics monitoring to about-site
Diffstat:
3 files changed, 94 insertions(+), 2 deletions(-)
diff --git a/build/base.css b/build/base.css
@@ -33,13 +33,20 @@ p.noindent {
pre {
font-family: "DejaVu Sans Mono", monospace;
- text-indent: 1em;
/* Do word-wrapping in every browser for pre */
white-space: -moz-pre-wrap;
white-space: -o-pre-wrap;
white-space: -pre-wrap;
white-space: pre-wrap;
word-wrap: break-word;
+ background-color: #424242;
+ border: 3px #585858 solid;
+ box-shadow: inset 0 0 0 2px rgba(40, 40, 40, 0.5);
+ padding: 20px;
+}
+
+pre code {
+ background-color: transparent;
}
code {
diff --git a/pages/about-site.md b/pages/about-site.md
@@ -4,7 +4,7 @@
[//]: # "base.min.css"
-[//]: # "Introduction; Privacy; Design; The Technical Side; References"
+[//]: # "Introduction; Privacy; Design; The Technical Side; Current Uptime Statistics; References"
### Introduction
@@ -83,6 +83,29 @@ the website's directory.
All of the scripts used can be found in the aforementioned git repository.
+### Current Uptime Statistics
+
+The statistics below are updated once every hour (time is EST/EDT, Ontario,
+Canada):
+
+<pre><code># Output from 'tuptime'
+System startups: 12 since 21:32:51 08/10/19
+System shutdowns: 10 ok <- 1 bad
+System uptime: 99.95 % - 58 days, 3 hours, 44 minutes and 25 seconds
+System downtime: 0.05 % - 42 minutes and 11 seconds
+System life: 58 days, 4 hours, 26 minutes and 36 seconds
+
+Largest uptime: 11 days, 17 hours, 51 minutes and 56 seconds from 00:20:22 09/08/19
+Shortest uptime: 48 seconds from 17:49:13 09/29/19
+Average uptime: 4 days, 20 hours, 18 minutes and 42 seconds
+
+Largest downtime: 19 minutes and 9 seconds from 17:24:43 09/29/19
+Shortest downtime: 8 seconds from 18:22:10 08/22/19
+Average downtime: 3 minutes and 50 seconds
+
+Current uptime: 5 minutes and 31 seconds since 01:53:56 10/08/19
+</code></pre>
+
### References
<a name=1></a>
diff --git a/tuptime-update.pl b/tuptime-update.pl
@@ -0,0 +1,62 @@
+#!/bin/perl
+
+use strict;
+use warnings;
+use HTML::TreeBuilder;
+use File::Copy qw(copy), qw(move);
+
+# Copy about-site file so we can work on it without disturbing live copy
+copy '/var/www/html/about-site.html', './about-site.html';
+my $outfile = './about-site.html.new';
+my $infile = './about-site.html';
+
+# Open both infile and outfile for reading/writing respectively
+open(my $fh, '<:encoding(UTF-8)', $infile)
+ or die "Could not open file '$infile' $!";
+open my $out, '>', "$outfile" or die "Can't write new file: $!";
+
+# Run the tuptime command to get output for putting into outfile
+my $cmd = "tuptime";
+my @output = `$cmd`;
+chomp @output;
+
+# Look through each line of the infile, write the line to outfile unless we are
+# in between <pre></pre> in which case write out the output of tuptime.
+my $inPreFlag = 0;
+my $arrIndex = 0;
+while (my $row = <$fh>) {
+ chomp $row;
+ # Create a new tree to parse HTML tags from $row
+ my $tr = HTML::TreeBuilder->new_from_content($row);
+
+ # If this line contains a <pre> tag, set the flag so we will begin printing
+ # output from tuptime.
+ if ($tr->find_by_tag_name('pre')) {
+ $inPreFlag = 1;
+ print "Entering pre\n";
+ print $out "<pre><code>\n";
+ next;
+ }
+ # Check if we have printed out every line from the output of tuptime
+ if ($arrIndex == scalar @output) {
+ # Reset arrIndex so this if doesn't continue to resolve to true
+ $arrIndex = 0;
+ $inPreFlag = 0;
+ print "Exiting pre\n";
+ print $out "</code></pre>\n";
+ next;
+ }
+
+ if ($inPreFlag) {
+ print $out "$output[$arrIndex]\n";
+ $arrIndex++;
+ }
+ else {
+ print $out "$row\n";
+ }
+}
+
+# Finally, overwrite the old about-site file with this new one:
+move './about-site.html.new', '/var/www/html/about-site.html';
+# And remove the copy of the old one
+unlink('./about-site.html');