Use Heartbeat to determine if a service is reachable via ICMP, TCP or HTTP

Saidani Mohamed El Amine
3 min readAug 9, 2024

--

After installing Heartbeat as we did in the previous blog / video today we will configure Heartbeat to use the HTTP, TCP, and ICMP Monitors

Here’s the configuration of the all of the three monitors,

heartbeat.monitors:
- type: http
# Set enabled to true (or delete the following line) to enable this example monitor
enabled: true
# ID used to uniquely identify this monitor in elasticsearch even if the config changes
id: my-monitor-http
# Human readable display name for this service in Uptime UI and elsewhere
name: My Monitor HTTP
# List or urls to query
urls: ["http://localhost:5601"]
# Configure task schedule
schedule: '@every 10s'

- type: icmp # monitor type `icmp` (requires root) uses ICMP Echo Request to ping
# configured hosts

# ID used to uniquely identify this monitor in elasticsearch even if the config changes
id: my-monitor-icmp
enabled: true
# Human readable display name for this service in Uptime UI and elsewhere
name: my-icmp-monitor

# Configure task schedule using cron-like syntax
schedule: '@every 10s' # exactly every 5 seconds like 10:00:00, 10:00:05, ...

# List of hosts to ping
hosts: ["127.0.0.1"]

# Configure IP protocol types to ping on if hostnames are configured.
# Ping all resolvable IPs if `mode` is `all`, or only one IP if `mode` is `any`.
ipv4: true
ipv6: true
mode: any

# Total running time per ping test.
timeout: 16s

# Waiting duration until another ICMP Echo Request is emitted.
wait: 1s

- type: tcp # monitor type `tcp`. Connect via TCP and optionally verify endpoint
# by sending/receiving a custom payload

# ID used to uniquely identify this monitor in elasticsearch even if the config changes
id: my-tcp-monitor
enabled: true
# Human readable display name for this service in Uptime UI and elsewhere
name: My TCP monitor

# Configure task schedule
schedule: '@every 5s' # every 5 seconds from start of beat

hosts: ["localhost:9200"]

# Configure IP protocol types to ping on if hostnames are configured.
# Ping all resolvable IPs if `mode` is `all`, or only one IP if `mode` is `any`.
ipv4: true
ipv6: true
mode: any

Once you add the configurations, save and restart the Heartbeat,

note: the owner of the file should be root otherwise the ICMP Monitor will not work.

Now go to kibana >> Observability >> Uptime Monitors, you will see this:

when you click on each monitor it will redirect you to more detailed page about each monitor:

as you can see all are up and running,

Now let’s change one of the monitors and see what happen:

for the HTTP monitor change the port from 5601 to 5602 (this last there’s no service, mean this monitor will not get any response)

and you should be seeing this

and you will have more details about the service when it’s down.

let me know if you faced any issue in the comment section ^^ will see you in the next blog.

--

--

Saidani Mohamed El Amine

Currently working as DevSecOps consultant with focus on security, monitoring, Big Data, and related topics.