修完bug

This commit is contained in:
2026-08-10 16:36:12 +08:00
parent 18e92d3631
commit d28edab2d7
12 changed files with 389 additions and 158 deletions
+64 -27
View File
@@ -33,6 +33,12 @@ public:
BIN_Msg_Buffer msg_buffer{};
adminive::Managed_Value<Output_Format> output_format;
Frequency_Limit_Multi sbs_flm{};
Psc::Throughput_Statistics queued_statistics;
Psc::Throughput_Statistics dispatched_statistics;
Psc::Throughput_Statistics dropped_statistics;
Psc::Throughput_Statistics filtered_statistics;
std::atomic<std::uint64_t> mode_s_limit_drop_total{};
std::atomic<std::uint64_t> mode_other_limit_drop_total{};
asio::awaitable<void> loop_coro() final;
virtual void handle_in_loop() {
}
@@ -60,7 +66,17 @@ public:
return Psc::JSON::object();
}
virtual Psc::JSON get_state_json() {
Psc::JSON ret = msg_buffer.state_json();
Psc::JSON pipeline = Psc::JSON::object();
pipeline.append({"queued", queued_statistics.to_json()});
pipeline.append({"dispatched", dispatched_statistics.to_json()});
pipeline.append({"dropped", dropped_statistics.to_json()});
pipeline.append({"filtered", filtered_statistics.to_json()});
pipeline.append({"mode_s_limit_drop_total", mode_s_limit_drop_total.load()});
pipeline.append({"mode_other_limit_drop_total", mode_other_limit_drop_total.load()});
Psc::JSON ret = Psc::JSON::object();
ret.append({"lifecycle", lifecycle_state_json()});
ret.append({"queue", msg_buffer.state_json()});
ret.append({"pipeline", pipeline});
ret += get_custom_state_json();
return ret;
}
@@ -68,6 +84,22 @@ public:
return "Data_Feed{" + key + "," + (enabled() ? "true" : "false") + "," + type + "}";
}
bool registered();
void record_queued(std::size_t bytes) {
queued_statistics.update(bytes);
}
void record_dispatched(std::size_t bytes) {
dispatched_statistics.update(bytes);
}
void record_dropped(std::size_t bytes, bool mode_s) {
dropped_statistics.update(bytes);
if (mode_s)
++mode_s_limit_drop_total;
else
++mode_other_limit_drop_total;
}
void record_filtered(std::size_t bytes) {
filtered_statistics.update(bytes);
}
protected:
Data_Feed() = default;
Frequency_Limit too_many_msg_limit;
@@ -96,11 +128,13 @@ public:
adminive::Managed_Value<Data_Feed_TCP_Server_Data> specific;
Psc::asio_socket::TCP_Server_Coro svr;
Psc::JSON get_custom_state_json() override {
auto& state = svr.state;
auto value = specific.read([](const auto& value) { return value; });
auto ret = value.to_base_json();
ret.key = "fixed";
auto result = VAR_JSON_1(state);
Psc::JSON result = Psc::JSON::object();
result.append({"transport_state", Psc::to_string(svr.state.load())});
result.append({"transport", svr.get_statistics_json()});
result.append({"client_count", svr.get_all_clients().size()});
result.append(ret);
return result;
}
@@ -146,21 +180,7 @@ public:
auto& cur_port = info.sockaddr.port;
cur.append({"base", VAR_STR_3(cur_ip, cur_port, fd)});
cur.append({"state", conn->send_buffer.state_str()});
{
auto& ins = conn->push_speed.instant_speed;
auto& avr = conn->push_speed.average_speed;
cur.append({"send_speed(KB/s)", VAR_STR_2(ins, avr)});
}
{
auto& ins = conn->lose_speed.instant_speed;
auto& avr = conn->lose_speed.average_speed;
cur.append({"lose_speed(KB/s)", VAR_STR_2(ins, avr)});
}
{
auto& ins = conn->send_num.instant;
auto& avr = conn->send_num.average;
cur.append({"send_num(byte/count)", VAR_STR_2(ins, avr)});
}
cur.append({"statistics", conn->statistics.to_json()});
ret.append(cur);
}
return ret;
@@ -195,8 +215,10 @@ public:
co_return;
}
Psc::JSON get_custom_state_json() override {
auto& state = cli.state;
return VAR_JSON_1(state);
Psc::JSON ret = Psc::JSON::object();
ret.append({"transport_state", Psc::to_string(cli.state.load())});
ret.append({"transport", cli.statistics.to_json()});
return ret;
}
Psc::asio_socket::TCP_Client_Coro cli;
~Data_Feed_TCP_Client() override = default;
@@ -243,8 +265,20 @@ class Data_Feed_UDP_Server : public Data_Feed {
public:
adminive::Managed_Value<Data_Feed_UDP_Server_Data> specific;
Psc::JSON get_custom_state_json() override {
auto& state = svr.state;
return VAR_JSON_1(state);
const auto clients = svr.get_all_clients();
const auto now = Psc::get_current_millisecond_timestamp();
std::size_t active_client_count = 0;
for (const auto& client : clients) {
const auto last_activity = client.statistics->last_activity_unix_ms();
if (last_activity != 0 && now - last_activity <= 30000)
++active_client_count;
}
Psc::JSON ret = Psc::JSON::object();
ret.append({"transport_state", Psc::to_string(svr.state.load())});
ret.append({"transport", svr.statistics.to_json()});
ret.append({"client_count", clients.size()});
ret.append({"active_client_count", active_client_count});
return ret;
}
Data_Feed_UDP_Server() = default;
~Data_Feed_UDP_Server() override = default;
@@ -252,10 +286,11 @@ public:
asio::awaitable<void> send_coro(std::string_view data) override;
[[nodiscard]] Psc::JSON get_clients_json() const {
Psc::JSON ret = Psc::JSON::array();
for (const auto& i : svr.clients) {
for (const auto& client : svr.get_all_clients()) {
Psc::JSON cur = Psc::JSON::object();
cur.append({"ip", i.ip});
cur.append({"port", i.port});
cur.append({"ip", client.address.ip});
cur.append({"port", client.address.port});
cur.append({"statistics", client.statistics->to_json()});
ret.append(cur);
}
return ret;
@@ -297,8 +332,10 @@ class Data_Feed_UDP_Client : public Data_Feed {
public:
adminive::Managed_Value<Data_Feed_UDP_Client_Data> specific;
Psc::JSON get_custom_state_json() override {
auto& state = cli.state;
return VAR_JSON_1(state);
Psc::JSON ret = Psc::JSON::object();
ret.append({"transport_state", Psc::to_string(cli.state.load())});
ret.append({"transport", cli.statistics.to_json()});
return ret;
}
asio::awaitable<void> handle_in_loop_coro() override {
co_await cli.tick_coro();