修完bug
This commit is contained in:
@@ -453,7 +453,7 @@ Data_Source_Row source_row(const std::shared_ptr<Data_Source>& source) {
|
||||
source->settings.read([&](const auto& value) {
|
||||
row.config = value;
|
||||
});
|
||||
row.state = Psc::to_string(source->state);
|
||||
row.state = Psc::to_string(source->state.load());
|
||||
if(const auto source_value = dynamic_cast<TCP_Client_Data_Source*>(source.get())) {
|
||||
source_value->specific.read([&](const auto& value) {
|
||||
row.ip = value.ip;
|
||||
@@ -533,7 +533,7 @@ Data_Feed_Row feed_row(const std::shared_ptr<Data_Feed>& feed) {
|
||||
row.output_format = value;
|
||||
row.format = value.type;
|
||||
});
|
||||
row.state = Psc::to_string(feed->state);
|
||||
row.state = Psc::to_string(feed->state.load());
|
||||
if(const auto feed_value = dynamic_cast<Data_Feed_TCP_Server*>(feed.get())) {
|
||||
feed_value->specific.read([&](const auto& value) {
|
||||
row.port = value.port;
|
||||
@@ -641,13 +641,13 @@ Json data_topology_view(Global* global) {
|
||||
Json data_topology_connection_status(Global* global, std::uint64_t id) {
|
||||
const auto feed = item_by_id(global->mode_acs.data_feed_config.map.list(), id);
|
||||
const auto source = global->mode_acs.data_source_config.map.get(feed->source_key);
|
||||
Json result{{"连接", feed->source_key + " → " + feed->key}, {"数据馈送状态", Psc::to_string(feed->state)}, {"数据馈送启用", feed->enabled()}};
|
||||
Json result{{"连接", feed->source_key + " → " + feed->key}, {"数据馈送状态", Psc::to_string(feed->state.load())}, {"数据馈送启用", feed->enabled()}};
|
||||
if(!source) {
|
||||
result["连接状态"] = "数据源不存在";
|
||||
result["已在数据源注册"] = false;
|
||||
return result;
|
||||
}
|
||||
result["数据源状态"] = Psc::to_string(source.value()->state);
|
||||
result["数据源状态"] = Psc::to_string(source.value()->state.load());
|
||||
result["数据源启用"] = source.value()->enabled();
|
||||
const auto all_status = adminive::parse_json<Json>(source.value()->get_all_connect_feed_status().to_json_string());
|
||||
const auto status = all_status.find(feed->key);
|
||||
@@ -655,8 +655,30 @@ Json data_topology_connection_status(Global* global, std::uint64_t id) {
|
||||
result["连接状态"] = status != all_status.end() && source.value()->enabled() && feed->enabled() ? "运行中" : "未运行";
|
||||
if(status != all_status.end())
|
||||
result["缓存统计"] = *status;
|
||||
result["数据馈送观测"] = adminive::parse_json<Json>(feed->get_state_json().to_json_string());
|
||||
return result;
|
||||
}
|
||||
Json data_topology_runtime_client_status(Global* global, std::uint64_t feed_id, std::uint64_t client_id) {
|
||||
const auto feed = item_by_id(global->mode_acs.data_feed_config.map.list(), feed_id);
|
||||
if(const auto tcp = dynamic_cast<Data_Feed_TCP_Server*>(feed.get())) {
|
||||
const auto client = tcp->svr.get_client(static_cast<Psc::asio_socket::Socket_FD>(client_id));
|
||||
if(!client)
|
||||
throw std::out_of_range("TCP client is no longer connected");
|
||||
return Json{{"connection_state", client->closing.load() ? "closing" : "connected"},
|
||||
{"remote", client->info.sockaddr.to_string()}, {"fd", client->info.fd},
|
||||
{"statistics", adminive::parse_json<Json>(client->statistics.to_json().to_json_string())}};
|
||||
}
|
||||
if(const auto udp = dynamic_cast<Data_Feed_UDP_Server*>(feed.get())) {
|
||||
const auto client = udp->svr.get_client(static_cast<std::size_t>(client_id));
|
||||
if(!client)
|
||||
throw std::out_of_range("UDP client is no longer available");
|
||||
const auto last_activity = client->statistics->last_activity_unix_ms();
|
||||
const auto idle_ms = last_activity == 0 ? 0 : Psc::get_current_millisecond_timestamp() - last_activity;
|
||||
return Json{{"connection_state", last_activity != 0 && idle_ms <= 30000 ? "active" : "idle"}, {"remote", client->address.to_string()}, {"idle_ms", idle_ms},
|
||||
{"statistics", adminive::parse_json<Json>(client->statistics->to_json().to_json_string())}};
|
||||
}
|
||||
throw std::invalid_argument("data feed does not expose runtime clients");
|
||||
}
|
||||
Json data_topology(Global* global) {
|
||||
const auto sources = global->mode_acs.data_source_config.map.list();
|
||||
const auto feeds = global->mode_acs.data_feed_config.map.list();
|
||||
@@ -670,7 +692,7 @@ Json data_topology(Global* global) {
|
||||
auto config = adminive::to_frontend_json<Json>(source_row(source));
|
||||
config["id"] = index + 1;
|
||||
Json details = Json::array();
|
||||
details.push_back(Json{{"label", "运行状态"}, {"value", Psc::to_string(source->state)}});
|
||||
details.push_back(Json{{"label", "运行状态"}, {"value", Psc::to_string(source->state.load())}});
|
||||
if(const auto value = dynamic_cast<TCP_Client_Data_Source*>(source.get())) {
|
||||
value->specific.read([&](const auto& config) { details.push_back(Json{{"label", "目标"}, {"value", config.ip + ":" + std::to_string(config.port)}}); });
|
||||
} else if(const auto value = dynamic_cast<Serial_Data_Source*>(source.get())) {
|
||||
@@ -691,7 +713,7 @@ Json data_topology(Global* global) {
|
||||
const auto id = "data_feed:" + feed->key;
|
||||
auto config = adminive::to_frontend_json<Json>(feed_row(feed));
|
||||
config["id"] = index + 1;
|
||||
Json details = Json::array({Json{{"label", "运行状态"}, {"value", Psc::to_string(feed->state)}}});
|
||||
Json details = Json::array({Json{{"label", "运行状态"}, {"value", Psc::to_string(feed->state.load())}}});
|
||||
feed->output_format.read([&](const auto& value) { details.push_back(Json{{"label", "数据格式"}, {"value", std::string(magic_enum::enum_name(value.type))}}); });
|
||||
if(const auto value = dynamic_cast<Data_Feed_TCP_Server*>(feed.get())) {
|
||||
value->specific.read([&](const auto& config) { details.push_back(Json{{"label", "监听端口"}, {"value", config.port}}); });
|
||||
@@ -716,15 +738,21 @@ Json data_topology(Global* global) {
|
||||
for(const auto& client : value->svr.get_all_clients()) {
|
||||
const auto client_id = "client:tcp:" + feed->key + ":" + std::to_string(client->info.fd);
|
||||
const auto endpoint = client->info.sockaddr.to_string();
|
||||
nodes.push_back(Json{{"id", client_id}, {"kind", "client"}, {"entity_id", 0}, {"key", endpoint}, {"label", endpoint}, {"type", "TCP 客户端"}, {"enabled", true}, {"details", Json::array({Json{{"label", "文件描述符"}, {"value", client->info.fd}}, Json{{"label", "发送缓冲区"}, {"value", client->send_buffer.state_str()}}})}});
|
||||
edges.push_back(Json{{"id", "feed-client:" + feed->key + ":" + std::to_string(client->info.fd)}, {"kind", "runtime"}, {"source", id}, {"target", client_id}, {"active", true}, {"details", Json::array({Json{{"label", "连接状态"}, {"value", "已连接"}}, Json{{"label", "远端"}, {"value", endpoint}}, Json{{"label", "发送缓冲区"}, {"value", client->send_buffer.state_str()}}})}});
|
||||
const auto status_api = data_topology_path + "/status/runtime_client/" + std::to_string(index + 1) + "/" + std::to_string(client->info.fd);
|
||||
nodes.push_back(Json{{"id", client_id}, {"kind", "client"}, {"entity_id", 0}, {"key", endpoint}, {"label", endpoint}, {"type", "TCP 客户端"}, {"enabled", true}, {"status_api", status_api}, {"details", Json::array({Json{{"label", "文件描述符"}, {"value", client->info.fd}}, Json{{"label", "远端"}, {"value", endpoint}}})}});
|
||||
edges.push_back(Json{{"id", "feed-client:" + feed->key + ":" + std::to_string(client->info.fd)}, {"kind", "runtime"}, {"source", id}, {"target", client_id}, {"active", !client->closing.load()}, {"status_api", status_api}, {"details", Json::array({Json{{"label", "连接状态"}, {"value", "已连接"}}, Json{{"label", "远端"}, {"value", endpoint}}})}});
|
||||
}
|
||||
} else if(const auto value = dynamic_cast<Data_Feed_UDP_Server*>(feed.get())) {
|
||||
for(const auto& client : value->svr.clients) {
|
||||
const auto endpoint = client.to_string();
|
||||
const auto clients = value->svr.get_all_clients();
|
||||
for(std::size_t client_index = 0; client_index < clients.size(); ++client_index) {
|
||||
const auto& client = clients[client_index];
|
||||
const auto endpoint = client.address.to_string();
|
||||
const auto last_activity = client.statistics->last_activity_unix_ms();
|
||||
const auto active = last_activity != 0 && Psc::get_current_millisecond_timestamp() - last_activity <= 30000;
|
||||
const auto client_id = "client:udp:" + feed->key + ":" + endpoint;
|
||||
nodes.push_back(Json{{"id", client_id}, {"kind", "client"}, {"entity_id", 0}, {"key", endpoint}, {"label", endpoint}, {"type", "UDP 客户端"}, {"enabled", true}, {"details", Json::array()}});
|
||||
edges.push_back(Json{{"id", "feed-client:" + feed->key + ":" + endpoint}, {"kind", "runtime"}, {"source", id}, {"target", client_id}, {"active", true}, {"details", Json::array({Json{{"label", "连接状态"}, {"value", "已连接"}}, Json{{"label", "远端"}, {"value", endpoint}}})}});
|
||||
const auto status_api = data_topology_path + "/status/runtime_client/" + std::to_string(index + 1) + "/" + std::to_string(client_index);
|
||||
nodes.push_back(Json{{"id", client_id}, {"kind", "client"}, {"entity_id", 0}, {"key", endpoint}, {"label", endpoint}, {"type", "UDP 客户端"}, {"enabled", true}, {"status_api", status_api}, {"details", Json::array({Json{{"label", "远端"}, {"value", endpoint}}})}});
|
||||
edges.push_back(Json{{"id", "feed-client:" + feed->key + ":" + endpoint}, {"kind", "runtime"}, {"source", id}, {"target", client_id}, {"active", active}, {"status_api", status_api}, {"details", Json::array({Json{{"label", "连接状态"}, {"value", active ? "活跃" : "空闲"}}, Json{{"label", "远端"}, {"value", endpoint}}})}});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1023,6 +1051,11 @@ private:
|
||||
return adminive::make_http_success<Json>(data_topology_connection_status(global_, id));
|
||||
});
|
||||
}, get);
|
||||
app.registerHandler(data_topology_path + "/status/runtime_client/{1:feed_id}/{2:client_id}", [this](const drogon::HttpRequestPtr&, std::function<void(const drogon::HttpResponsePtr&)>&& callback, std::uint64_t feed_id, std::uint64_t client_id) {
|
||||
complete_business_request(callback, [this, feed_id, client_id] {
|
||||
return adminive::make_http_success<Json>(data_topology_runtime_client_status(global_, feed_id, client_id));
|
||||
});
|
||||
}, get);
|
||||
}
|
||||
void bind_backend_config(drogon::HttpAppFramework& app) {
|
||||
const auto get = adminive::make_drogon_constraints(drogon::Get, {});
|
||||
|
||||
Reference in New Issue
Block a user