Skip to content

Commit e4a8af0

Browse files
committed
feat(cli): hide normal log disconnect noise
2 parents d36d778 + bfc103c commit e4a8af0

3 files changed

Lines changed: 66 additions & 5 deletions

File tree

include/vix/cli/commands/logs/LogsAnalyzer.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ namespace vix::commands::logs::analyzer
8383
* @brief Number of common network disconnect groups detected.
8484
*/
8585
int networkDisconnectGroups{0};
86+
87+
/**
88+
* @brief Number of normal network noise lines hidden from repeated errors.
89+
*/
90+
int hiddenNormalNoiseLines{0};
8691
};
8792

8893
/**

src/commands/logs/LogsAnalyzer.cpp

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ namespace vix::commands::logs::analyzer
100100
return "connection reset by peer";
101101
}
102102

103-
if (line.find("client closed connection") != std::string::npos ||
103+
if (line.find("client disconnected") != std::string::npos ||
104+
line.find("client_closed") != std::string::npos ||
105+
line.find("client closed connection") != std::string::npos ||
104106
line.find("client prematurely closed connection") != std::string::npos ||
105-
line.find("broken pipe") != std::string::npos)
107+
line.find("broken pipe") != std::string::npos ||
108+
line.find("detail=eof") != std::string::npos ||
109+
line.find(" eof") != std::string::npos)
106110
{
107111
return "client disconnected";
108112
}
@@ -136,6 +140,13 @@ namespace vix::commands::logs::analyzer
136140

137141
return {};
138142
}
143+
144+
bool is_normal_network_noise(const std::string &group)
145+
{
146+
return group == "client disconnected" ||
147+
group == "connection reset by peer" ||
148+
group == "websocket disconnected";
149+
}
139150
}
140151

141152
RepeatedLogReport analyze_repeated_errors(
@@ -154,13 +165,21 @@ namespace vix::commands::logs::analyzer
154165
if (normalized.empty())
155166
continue;
156167

157-
++repeatedCounts[normalized];
158-
159168
const std::string networkGroup =
160169
detect_network_group(normalized);
161170

162171
if (!networkGroup.empty())
172+
{
163173
++networkCounts[networkGroup];
174+
175+
if (is_normal_network_noise(networkGroup))
176+
{
177+
++report.hiddenNormalNoiseLines;
178+
continue;
179+
}
180+
}
181+
182+
++repeatedCounts[normalized];
164183
}
165184

166185
for (const auto &[message, count] : repeatedCounts)
@@ -253,6 +272,14 @@ namespace vix::commands::logs::analyzer
253272
"Detected groups",
254273
std::to_string(report.networkDisconnectGroups));
255274

275+
if (report.hiddenNormalNoiseLines > 0)
276+
{
277+
vix::cli::util::kv(
278+
out,
279+
"Hidden normal noise",
280+
std::to_string(report.hiddenNormalNoiseLines) + " lines");
281+
}
282+
256283
if (report.networkGroups.empty())
257284
{
258285
vix::cli::util::ok_line(

src/commands/logs/LogsRunner.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ namespace vix::commands::logs::runner
5656
return "grep -Ei 'error|failed|failure|exception|panic|fatal|critical|timeout|refused|denied'";
5757
}
5858

59+
std::string grep_analysis_command()
60+
{
61+
return "grep -Ei 'error|failed|failure|exception|panic|fatal|critical|timeout|refused|denied|disconnect|disconnected|closed|reset by peer|broken pipe|eof'";
62+
}
63+
5964
std::string build_journalctl_command(
6065
const LogsConfig &cfg,
6166
const LogsOptions &options)
@@ -91,6 +96,30 @@ namespace vix::commands::logs::runner
9196
return cmd;
9297
}
9398

99+
std::string build_journalctl_analysis_command(
100+
const LogsConfig &cfg,
101+
const LogsOptions &options)
102+
{
103+
std::string cmd =
104+
"journalctl -u " +
105+
shell_quote(cfg.serviceName);
106+
107+
if (!options.since.empty())
108+
{
109+
cmd += " --since ";
110+
cmd += shell_quote(options.since);
111+
}
112+
113+
cmd += " -n ";
114+
cmd += std::to_string(cfg.lines);
115+
cmd += " --no-pager";
116+
117+
cmd += " | ";
118+
cmd += grep_analysis_command();
119+
120+
return cmd;
121+
}
122+
94123
std::vector<std::string> read_command_lines(
95124
const std::string &cmd)
96125
{
@@ -163,7 +192,7 @@ namespace vix::commands::logs::runner
163192
if (!cfg.serviceName.empty())
164193
{
165194
const std::string appCommand =
166-
build_journalctl_command(cfg, options);
195+
build_journalctl_analysis_command(cfg, options);
167196

168197
output::step(std::cout, "Analyze App Errors");
169198
output::ok(std::cout, "reading systemd app errors");

0 commit comments

Comments
 (0)