Automated screenshot generation... for example of uptime (monitoring)
Hi Jürgen.
If you're using uptime for some monitoring you might be interesting in generating automated screenshots for reporting. If so I just created a script that does exactly that (copied from our redmine ticket):
Screenshots
I set up periodic generation of screenshots. Thanks to cutycapt this is pretty easy. Cutycapt is present in the Ubuntu repositories.
Scripts
Cutycapt uses an X server to determine resolution and color depth. To keep the X server running I am using the following script that is started every minute. It checks if the X server (Xvfb in this case since we are on a server) is already running and if not starts it:
#!/usr/bin/zsh
if ! ps xo command | grep "^Xvfb -screen scrn 1920x1080x24 :99$" >/dev/null; then
date;
nohup Xvfb -screen scrn 1920x1080x24 :99 >>/home/ezi/cron/xvfb/log 2>&1 &
fi;
The screenshots are generated with the following script. It is called hourly at minute 59 since uptime shows the graphs from the beginning of the current time period per default.
It generates one screenshot per hour and updates the daily, monthly and yearly files at the same time.
#!/bin/sh
timestamp=$(date +%s);
year="$(date -d @$timestamp +%Y)";
month="$(date -d @$timestamp +%m)";
day="$(date -d @$timestamp +%d)";
hour="$(date -d @$timestamp +%H)";
datadir="/data/uptime";
mkdir -pv "$datadir/haustec/$year/$month/$day";
export DISPLAY=:99;
cutycapt --url=http://localhost:8082/dashboard/checks/5846ce0a1084bd1fb7bd3f31?type=hour --out="$datadir/haustec/$year/$month/$day/$year$month$day-$hour.png";
cutycapt --url=http://localhost:8082/dashboard/checks/5846ce0a1084bd1fb7bd3f31?type=day --out="$datadir/haustec/$year/$month/$year$month$day.png";
cutycapt --url=http://localhost:8082/dashboard/checks/5846ce0a1084bd1fb7bd3f31?type=month --out="$datadir/haustec/$year/$year$month.png";
cutycapt --url=http://localhost:8082/dashboard/checks/5846ce0a1084bd1fb7bd3f31?type=year --out="$datadir/haustec/$year.png";