4

I'm trying to figure what's the right way for me to be notified when some systemd service is having problems. Manually checking systemctl status isn't a sustainable option; at the very least I want to have a simple tray icon, like just green or red. Some sounds and/or visual notifications can be useful too. Surprisingly I don't seem to find any existing tools for that, so the best I can think of is to write my own, maybe some simple bash script which would poll systemctl once in a while, and update the icon status.

Pretty poor but alas.

Before I actually start spending time on that, want to make sure, am I by any chance missing some better options?

1
  • systemd has a dbus interface which you can use to subscribe to events -- see dbus-monitor and similar. Commented Jul 5, 2021 at 22:56

3 Answers 3

0
sudo systemctl --type=service

sudo systemctl --state=active  

sudo systemctl --state=failed 

journalctl -b -p err

These should be enough to monitor and to find any misbehaving services.

6
  • Your answer assumes I'm gonna be executing those commands manually, but as I mentioned in my question, checking it manually isn't a sustainable option. I have better things to do, you know; and I just need some status icon plus ideally some visual+sound notification when something breaks. And when I get that notification, then I'm going to get logs etc. Commented Jul 6, 2021 at 16:04
  • 1
    @DmitryFrank so your computer will play marche funebre, you will start fixing the service, then immediately after, you will get a support call and tell them you are on it. Commented Jul 24, 2022 at 6:34
  • @DmitryFrank So put it in cron. Commented Sep 12, 2023 at 20:34
  • What's the point of having that in cron @TrippKinetics? Those commands simply print something out, for the caller to read it and figure what to do with it. So if we want to have it in cron, at the very least we should also have something to parse the output, and then do something, like enable or disable a tray icon. Commented Sep 13, 2023 at 6:01
  • 1
    Yeah that's technically an option, but I just don't agree that emailing logs that I have to check manually is a good way to monitor services. I have better things to do than reading emailed logs every day; I want the computer to check things for me and let me know when there's a problem. In fact I already implemented a tool to show a simple green or red tray icon, hopefully I'll find the time to polish it and then will share it on github. Commented Sep 14, 2023 at 21:22
0

Use the check_systemd command line tool from the Nagios monitoring plugin collection. You can just call this without parameter or setting up Nagios (which is a hell to do).

On Ubuntu you only need to call:

sudo apt -y install monitoring-plugins-systemd 

and then you can check

/usr/lib/nagios/plugins/check_systemd 

If $? is 0 all is ok, if 1 its bad and 2 if its critical

All other return values should tell you to get the heck out because the world is on fire.

0

Systemd's internal monitoring for services is really basic and will only report "this service has stopped and returned a non-zero exit code", which is also one of the conditions it can "fix" by restarting the service.

Systemd services are also expected to close down on their own when they are no longer needed, which is not an error, however systemd does not usually have an insight if that is what happened, because once a service is started, systemd is no longer involved as a mediator.

If you want actual service monitoring, you need a monitoring solution like nagios that can also verify that services are responding in appropriate time, give meaningful answers, and follow protocol conventions (e.g. an HTTPS server should present a valid certificate, and deliver a static file with an error code indicating success within a short time).

No graphical monitoring tools exist because there is no group of users for which such alerts would be actionable (i.e. they are well enough acquainted with systemd to actually be able to investigate), and who are at the same time content with the limited monitoring implemented here.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.