π

Poor Man's Monitoring of a Remote Linux Host via Syncthing

Show Sidebar

Updates:

I'm helping some old lady by administrating her notebook. I set it up with Xubuntu LTS GNU/Linux which comes with the very easy to use and fast Xfce environment: not bloated and offers everything necessary. I stripped down the "start menu" such that it only shows the ten apps she's using.

Remote access is done via TeamViewer if necessary.

Today, I set it up with a neat monitoring I'm going to explain in this post.

The purpose is to have the possibility to take a quick look at the most basic status information whenever I want to.

For that, I wrote a small shell script named autologs.sh:

#!/bin/sh

## This script saves some basic infos about this host and commits them via git

## NOTE: if you add a new file, it has to be added to the Git repo manually.

## directory where the results are written to:
LOGDIR="/home/USER/.vk/share/autologs"

## ----------------------------------------------------------------------- ##

## get list of current cron jobs
crontab -l > "${LOGDIR}"/root-crontab.txt

## get list of installed Debian packages
dpkg --get-selections > "${LOGDIR}"/dpkg--get-selections.txt

## get current log file of Debian packages in order to review updates
cp /var/log/apt/history.log "${LOGDIR}"/var-log-apt-history.log

## how much space is left on the drives?
df -h > "${LOGDIR}"/df-h.txt

## when were the most recent backups?
ls -la /home/USER/.cache/deja-dup > "${LOGDIR}"/deja-dup_files.log

## what hardware is attached?
lspci > "${LOGDIR}"/lspci.txt
lsusb > "${LOGDIR}"/lsusb.txt
hwinfo --short > "${LOGDIR}"/hwinfo--short.txt

## ----------------------------------------------------------------------- ##

## commit everything after being generated
git -C "${LOGDIR}" add "${LOGDIR}"
git -C "${LOGDIR}" commit -a -m "`date '+%Y-%m-%dT%H.%M.%S autocommit by autologs.sh'`"

#end	  

Of course, "USER" is replaced with the account name.

The folder /home/USER/.vk/ is a hidden one which I shared via Syncthing. Syncthing doesn't need a public IP or a firewall rule in order to synchronize two folders between two hosts that are online at the same time. I configured Syncthing to start as user service via systemd automatically.

My own (receiving) host runs 24/7 and is therefore always available whenever the other notebook is running.

The autologs.sh is invoked two minutes after each boot via cron as user root on the remote notebook:

 @reboot sleep 2m ; /home/USER/.vk/share/autologs/autologs.sh	  

It then produces the files mentioned in the script, they are synchronized via Syncthing to my personal host where I can take a look on some status information any time.

I'm committing to a local Git repository because Git is extremely efficient in storing a history of linear text files that change slightly over time. It also provides decent tools to visualize differences between two given points in time.

Using the described method obove, I do have an up-to-date status report on remote hosts without having direct access to the remote host. Nothing fancy, simple to set up, reliable in use and probably a small trick you haven't thought of yet.

Comment via email or via Disqus comments below: