MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / count_connected_agents

Method count_connected_agents

src/docker/proxy_manager.rs:395–420  ·  view source on GitHub ↗

Counts the number of agent networks the specified proxy is connected to. Inspects the proxy container and counts networks matching the `tsk-agent-*` pattern (excluding the external network).

(&self, container_name: &str)

Source from the content-addressed store, hash-verified

393 /// Inspects the proxy container and counts networks matching the
394 /// `tsk-agent-*` pattern (excluding the external network).
395 pub async fn count_connected_agents(&self, container_name: &str) -> Result<usize> {
396 // Inspect the proxy container to get its network connections
397 match self.docker_client.inspect_container(container_name).await {
398 Ok(json_data) => {
399 let data: serde_json::Value = serde_json::from_str(&json_data)
400 .map_err(|e| anyhow::anyhow!("Failed to parse container info: {e}"))?;
401
402 // Count networks, excluding the external network
403 let count = data
404 .get("NetworkSettings")
405 .and_then(|ns| ns.get("Networks"))
406 .and_then(|n| n.as_object())
407 .map(|networks| {
408 networks
409 .keys()
410 .filter(|name| name.starts_with(TSK_AGENT_NETWORK_PREFIX))
411 .count()
412 })
413 .unwrap_or(0);
414
415 Ok(count)
416 }
417 Err(e) if e.to_lowercase().contains("no such container") => Ok(0),
418 Err(e) => Err(anyhow::anyhow!(e)),
419 }
420 }
421
422 /// Atomically acquires a proxy session for a task.
423 ///

Callers 3

force_stop_proxyMethod · 0.80

Calls 1

inspect_containerMethod · 0.45

Tested by 1