Skip to content
Snippets Groups Projects
Commit fb5ddac9 authored by Josef Němec's avatar Josef Němec
Browse files

Finalize cephpingmon

parent f92f3a9f
No related branches found
No related tags found
1 merge request!12Finalize cephpingmon
......@@ -6,9 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
## [1.3.4] - 2024-03-19
## [1.3.4] - 2024-03-25
### Added
- cephpingmon added as optional module (default behavior unchanged)
- cephpingmon added as optional module (default behavior unchanged), add fping dependency
## [1.3.3] - 2023-10-25
### Fixed
......
......@@ -6,3 +6,4 @@ curl
cronie
smartmontools
pciutils
fping
#!/bin/bash
set -eo pipefail
METRIC_NAME="cephpingmon_endpoint_accessible"
if [[ -z "${CEPH_IPS}" ]]; then
......@@ -9,24 +8,37 @@ if [[ -z "${MTU_SIZE}" ]]; then
MTU_SIZE=8972
fi
printf '# HELP %s: Ceph endpoint ping success ratio. (1 ~ no loss, 0 ~ complete loss)\n' $METRIC_NAME
function publish_metrics_nofrag {
local ping_result
local loss_percent
local success_ratio
local fragmentation="no"
# $1 == ip address, $2 == yes/no fragmentation allowed
function publish_metric {
if [[ $2 == "yes" ]]; then
local ping_result=$(ping -c4 -s $MTU_SIZE $ip || echo "0 received, 100% packet loss")
else
local ping_result=$(ping -c4 -s $MTU_SIZE -M do -q $ip || echo "0 received, 100% packet loss")
fi
for ip in $CEPH_IPS; do
ping_result=$(ping -q -c4 -W 1 -s $MTU_SIZE -M do $ip)
loss_percent=$(echo ${ping_result} | sed -n -e 's/^.*, \(.*\)% packet.*/\1/p')
success_ratio=$(echo "scale=2 ; 1 - ${loss_percent} / 100" | bc)
LC_NUMERIC=C printf '%s{endpoint_ip="%s", fragmentation="%s"} %.2f\n' \
"${METRIC_NAME}" $ip $fragmentation "${success_ratio}"
done
}
local packet_loss_percent=$(echo ${ping_result} | sed -n -e 's/^.*, \(.*\)% packet.*/\1/p')
local ping_success_ratio=$(echo "scale=2 ; 1 - ${packet_loss_percent} / 100" | bc)
function publish_metrics_frag {
local ip
local loss_percent
local success_ratio
local fragmentation="yes"
LC_NUMERIC=C printf '%s{ip="%s", fragmentation="%s"} %.2f\n' \
"${METRIC_NAME}" "$1" "$2" "${ping_success_ratio}"
while IFS= read -r line; do
ip=$(echo $line | cut -d' ' -f1)
loss_percent=$(echo $line | cut -d' ' -f5 | cut -d'/' -f3 | tr -d % | tr -d ,)
success_ratio=$(echo "scale=2 ; 1 - ${loss_percent} / 100" | bc)
LC_NUMERIC=C printf '%s{endpoint_ip="%s", fragmentation="%s"} %.2f\n' \
"${METRIC_NAME}" $ip $fragmentation "${success_ratio}"
done <<< "$1"
}
for ip in $CEPH_IPS; do
publish_metric $ip yes
publish_metric $ip no
done
printf '# HELP %s: Ceph endpoint ping success ratio. (1 ~ no loss, 0 ~ complete loss)\n' $METRIC_NAME
ping_result=$(fping -q -c4 -b $MTU_SIZE $CEPH_IPS 2>&1)
publish_metrics_frag "${ping_result}"
publish_metrics_nofrag
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment