From 2ae228756ad75f25c3e44714a8f169d489f1a2f2 Mon Sep 17 00:00:00 2001 From: Maria Lisina Date: Fri, 13 Feb 2026 18:03:41 +0300 Subject: units/ping: Add system latency Signed-off-by: Maria Lisina --- bot.zsh | 2 ++ operators/callback_ping.zsh | 5 +++-- operators/command_ping.zsh | 5 +++-- units/ping.zsh | 13 +++++++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/bot.zsh b/bot.zsh index 90fcb00..8010f91 100755 --- a/bot.zsh +++ b/bot.zsh @@ -939,6 +939,8 @@ do continue fi + latency_sys=$(strftime %s%N) + if ! jq -e '.' <<< "${input_data}" > /dev/null then log_text="getUpdates: An unknown error occurred, sleeping for ${sleep_time} seconds" diff --git a/operators/callback_ping.zsh b/operators/callback_ping.zsh index b728bc4..2a3c541 100644 --- a/operators/callback_ping.zsh +++ b/operators/callback_ping.zsh @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 output_text="Measuring latency..." -latency_init=$(strftime %s%N) +latency_sysf=$(strftime %s%N) +latency_net=$(strftime %s%N) if ! output_data="$( curl --connect-timeout ${connrefused_timeout} \ @@ -29,7 +30,7 @@ then return fi -latency_fin=$(strftime %s%N) +latency_netf=$(strftime %s%N) if ! jq -e '.' <<< "${output_data}" > /dev/null then diff --git a/operators/command_ping.zsh b/operators/command_ping.zsh index 546e588..dfb6016 100644 --- a/operators/command_ping.zsh +++ b/operators/command_ping.zsh @@ -3,7 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 output_text="Measuring latency..." -latency_init=$(strftime %s%N) +latency_sysf=$(strftime %s%N) +latency_net=$(strftime %s%N) if ! output_data="$( curl --connect-timeout ${connrefused_timeout} \ @@ -30,7 +31,7 @@ then return fi -latency_fin=$(strftime %s%N) +latency_netf=$(strftime %s%N) if ! jq -e '.' <<< "${output_data}" > /dev/null then diff --git a/units/ping.zsh b/units/ping.zsh index d6ca158..6bd2c72 100644 --- a/units/ping.zsh +++ b/units/ping.zsh @@ -9,6 +9,10 @@ uptime_table=( 1 s ) +latency_sys=$(((latency_sysf - latency_sys) / 1000000)) +latency_net=$(((latency_netf - latency_net) / 1000000)) +latency_all=$((latency_sys + latency_net)) + uptime_time=$(($(strftime %s) - startup_time + 1)) while [[ ${uptime_time} -gt 0 && ${#uptime_table} -ge 2 ]] @@ -27,10 +31,11 @@ do shift 2 uptime_table done -latency_text=$(((latency_fin - latency_init) / 1000000)) - -output_text="$(printf "Uptime:%s" "${uptime_text}")" -output_text="$(printf "%s\nLatency: %ums" "${output_text}" "${latency_text}")" +output_text="Latency" +output_text="$(printf "%s\nSystem: %ums" "${output_text}" "${latency_sys}")" +output_text="$(printf "%s\nNetwork: %ums" "${output_text}" "${latency_net}")" +output_text="$(printf "%s\nOverall: %ums" "${output_text}" "${latency_all}")" +output_text="$(printf "%s\n\nUptime:%s" "${output_text}" "${uptime_text}")" keyboard_text1="Refresh" keyboard_data1="ping" -- cgit v1.2.3