Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore(NODE-1241): Move IPv4 connectivity check to be a separate service
- Loading branch information
1 parent
16c08f4
commit b5859f9
Showing
5 changed files
with
50 additions
and
68 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
ic-os/guestos/rootfs/etc/systemd/system/ipv4-connectivity-check.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Check IPv4 connectivity | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/opt/ic/bin/ipv4-connectivity-check.sh |
10 changes: 10 additions & 0 deletions
10
ic-os/guestos/rootfs/etc/systemd/system/ipv4-connectivity-check.timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[Unit] | ||
Description=IPv4 connectivity timer | ||
|
||
[Timer] | ||
OnBootSec=60s | ||
OnUnitActiveSec=60s | ||
Unit=ipv4-connectivity-check.service | ||
|
||
[Install] | ||
WantedBy=timers.target |
29 changes: 29 additions & 0 deletions
29
ic-os/guestos/rootfs/opt/ic/bin/ipv4-connectivity-check.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/bin/bash | ||
|
||
set -o nounset | ||
set -o pipefail | ||
|
||
METRICS_DIR="/run/node_exporter/collector_textfile" | ||
|
||
write_metric() { | ||
local name=$1 | ||
local value=$2 | ||
local help=$3 | ||
local type=$4 | ||
|
||
echo -e "# HELP ${name} ${help}\n# TYPE ${type}\n${name} ${value}" >"${METRICS_DIR}/${name}.prom" | ||
} | ||
|
||
endpoints=("1.1.1.1" "8.8.8.8" "9.9.9.9") | ||
|
||
connectivity_status=0 | ||
|
||
for endpoint in "${endpoints[@]}"; do | ||
# Using curl instead of ping as it requires less permissions | ||
if curl --connect-timeout 10 "${endpoint}" &>/dev/null; then | ||
connectivity_status=1 | ||
break | ||
fi | ||
done | ||
|
||
write_metric "ipv4_connectivity_status" "${connectivity_status}" "Status of IPv4 connectivity" "gauge" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters