| 301 | } |
| 302 | |
| 303 | void RpcMgr::ToJson(Document* document) { |
| 304 | if (messenger_.get() == nullptr) return; |
| 305 | // Add rpc_use_unix_domain_socket. |
| 306 | document->AddMember( |
| 307 | "rpc_use_unix_domain_socket", krpc_use_uds_, document->GetAllocator()); |
| 308 | // Add acceptor metrics. |
| 309 | int64_t num_accepted = 0; |
| 310 | if (acceptor_pool_.get() != nullptr) { |
| 311 | num_accepted = acceptor_pool_->num_rpc_connections_accepted(); |
| 312 | } |
| 313 | document->AddMember("rpc_connections_accepted", num_accepted, document->GetAllocator()); |
| 314 | |
| 315 | document->AddMember("reactor_active_latency", ToString( |
| 316 | METRIC_reactor_active_latency_us, messenger_->metric_entity(), TUnit::TIME_US), |
| 317 | document->GetAllocator()); |
| 318 | document->AddMember("reactor_load_percent", ToString(METRIC_reactor_load_percent, |
| 319 | messenger_->metric_entity(), TUnit::UNIT), document->GetAllocator()); |
| 320 | |
| 321 | // Add messenger metrics. |
| 322 | DumpConnectionsResponsePB response; |
| 323 | messenger_->DumpConnections(DumpConnectionsRequestPB(), &response); |
| 324 | |
| 325 | int64_t num_inbound_calls_in_flight = 0; |
| 326 | // Add per connection metrics for inbound connections. |
| 327 | Value inbound_per_conn_metrics(kArrayType); |
| 328 | for (const RpcConnectionPB& conn : response.inbound_connections()) { |
| 329 | Value per_conn_metrics_entry(kObjectType); |
| 330 | // Remote addresses for UDS inbound connections are not available. |
| 331 | Value remote_addr_str( |
| 332 | (!krpc_use_uds_ ? conn.remote_ip().c_str() : "*"), document->GetAllocator()); |
| 333 | per_conn_metrics_entry.AddMember( |
| 334 | "remote_addr", remote_addr_str, document->GetAllocator()); |
| 335 | per_conn_metrics_entry.AddMember( |
| 336 | "num_calls_in_flight", conn.calls_in_flight().size(), document->GetAllocator()); |
| 337 | num_inbound_calls_in_flight += conn.calls_in_flight().size(); |
| 338 | Value socket_stats_entry(kObjectType); |
| 339 | ProtobufToJson(conn.socket_stats(), document, &socket_stats_entry); |
| 340 | per_conn_metrics_entry.AddMember( |
| 341 | "socket_stats", socket_stats_entry, document->GetAllocator()); |
| 342 | |
| 343 | Value calls_in_flight(kArrayType); |
| 344 | for (const RpcCallInProgressPB& call : conn.calls_in_flight()) { |
| 345 | Value call_in_flight(kObjectType); |
| 346 | ProtobufToJson(call, document, &call_in_flight); |
| 347 | calls_in_flight.PushBack(call_in_flight, document->GetAllocator()); |
| 348 | } |
| 349 | per_conn_metrics_entry.AddMember( |
| 350 | "calls_in_flight", calls_in_flight, document->GetAllocator()); |
| 351 | inbound_per_conn_metrics.PushBack(per_conn_metrics_entry, document->GetAllocator()); |
| 352 | } |
| 353 | document->AddMember( |
| 354 | "inbound_per_conn_metrics", inbound_per_conn_metrics, document->GetAllocator()); |
| 355 | document->AddMember("num_inbound_calls_in_flight", num_inbound_calls_in_flight, |
| 356 | document->GetAllocator()); |
| 357 | |
| 358 | // Add per connection metrics for outbound connections. |
| 359 | Value outbound_per_conn_metrics(kArrayType); |
| 360 | int64_t num_outbound_calls_in_flight = 0; |
nothing calls this directly
no test coverage detected