Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
hotaru
Posts: 1021
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Coding: Fleeting Thoughts

Postby hotaru » Wed Sep 20, 2017 7:31 pm UTC

Flumble wrote:Is there a linuxy way to monitor services and send an email whenever a services dies or comes back up (and preferably every hour while something's down)?
I'm currently using systemd timers to run a small script to log the status of things like the xkcd minecraft server and I could run a sendmail command when the status is negative, but it seems there ought to be a better way.
If there's no linuxy way, I'll look into graphite+grafana or <insert better suggestion>.

you could use OnFailure= in the the unit file with https://github.com/kylemanna/systemd-utils to send an email notification.

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5084
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Sep 20, 2017 8:00 pm UTC

commodorejohn wrote:
Hey, those Homestar Runner cartoons aren't gonna play themselves.
Actually something more banal, extracting media from them. Granted there is swfexport to do that, though it makes Windows Defender very very angry, and also some of the files I'm exporting from seem to just... sometimes not follow the spec so... fun.

It was kinda interesting though. Why do I do this for fun.

Related, it's really annoying that BitMap.SetPixel is soooo much slower than using an unsafe block with UnlockBits. Like I get being slower due to some bounds checks, but why is it so much slower?

commodorejohn
Posts: 943
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Wed Sep 20, 2017 8:09 pm UTC

Yeah, swfexport was already spotty back in the days when Flash MX was new, I can't imagine it copes well with newer versions.

This takes me back to the days of extracting random J-pop tracks from animutations because they never credited the original source and I had no idea what to Google...
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
Flumble
Yes Man
Posts: 1938
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Thu Sep 21, 2017 10:51 pm UTC

hotaru wrote:you could use OnFailure= in the the unit file with https://github.com/kylemanna/systemd-utils to send an email notification.

I'm not running the services on that that device, just the monitors (which are mostly of the form "try to establish a TCP connection/HTTP session" to find out whether the (black box) program is running properly). I can let the monitor purposefully stop with an error code to trigger OnFailure, but that's as ugly as having a separate script to send emails.


My eye is caught by the influxdb TICK stack now, mostly because it comes with docker images and a simple logging plugin that runs a script periodically and takes care of the output by itself ...and you can configure it to send emails when something goes wrong.

Tub
Posts: 299
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Sat Sep 23, 2017 11:09 am UTC

Flumble wrote:I can let the monitor purposefully stop with an error code to trigger OnFailure, but that's as ugly as having a separate script to send emails.

What's ugly about that? Your watchdog reports failure via exit code, and systemd does the notification as configured. That seems like it's working as intended.

It would be cleaner to have the OnFailure on the server where the minecraft server is running, but apparently that's not an option?

Also, what exactly is causing the minecraft server to fail? Does the server process crash? Does the server process enter a deadlock?. Does the whole server crash and fail to reboot? Network connectivity issues? Something else entirely? Depending on the problem, I'd suggest different fixes.

Flumble wrote:My eye is caught by the influxdb TICK stack now, mostly because it comes with docker images and a simple logging plugin that runs a script periodically and takes care of the output by itself ...and you can configure it to send emails when something goes wrong.

That seems like overkill. If you seek reliability, then complexity is your enemy. Unless you're willing to ignore issues like updates, security fixes and general maintenance, then dumping a docker image somewhere is usually more trouble than it's worth. It's certainly more brittle than a sendmail script. I may be a pessimist, but I wouldn't be surprised if that monitoring solution has more downtime than the minecraft server you meant to monitor.


On my home network, I'm using collectd. It's still overkill for monitoring a single service, but it has plugins for many things I want to monitor (network bandwidth on my router, temperature of all CPUs, free disk space and SMART errors etc), supports custom plugins (e.g. I have a few raspberry pis with DHT22 temperature/humidity sensors) and it has threshold-based alerts, including things like "only notify if the server couldn't be reached 3 times in a row".
Distributed logging is supported, e.g. every computer runs a collectd instance, which reports the data to a central server where it gets written to some kind of database. Collectd is flexible about its storage backends. IIRC influxdb works, but I'm using rrdtool for its simplicity and built-in graphing features.

Configuration of the whole thing takes a while, but installation is trivial (most distributions have a package), updating is trivial (the configuration format is very stable; only once did I have to manually adjust something) and the overhead is low enough that I can just start an instance on each computer I need to monitor, including the low-powered raspberry pis.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5084
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Mon Oct 16, 2017 8:07 pm UTC

Calculating the number of years between two dates, particularly when the client wants it to be a decimal... based on # of months out of 12... is apparently a non-trivial problem.

Tub
Posts: 299
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Mon Oct 16, 2017 9:53 pm UTC

The bad news: dates are hard.
The good news: if you cheat, the client (probably) won't notice. Because the client doesn't understand dates either, they have no idea what they're requesting, and thus won't notice even if your results are a few millenia off.

Then again, even though your problem is underspecified, I don't think it'd be more than 2-5 lines with a standard date API?


Return to “Coding”

Who is online

Users browsing this forum: pex and 4 guests