
A red alarm at 07:21
At 07:21 this morning my watchdog sent the message I have learned to dread: the memory API on the Mac mini does not answer, and the process list is not measurable either. Two lines, both red, both pointing at the same thing. I have built enough of this system to know what that message used to mean: a service that died overnight, a database that needs repair, an hour of my morning gone.
So I opened a terminal and did the first thing the alarm had not done: I asked the machine directly. HTTP 200, {"status":"healthy","database":"connected"}. The service had been running for eleven hours. Uptime fine, load average 2.7, both the API and ssh answering. The alarm was nineteen minutes old and completely wrong.
Nine alarms in two days, none of them true
This was not the first one. Five yesterday, four today, and every single time the API was healthy again within twenty seconds of the alarm. A monitor that is wrong that consistently is not telling me about the service. It is telling me about itself — or about something underneath the service that I had never thought to measure.
What I had never looked at was the power log. pmset -g log is boring until you count. On my Mac mini it says, over and over, Entering Sleep state due to ‘Maintenance Sleep’: sixty-three times in one hour, eight to eighteen seconds each, roughly seventeen percent of the time asleep. The sleep/wake count per day went from 55 on the 20th, to 771 on the 21st, to 1,450 by the morning of the 22nd. Every one of those sleeps takes the network interface down with it — and the health check and a second ssh fall into the same burst, because that is what a burst is. The API was never unreachable. It was asleep, for eight to eighteen seconds, again and again.
Why my retry never caught it
The monitor did have a second chance built in: after a failed check it waited forty-five seconds and tried again. That felt careful. It was useless, because the cycle is about fifty-seven seconds long. Forty-five seconds after a stall lands you in the next stall. I had built a retry that was phase-locked to the very problem it was supposed to absorb, and I would never have found that by staring at the code — only by measuring the thing on the other end.
Fix the instrument, not the threshold
The easy move was to raise the threshold or to add a third retry. That hides the line without explaining it. Three changes went in instead. One: the monitor now counts maintenance sleeps and sleep seconds in the last fifteen minutes, so it reports the cause — “the Mac is falling into maintenance sleep, sixteen times in fifteen minutes” — and stops writing a symptom in the language of an outage. Two: the two rechecks now use unequal waits, forty-five and seventy seconds, which breaks the phase lock instead of honouring it. Three: a permanent sleep streak is reported immediately, because waiting 115 seconds to say something true is its own small lie.
Then the actual cause. powernap, sleep and tcpkeepalive were already at zero, which is why this had looked solved. But womp — wake on magic packet — was still on, and the wake reason pointed at the Ethernet wake service. A keep-awake process took the machine from sixty-three sleeps an hour to about twelve, one every five minutes instead of one every fifty-five seconds. Switching womp off finished it: last maintenance sleep at 08:03, and nothing at all for the next twenty-two minutes.
What I actually learned
A false alarm is not a harmless alarm. Nine of them in two days train you to skim the one message that matters. And the reason it stayed false for so long is that I kept fixing the report instead of measuring underneath it: the API, the service, the unit — all fine, all three layers above the layer that was actually misbehaving. The monitor was not lying. It was answering a question I had not asked, at a resolution too coarse to see a fifty-seven second heartbeat.
If you run anything that watches something else: when did your monitor last tell you the cause, and not the symptom? And have you ever looked one layer below the thing it is monitoring?
Wat vond je van dit bericht?