This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 9cea4173b7 traffic_top: Allow traffic_top to be running while TS is
down. (#11065)
9cea4173b7 is described below
commit 9cea4173b787a546c11e000b7f780da77306a4c6
Author: Damian Meden <[email protected]>
AuthorDate: Tue Feb 13 11:35:02 2024 +0100
traffic_top: Allow traffic_top to be running while TS is down. (#11065)
This also adds a "connecting" message at the bottom of the panel.
---
src/traffic_top/stats.h | 2 +-
src/traffic_top/traffic_top.cc | 24 ++++++++++++++++++------
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/src/traffic_top/stats.h b/src/traffic_top/stats.h
index 0ca3f312d9..8025115b72 100644
--- a/src/traffic_top/stats.h
+++ b/src/traffic_top/stats.h
@@ -353,7 +353,7 @@ public:
if (key == "total_time") {
old = old / 10000000;
}
- value = (value - old) / _time_diff;
+ value = _time_diff ? (value - old) / _time_diff : 0;
}
} else if (type == 3 || type == 4) {
double numerator = 0;
diff --git a/src/traffic_top/traffic_top.cc b/src/traffic_top/traffic_top.cc
index a017d2248d..10ebb83a09 100644
--- a/src/traffic_top/traffic_top.cc
+++ b/src/traffic_top/traffic_top.cc
@@ -372,6 +372,9 @@ main_stats_page(Stats &stats)
makeTable(62, 17, server2, stats);
}
+enum class HostStatus { UP, DOWN };
+char reconnecting_animation[4] = {'|', '/', '-', '\\'};
+
//----------------------------------------------------------------------------
int
main(int argc, const char **argv)
@@ -400,9 +403,10 @@ main(int argc, const char **argv)
usage(argument_descriptions, countof(argument_descriptions), USAGE);
}
+ HostStatus host_status{HostStatus::DOWN};
Stats stats;
- if (!stats.getStats()) {
- return 2;
+ if (stats.getStats()) {
+ host_status = HostStatus::UP;
}
const string &host = stats.getHost();
@@ -428,6 +432,7 @@ main(int argc, const char **argv)
Page page = MAIN_PAGE;
string page_alt = "(r)esponse";
+ int animation_index{0};
while (true) {
attron(COLOR_PAIR(colorPair::border));
attron(A_BOLD);
@@ -440,7 +445,16 @@ main(int argc, const char **argv)
strftime(timeBuf, sizeof(timeBuf), "%H:%M:%S", &nowtm);
stats.getStat("version", version);
- mvprintw(23, 0, "%-20.20s %30s (q)uit (h)elp (%c)bsolute ",
host.c_str(), page_alt.c_str(), absolute ? 'A' : 'a');
+ std::string hh;
+ if (host_status == HostStatus::DOWN) {
+ hh.append("connecting ");
+ hh.append(1, reconnecting_animation[animation_index % 4]);
+ ++animation_index;
+ } else {
+ hh = host;
+ }
+
+ mvprintw(23, 0, "%-20.20s %30s (q)uit (h)elp (%c)bsolute ", hh.c_str(),
page_alt.c_str(), absolute ? 'A' : 'a');
attroff(COLOR_PAIR(colorPair::border));
attroff(A_BOLD);
@@ -472,9 +486,7 @@ main(int argc, const char **argv)
case 'a':
absolute = stats.toggleAbsolute();
}
- if (!stats.getStats()) {
- goto quit;
- }
+ host_status = !stats.getStats() ? HostStatus::DOWN : HostStatus::UP;
clear();
}