-
Notifications
You must be signed in to change notification settings - Fork 97
List running server health and status #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
25cc283
Init
fsiino-nvidia 296526d
Parse server info
fsiino-nvidia 64705b9
Print output
fsiino-nvidia c36f84b
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 8cc480a
Round uptime seconds, add tests
fsiino-nvidia dfc3cfe
Add docs
fsiino-nvidia 4cf6d1f
Fix copyrights
fsiino-nvidia c3d2fe6
Clean print statement
fsiino-nvidia 2647e8f
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 4261772
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 40445c8
Update uv.lock
fsiino-nvidia 1087b83
Merge branch 'main' into fsiino/server-health-status
fsiino-nvidia ab6feb4
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 696fdc0
Improve test coverage
fsiino-nvidia 91a525c
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 5f2532a
Merge remote-tracking branch 'github/main' into fsiino/server-health-…
fsiino-nvidia 00abd06
Move docs
fsiino-nvidia 35e0206
Reuse server info base class
fsiino-nvidia 00e7629
Call headserver instead of process search
fsiino-nvidia 06994c3
Use ServerInstanceDisplayConfig for ng_run and ng_status
fsiino-nvidia 6d174d2
Small format adjustment, update output in docs
fsiino-nvidia bacf133
Remove ng_version from faq
fsiino-nvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| from time import time | ||
| from typing import List | ||
|
|
||
| import requests | ||
| from devtools import pprint | ||
|
|
||
| from nemo_gym.server_utils import ServerClient, ServerInstanceDisplayConfig, ServerStatus | ||
|
|
||
|
|
||
| class StatusCommand: | ||
| """Main class to check server status""" | ||
|
|
||
| def check_health(self, server_info: ServerInstanceDisplayConfig) -> ServerStatus: | ||
| """Check if server is responding""" | ||
| if not server_info.url: | ||
| return "unknown_error" | ||
|
|
||
| try: | ||
| requests.get(server_info.url, timeout=2) | ||
| return "success" | ||
| except requests.exceptions.ConnectionError: | ||
| return "connection_error" | ||
| except requests.exceptions.Timeout: | ||
| return "timeout" | ||
| except Exception: | ||
| return "unknown_error" | ||
|
|
||
| def discover_servers(self) -> List[ServerInstanceDisplayConfig]: | ||
| """Find all running NeMo Gym server processes""" | ||
|
|
||
| try: | ||
| head_server_config = ServerClient.load_head_server_config() | ||
| head_url = f"http://{head_server_config.host}:{head_server_config.port}" | ||
|
|
||
| response = requests.get(f"{head_url}/server_instances", timeout=5) | ||
| response.raise_for_status() | ||
| instances = response.json() | ||
|
|
||
| servers = [] | ||
| current_time = time() | ||
|
|
||
| for inst in instances: | ||
| uptime = current_time - inst.get("start_time", current_time) | ||
| server_info = ServerInstanceDisplayConfig( | ||
| process_name=inst["process_name"], | ||
| server_type=inst["server_type"], | ||
| name=inst["name"], | ||
| host=inst.get("host"), | ||
| port=inst.get("port"), | ||
| url=inst.get("url"), | ||
| entrypoint=inst.get("entrypoint"), | ||
| pid=inst.get("pid"), | ||
| uptime_seconds=uptime, | ||
| status="unknown_error", | ||
| ) | ||
| server_info.status = self.check_health(server_info) | ||
| servers.append(server_info) | ||
|
|
||
| return servers | ||
|
|
||
| except (requests.RequestException, ConnectionError) as e: | ||
| print(f""" | ||
| Could not connect to head server: {e} | ||
| Is the head server running? Start it with: `ng_run` | ||
| """) | ||
| return [] | ||
|
|
||
| def display_status(self, servers: List[ServerInstanceDisplayConfig]) -> None: | ||
| """Show server info in a table""" | ||
|
|
||
| def format_uptime(uptime_seconds: float) -> str: | ||
| """Format uptime in a human readable format""" | ||
| minutes, seconds = divmod(uptime_seconds, 60) | ||
| hours, minutes = divmod(minutes, 60) | ||
| days, hours = divmod(hours, 24) | ||
| return f"{int(days)}d {int(hours)}h {int(minutes)}m {seconds:.1f}s" | ||
|
|
||
| if not servers: | ||
| print("No NeMo Gym servers found running.") | ||
| return | ||
|
|
||
| print("\nNeMo Gym Server Status:\n") | ||
|
|
||
| for i, server in enumerate(servers, 1): | ||
| status_icon = "✓" if server.status == "success" else "✗" | ||
| print(f"[{i}] {status_icon} {server.process_name} ({server.server_type}/{server.name})") | ||
| display_dict = { | ||
| "server_type": server.server_type, | ||
| "name": server.name, | ||
| "port": server.port, | ||
| "pid": server.pid, | ||
| "uptime_seconds": format_uptime(server.uptime_seconds), | ||
| } | ||
| pprint(display_dict) | ||
|
|
||
| healthy_count = sum(1 for s in servers if s.status == "success") | ||
| print(f""" | ||
| {len(servers)} servers found ({healthy_count} healthy, {len(servers) - healthy_count} unhealthy) | ||
| """) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this intended? can we double check this is using the right license?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This appears to be the updated licensing info that we have been using for all files.