diff --git a/CHANGELOG.md b/CHANGELOG.md index 121ce0f295ef998e5282b45e5439509c6994c4f2..96f90f4b3026bab08e8f8936d5f5f88d2e928c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/dependencies.yum.txt b/dependencies.yum.txt index 1db6d4d73c4f82221dc3e08ae252e9233d62637f..dab0d125b9cf091c2e852f360b868a2b59f9fb79 100644 --- a/dependencies.yum.txt +++ b/dependencies.yum.txt @@ -6,3 +6,4 @@ curl cronie smartmontools pciutils +fping diff --git a/src/metric-generators/cephpingmon.sh b/src/metric-generators/cephpingmon.sh index dfc43d198790d53d286292c3f46aee4abc16a9f8..afafc5bc87303dc9bb2cbb56e59ee7972d0d59ca 100755 --- a/src/metric-generators/cephpingmon.sh +++ b/src/metric-generators/cephpingmon.sh @@ -1,5 +1,4 @@ #!/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