HACKER Q&A
📣 benjbrooks

How to do simple heartbeat monitoring?


Hey there!

My team is hosting an API that sends open telemetry data to Signoz & manages on-call via PagerDuty. We've configured Signoz to hit Pagerduty when there's a series of 500 errors.

However, our server went down last night and NO opentel data was sent to Signoz. We weren't notified that the server went down as there weren't 500 responses to report. What's the easiest way to have a cron-like query hit our API and integrate with our existing stack? Is this feasible with our existing vendors? Should I have a serverless function running on a timer that uses Pagerduty's API? Should I be migrating to another monitoring service?

Any advice would be appreciated!


  👤 runjake Accepted Answer ✓
If you want super minimal, something like this might work?

  #!/bin/bash

  # Add this script to cron to run at whatever duration you desire.

  # URL to be checked
  URL="https://example.com/test.php"

  # Email for alerts
  EMAIL="root@example.com"

  # Perform the HTTP request and extract the status code with 10 second timeout.
  STATUS=$(curl -o /dev/null -s -w "%{http_code}\n" --max-time 10 $URL)

  # Check if the status code is not 200
  if [ "$STATUS" -ne 200 ]; then
      # Send email alert
      echo "The URL $URL did not return a 200 status code. Status was $STATUS." | mail -s "URL Check Alert" $EMAIL

      # Instead of email, you could send a Slack/Teams/PagerDuty/Pushover/etc, etc alert, with something like:
      curl -X POST https://events.pagerduty.com/...
  fi
Edit: updated with suggested changes.

👤 azeemba
A lot of vendors offer this and call it "synthetic monitoring". They will repeatedly send requests that you configure and record the success rate.

They usually all have pager duty integration as well.

Some examples:

Datadog: https://docs.datadoghq.com/synthetics/ Grafana cloud: https://grafana.com/grafana/plugins/grafana-synthetic-monito...


👤 Gys
https://heartbeat.sh/

Free and easy. Not affiliated, just a happy user.

I combine it with a service like uptimerobot to get messages if the heartbeat stopped.


👤 cweagans
You're looking for a dead man's switch. https://deadmanssnitch.com is a good hosted service or Uptime Kuma (https://github.com/louislam/uptime-kuma) can be configured to do the same thing.

👤 what2
You need to implement a deadman switch. For example if using Prometheus you can configure it to access an HTTP endpoint of a deadman switch service every X seconds. When that service detects you have not accessed it in some time it will alert you.

For example: https://blog.ediri.io/how-to-set-up-a-dead-mans-switch-in-pr...


👤 benjbrooks
Update:

Thanks for your recommendations everyone! We decided to go the route of measuring successful hits on the endpoint associated with our docs (inside our monitoring service). That's the default health check associated with our load balancer, so it gets hit periodically (built-in cron job). We just added a signoz alert that is triggered if the sum of those successful calls over the past X seconds falls below a threshold.


👤 guzik
I can highly recommend Better Stack. We have never been let down by their service.

👤 dvlsg
Depending on your expected traffic patterns and volume, no responses to report for an extended period of time is its own data point.

👤 foobarqux
Healthchecks.io is very simple to use and free for low usage (including 5 free sms per month)

👤 geor9e
I came here ready to pontificate on the wild world of signal processing for electrocardiography and photoplethysmography sensors. Nevermind.

👤 tomsun28
Maybe can try use opensource project apache hertzbeat to monitoring heartbeat. https://github.com/apache/hertzbeat

👤 roboben
https://checklyhq.com

You cannot only do classic heartbeat checks but also high level API (single request and multi request) and Browser checks to make sure your service is behaving as expected.


👤 winrid
I've been using UptimeRobot since 2019 for FastComments, relatively happy. They have a PagerDuty integration, although I just use the built in text/email alerts ATM.

👤 encoderer
This basic monitoring primitive is the first thing we started with at Cronitor[1]. I was a software engineer at my day job and needed a way to be alerted when something doesn't happen.

We have a decent free plan that would probably work for you.

[1] https://news.ycombinator.com/item?id=7917587


👤 notatoad
we use updown.io for this and are happy with it.

there's probably functionality built in to your other monitoring tools, or you could write a little serverless function to to it, but for me i really like to have it isolated. i wanted a tool that's not part of the rest of our monitoring stack, not part of our own codebase, and not something we manage.


👤 jrockway
This is normal website monitoring. There are a billion services that do this. The cloud providers have them. I use Oh Dear.

Something that can happen is that your alerting system stops working. I wrote alertmanager-status to bridge Alertmanager to these website uptime checkers: https://github.com/jrockway/alertmanager-status Basically, Alertmanager gives it a fake alert every so often. If that arrives, then alertmanager-status reports healthy to your website upness checker. If it doesn't arrive in a given time window, then that reports unhealthy, and you'll get an alert that alerts don't work. I use this for my personal stuff and at work and ... Alertmanager has never broken, so it was a waste of time to write ;)


👤 sixhobbits
This is one of those things that _seems_ really simple but the details make it pretty complicated.

Not sure about Signoz and PagerDuty, but there are plenty freemium services like UpTimeRobot that work fine for basics.

And then something like AWS CloudWatch has a lot more advanced options about how to treat missing data.

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitori...

With a lot of knobs to tune around what intervals you need and what counts as 'down', which you'll want to think about pretty carefully given what you need.


👤 et-al
> Should I have a serverless function running on a timer that uses Pagerduty's API?

If you're on AWS, there's already heartbeat monitoring and that can integrate with CloudWatch to notify PagerDuty.


👤 divbzero
If this is a cloud deployment, there might be a recommended method native to your cloud if you search for synthetic monitoring or canary.

For example, AWS recommends using CloudWatch Synthetics to create a canary: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitori...


👤 jarofgreen
I had a similar concern about a custom monitoring script that was regularly writing out a metrics file in Prometheus format to be picked up by the Prometheus node monitor. What if the script breaks?

So I set the script to also write out a metric that was just the time stamp the metrics were last updated. Then it was simple to set up an alert in Prometheus - I can't access the config now so you'll have to look it up yourself, but it was basically "alert if metric less than now minus a time gap"


👤 devoutsalsa
Writing a heartbeat process using UDP for a Fluentd logger is as one of the first things I learned in Elixir! In my case, basically when then there was no heartbeat, the TCP forwarder /w a connection pool would be taken offline. When the heartbeat came back, the forwarder was free to send messages again.

The heartbeat process itself basically just sent pings every second on a UDP port and waited for a reply. If we didn’t get a reply in one second, it’d assume the connection was bad until a ping came again.


👤 ttymck
For my applications, monitored by prometheus + grafana, we have alerts when no data is reported for certain metrics in the past 5 minutes, indicating a malfunction in the subsystem.

With a metric, you can use a monotonic counter to serve as a heartbeat. A timestamp would work. In your monitoring system, when the heartbeat value has not increased in X minutes, you alert.


👤 AH4oFVbPT4f8
https://www.wormly.com

I run multiple e-commerce websites where up time is critical and the types of errors could be anything. I use a service called Wormly that hits specific end points from multiple locations around the world. I'm not affiliated, just a happy customer.


👤 anikdas
We have been using Cloudflare health check at work for this and we have been pretty happy with this. We have this integrated with slack and opsgenie as well.

https://developers.cloudflare.com/health-checks/


👤 jurajmasar
Better Stack offers heartbeat monitoring for free, here's the docs: https://betterstack.com/docs/uptime/cron-and-heartbeat-monit...

Disclaimer: I'm the founder


👤 nicky0
I use Uptime Robot for this: https://uptimerobot.com/

I just configure it to access some endpoint on the API server. It checks it every minute and if it fails (non 200) it pings me.

You can also set it up in more complex ways but this is easy.


👤 kraig911
Back in the day I had a script that would telnet once every so often to a configured time frame and listen on each one. Then another script monitoring the number of each and if the average over 10 mins was less than 90% each node send a message in your manner of choice (email or something)

👤 eps
> What's the easiest way to have a cron-like query hit our API and integrate with our existing stack?

Write a cron job that greps the logs and pulls on your api with curl?

With another 20 minutes of work you can remember the log size on each run and grep only what's new on the next run.


👤 hatthew
Not familiar with Signoz, but a simple solution should be to check if the total number of requests in the past X duration is <= Y, where X depends on how much traffic you see and Y is some threshold such as 1, 1000, or min(yesterday, last_week).

👤 compumike
We do this at Heii On-Call: https://heiioncall.com/

Outbound Probes to hit your exposed HTTP services, or Inbound Liveness for your own cron jobs etc to check in.


👤 rozenmd
OnlineOrNot has a cron job/scheduled task monitoring system that integrates with PagerDuty fwiw

edit: on second read, it sounds like regular uptime monitoring for your API would do the trick


👤 renewiltord
All monitoring systems have a no-data condition. Use that.

👤 seper8
I use grafana. Setup an endpoint on the backend that uses things like the database to check if it can still connect. Every 10 sec. If it fails I get a text.

👤 Atotalnoob
To me, this is the biggest problem with OpenTelemetry.

There isn’t a good way to solve this using a PUSH model that isn’t somewhat of a hack or using another external tool


👤 GauntletWizard
Prometheus makes this a basic part of monitoring, "up" is a synthetic metric based on whether or not metrics gathering succeeds.

👤 nprateem
Invert the flux capacitor so it fires an alert if it doesn't receive a heartbeat. This should be a separate alert to your 500 one.

👤 beeboobaa3
Just have your monitoring system hit some health check endpoint of yours to verify everything is reachable & healthy.

👤 papa_autist
healthchecks.io

👤 lmeyerov
We have two different external uptime status monitoring services, which has helped

👤 Joel_Mckay
In general the "are-you-alive" messages are redundant, as the data exchange messages serves the same purpose.

While my legal encumbrances prohibit helping you with actual code, I would recommend looking at watchdog processes.

For example, even a simple systemd periodic trigger that runs a script every minute that does general house keeping can work. i.e. a small script has the advantage of minimal library dependencies, fast/finite run state, and flexible behavior (checking cpu/network loads for nuisance traffic, and playing possum when a set threshold exceeded.)

Distributed systems is hard, but polling generally does not scale well (i.e. the cost of a self-check is locally fixed, but balloons on a cluster if going beyond a few fixed peer-checks).

And yeah, some clowns that think they are James Bond have been DDoS small boxes on Sun (they seem to be blindly hitting dns and ntp ports hard). We had to reset the tripwire on a 6 year old hobby host too.

tip, rate limiting firewall rules that expose whitelisted peers/admins to bandwidth guarantees is wise. Otherwise any cluster/heartbeats can be choked into a degraded state.

Don't take it personally, and enjoy a muffin with your tea. =3


👤 devneelpatel
OneUptime.com does this for you and is 100% open-source.

👤 liveoneggs
statuscake & new relic both have generous free tiers

👤 g8oz
I've heard good things about UptimeRobot.

👤 nsguy
I clicked to say something about Instrumentation Amplifiers or interfacing with chest straps ;)

You might want to use a different service for monitoring your stack just to make sure you have some redundancy there. Seems like you got an answer for how to do this with Signoz but if that is down then you won't know.


👤 jeffbarg
Believe you can do this in Signoz: https://signoz.io/docs/monitor-http-endpoints/