-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Federico Ceratto
committed
Apr 3, 2020
1 parent
c19497f
commit 58b5bd9
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
ansible/roles/node_exporter/files/db_replication_mon_active
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,22 @@ | ||
#!/bin/bash | ||
# Deployed by ansible | ||
# See roles/node_exporter/files/db_replication_mon_active | ||
# active database --> standby | ||
# | ||
# Errors are reported as RTT=0 | ||
|
||
set -u | ||
FN=/run/nodeexp/db_replication_socket.prom | ||
while true; do | ||
socket_rtt=$(ss -ntpi state established 'dst 37.218.242.175' | tr -s " " "\n" | grep ^rtt: | cut -c5- | cut -d'/' -f1) | ||
socket_rtt=${socket_rtt:-0} | ||
ping_rtt=$(ping -w 1 -c 1 10.1.0.1 | tail -n1 | cut -d'/' -f5) | ||
ping_rtt=${ping_rtt:-0} | ||
|
||
cat <<EOF > $FN.tmp | ||
db_replication_rtt{role="active"} $socket_rtt | ||
ping_rtt{role="active"} $ping_rtt | ||
EOF | ||
mv $FN.tmp $FN | ||
sleep 1 | ||
done |
22 changes: 22 additions & 0 deletions
22
ansible/roles/node_exporter/files/db_replication_mon_standby
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,22 @@ | ||
#!/bin/bash | ||
# Deployed by ansible | ||
# See roles/node_exporter/files/db_replication_mon_standby | ||
# standby database --> active | ||
# | ||
# Errors are reported as RTT=0 | ||
|
||
set -u | ||
FN=/run/nodeexp/db_replication_socket.prom | ||
while true; do | ||
socket_rtt=$(ss -ntpi state established 'dst 37.218.240.56 dport = 5432' | tr -s " " "\n" | grep ^rtt: | cut -c5- | cut -d'/' -f1) | ||
socket_rtt=${socket_rtt:-0} | ||
ping_rtt=$(ping -w 1 -c 1 10.1.0.2 | tail -n1 | cut -d'/' -f5) | ||
ping_rtt=${ping_rtt:-0} | ||
|
||
cat <<EOF > $FN.tmp | ||
db_replication_rtt{role="standby"} $socket_rtt | ||
ping_rtt{role="standby"} $ping_rtt | ||
EOF | ||
mv $FN.tmp $FN | ||
sleep 1 | ||
done |
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
27 changes: 27 additions & 0 deletions
27
ansible/roles/node_exporter/templates/db_replication_mon.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,27 @@ | ||
# Deployed by ansible | ||
# see roles/node_exporter/templates/db_replication_mon.service | ||
[Unit] | ||
Description=DB replication monitor | ||
|
||
[Service] | ||
User=root | ||
Group=root | ||
|
||
ExecStartPre=/usr/bin/install --owner root --group root --mode 0755 --directory {{ node_exporter_textfiles_path }} | ||
ExecStart=/srv/db_replication_mon | ||
KillMode=process | ||
Restart=always | ||
|
||
# Hardening | ||
CapabilityBoundingSet=CAP_SETUID CAP_SETGID CAP_NET_RAW | ||
SystemCallFilter=~@clock @debug @cpu-emulation @keyring @module @mount @obsolete @raw-io @reboot @swap | ||
NoNewPrivileges=yes | ||
PrivateDevices=yes | ||
PrivateTmp=yes | ||
ProtectHome=yes | ||
ProtectSystem=full | ||
ProtectKernelModules=yes | ||
ProtectKernelTunables=yes | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,8 @@ | ||
PostgreSQL metadb database | ||
|
||
Deploys a temporary traffic forwarder using A VPN | ||
HKG -> mia-ps-test.ooni.nu -> AMS | ||
|
||
Runs db_replication_mon.service on HKG and AMS db to monitor the replication | ||
sudo systemctl status db_replication_mon.service | ||
sudo journalctl -f -u db_replication_mon |