AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
So when you run this script you should see at least one blinking red “failure”. The last file check is for /tmp/foo, which probably doesn’t exist. You can run the full script like so: $ sudo. [ # make sure Dave's little pi blog is runningĬheck(file, '/var/backups/dpkg.status.0'),Ĭheck(file, '/var/backups/apt.extended_states.0'), I’ve included some examples which check some common / important pages on the piwheels site, some pages on my blog server, some basic connectivity checks (can ping the local gateway, can ping a DNS name, can ping Google’s DNS), and some example file checks. Super()._init_(target=self.update, args=(layout,), daemon=True)įinally, we need to run the main monitor function and define all the checks we want to execute. Next, we need the background thread that will loop round running the update method of all the checks in the layout: class UpdateThread(Thread): Self.value = self.func(*self.args, **self.kwargs) If self.last_run is None or self.last_run + self.every < now: It will wrap one of the functions above, the parameters we want to pass to it, and how long we should cache results for before allowing the check to be run again: class Check:ĭef _init_(self, func, *args, every=60, **kwargs): Next, we define a class which we’ll use to define individual checks. file – checks that the specified file exists and has a particular minimum size (defaults to 1 so this effectively checks the file is not empty).cmd – checks that executing a particular shell command is successful (exits with code 0).page – checks that accessing a particular url (with the “HEAD” method by default) returns status code 200 (OK in HTTP parlance).Now onto the main monitor function: def monitor(layout): Nothing terribly remarkable here other than to note the only external dependency is the Unicorn HAT library. We start off with all the imports we’ll need. We’ll go through it piece by piece: #!/usr/bin/python3įrom urllib.request import urlopen, Request If anyone wants to follow in my pioneering lo-fi monitoring footsteps, here’s a little script to achieve something similar with a Unicorn HAT. I’ve occasionally caught issues in piwheels for which no specific alert existed because the monitor “looked off”. It’s a constant view of the overall system I can trigger alerts to fire when certain things fail or occur, but it’s also useful to have an “at a glance” view of the “health” of the overall system. I’ll handle that when I’m suitably caffeinated and behind my computer. But if the builders go down at 4 in the morning, it’s not a big deal.
0 Comments
Read More
Leave a Reply. |