Skip to content

Add resource agent, dashboard, and proxy resource snapshot reporting#82

Open
zhy1658858023 wants to merge 1 commit into
mainfrom
codex/instance
Open

Add resource agent, dashboard, and proxy resource snapshot reporting#82
zhy1658858023 wants to merge 1 commit into
mainfrom
codex/instance

Conversation

@zhy1658858023

Copy link
Copy Markdown
Collaborator

Motivation

  • Provide a lightweight local resource agent that samples host/GPU/memory/network and exposes a JSON snapshot over HTTP.
  • Offer a small desktop and web dashboard to visualize Instance resource snapshots and manage the local agent.
  • Extend the Proxy control plane to accept resource snapshot reports and persist structured resource metrics per Instance.

Description

  • Add a Rust-based resource agent at instance/resource_agent/src/main.rs exposing /healthz and /v1/resource/snapshot, capturing CPU, memory, network, and GPU info and producing a resource_snapshot_v1 JSON payload.
  • Add instance/resource_agent/Cargo.toml and Cargo.lock for the agent manifest.
  • Add instance/resource_agent/proxy_reporter.py which periodically fetches the local agent snapshot and POSTs it to the Proxy control plane endpoint.
  • Add the dashboard tooling under instance/resource_dashboard/: a standard-library server dashboard_server.py, a Tk desktop app dashboard_app.py, and static web UI assets in static/ (index.html, app.js, style.css) to visualize snapshots and manage the agent process.
  • Extend the Proxy code to accept and store resource snapshots by adding InstanceResource to proxy/resource/instance_pool.py, implementing report_resource_snapshot and helpers to convert raw snapshots into structured fields.
  • Expose a new control-plane API POST /v1/instance/resource_snapshot in proxy/resource/p_control_plane.py, and include resource in the /v1/instance/list response.

Testing

  • Performed a Rust project build check with cargo check for instance/resource_agent which completed successfully.
  • Performed Python syntax checks by compiling the new Python modules (python -m py_compile) which succeeded.
  • No unit tests were added or modified as part of this change.

Codex Task

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5745296314

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

it = self._items.get(instance_id)
if not it:
return False
it.last_seen_at = now

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not let resource reports renew instance liveness

When the new resource agent/proxy_reporter is launched as a separate process, it can keep posting host snapshots after the actual Instance server or its heartbeat loop has stopped. Refreshing last_seen_at here makes InstancePool.list(include_dead=False) continue returning that dead instance, so select_instance can dispatch requests to an unavailable host:port instead of letting the TTL expire; resource updates should not renew serving liveness unless they are coupled to the Instance heartbeat.

Useful? React with 👍 / 👎.

Comment on lines +106 to +107
"{{\"index\":{},\"uuid\":\"{}\",\"name\":\"{}\",\"utilization_pct\":{},\"memory_used_mb\":{},\"memory_total_mb\":{},\"memory_free_mb\":{},\"temperature_c\":{},\"power_w\":{},\"health\":\"ok\"}}",
cols[0].parse::<u32>().unwrap_or(0), json_escape(cols[1]), json_escape(cols[2]), cols[3], cols[4], cols[5], cols[6], cols[7], cols[8].replace("[Not Supported]", "0")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Sanitize GPU metric fields before emitting JSON

On GPUs or drivers where nvidia-smi reports unsupported metrics as N/A or [Not Supported], these columns are interpolated directly into numeric JSON fields, so a value like "power_w":N/A makes /v1/resource/snapshot invalid JSON and causes both the dashboard and proxy_reporter to reject the snapshot. Parse each metric with a numeric fallback or emit null before formatting the JSON.

Useful? React with 👍 / 👎.


def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description="Report Instance resource snapshots to Proxy control plane")
parser.add_argument("--agent-url", default="http://127.0.0.1:9201", help="local Rust resource agent base URL")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the same default port for agent and reporter

Running the new resource agent and proxy_reporter.py with their defaults does not work: the Rust agent binds to 127.0.0.1:9101, while the reporter queries http://127.0.0.1:9201. In that default setup the reporter just logs HTTP-unavailable warnings and no snapshots reach the Proxy unless users discover and override one side, so these defaults should be aligned.

Useful? React with 👍 / 👎.


def build_parser() -> argparse.ArgumentParser:
p = argparse.ArgumentParser(description="CacheRoute Instance resource dashboard")
p.add_argument("--dashboard-listen", default="0.0.0.0:9202", help="dashboard listen address")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Bind the process-control dashboard to loopback by default

With the default --dashboard-listen this server binds to all interfaces while also exposing unauthenticated /api/agent/start and /api/agent/stop endpoints. On a shared or routable experiment host, anyone who can reach port 9202 can stop the managed resource agent or repeatedly start cargo run, disrupting resource reporting; defaulting to 127.0.0.1 or adding an explicit auth/unsafe flag would avoid exposing process control by default.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant