{"id":27185162,"url":"https://github.com/saviornt/resourcemanager","last_synced_at":"2025-04-09T17:11:24.462Z","repository":{"id":283397873,"uuid":"950987183","full_name":"saviornt/ResourceManager","owner":"saviornt","description":"The Resource Manager is a Python package designed to monitor and manage system resources such as CPU, memory, and GPU usage. It utilizes the Pydantic library for configuration management and the psutil library for resource monitoring. If available, it also integrates with NVIDIA's NVML for GPU monitoring.","archived":false,"fork":false,"pushed_at":"2025-03-20T03:26:29.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T17:11:21.220Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/saviornt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-19T01:48:48.000Z","updated_at":"2025-03-20T03:06:33.000Z","dependencies_parsed_at":"2025-03-20T03:28:34.086Z","dependency_job_id":"016b265a-aef4-4fb2-b48a-ac4ca52d6e5c","html_url":"https://github.com/saviornt/ResourceManager","commit_stats":null,"previous_names":["saviornt/resourcemanager"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saviornt%2FResourceManager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saviornt%2FResourceManager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saviornt%2FResourceManager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/saviornt%2FResourceManager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/saviornt","download_url":"https://codeload.github.com/saviornt/ResourceManager/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248074964,"owners_count":21043490,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-09T17:11:23.834Z","updated_at":"2025-04-09T17:11:24.457Z","avatar_url":"https://github.com/saviornt.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ResourceManager\n\nA Python utility for monitoring and managing system resources. It helps prevent system overload by monitoring CPU, GPU, memory, and network usage while providing an API for resource status and pruning decisions.\n\n## Features\n\n* **Real-time Resource Monitoring:** Track CPU, GPU, memory, and network usage in real-time.\n* **Adaptive Resource Management:** Define thresholds for resource usage and get pruning signals when they're exceeded.\n* **Asynchronous Operation:** All operations can be performed asynchronously.\n* **FastAPI Integration:** Built-in REST API for remote monitoring and management.\n* **Simple Integration:** Designed to be easily dropped into existing Python projects.\n* **Python 3.12+ and CUDA Compatible:** Supports Python 3.12 and seamlessly integrates with CUDA environments when NVIDIA GPUs and `pynvml` are available.\n* **Comprehensive Error Handling and Resilience:** Includes proper error handling and resilience in API endpoints.\n* **Extensive Test Suite with High Coverage:** Includes a test suite with high coverage to ensure reliability.\n\n## Installation\n\n```bash\npip install git+https://github.com/saviornt/resourcemanager\n```\n\n## Usage\n\n```python\nfrom src.resource_manager import ResourceManager\n\n# Initialize with custom thresholds\nmanager = ResourceManager(\n    max_cpu_percent=80.0,\n    max_memory_percent=75.0,\n    max_gpu_percent=90.0,\n    max_network_bytes_per_sec=1_000_000\n)\n\n# Check if pruning is needed\nif manager.should_prune():\n    print(\"Pruning recommended due to high resource usage\")\n    \n# Get individual metrics\ncpu_usage = manager.resource_monitor.get_cpu_percent()\nmemory_usage = manager.resource_monitor.get_memory_usage_mb()\n\n# Asynchronous usage\nimport asyncio\n\nasync def check_resources():\n    should_prune = await manager.should_prune_async()\n    if should_prune:\n        print(\"Async pruning recommended\")\n        \n# Close when done\nmanager.close()\n```\n\n## GitHub Repository\n\n\u003chttps://github.com/saviornt/ResourceManager\u003e\n\n## API Reference\n\nResourceManager provides a FastAPI-based REST API for remote monitoring and resource management.\n\n### Server Setup\n\nTo start the API server:\n\n```python\nimport uvicorn\nfrom resource_manager import endpoints\n\nif __name__ == \"__main__\":\n    uvicorn.run(endpoints, host=\"0.0.0.0\", port=8000)\n```\n\n### Endpoints\n\nThe API provides the following endpoints:\n\n#### 1. `/endpoint/cpu`\n\n**Method:** GET  \n**Response Model:** `CPUResponse`  \n**Description:** Returns current CPU usage percentage.\n\n```json\n{\n  \"cpu_percent\": 25.7,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n#### 2. `/endpoint/memory`\n\n**Method:** GET  \n**Response Model:** `MemoryResponse`  \n**Description:** Returns current memory usage in MB.\n\n```json\n{\n  \"memory_usage_mb\": 4852.6,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n#### 3. `/endpoint/gpu`\n\n**Method:** GET  \n**Response Model:** `GPUResponse`  \n**Description:** Returns current GPU usage and memory usage percentages.\n\n```json\n{\n  \"gpu_percent\": 42.3,\n  \"gpu_memory_percent\": 35.8,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n#### 4. `/endpoint/network`\n\n**Method:** GET  \n**Response Model:** `NetworkResponse`  \n**Description:** Returns current network usage in bytes per second.\n\n```json\n{\n  \"network_usage_bytes_per_second\": 1250000,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n#### 5. `/endpoint/all`\n\n**Method:** GET  \n**Response Model:** `AllResourcesResponse`  \n**Description:** Returns all resource metrics in a single response.\n\n```json\n{\n  \"cpu_percent\": 25.7,\n  \"memory_usage_mb\": 4852.6,\n  \"gpu_percent\": 42.3,\n  \"gpu_memory_percent\": 35.8,\n  \"network_usage_bytes_per_second\": 1250000,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n#### 6. `/endpoint/prune`\n\n**Method:** GET  \n**Response Model:** `PruneResponse`  \n**Description:** Returns a boolean indicating whether resource pruning is necessary based on configured thresholds.\n\n```json\n{\n  \"should_prune\": true,\n  \"timestamp\": 1625482956.7891\n}\n```\n\n### Response Models\n\nThe API uses the following Pydantic models for responses:\n\n* `CPUResponse`: CPU utilization data\n* `MemoryResponse`: Memory usage data\n* `GPUResponse`: GPU utilization and memory data\n* `NetworkResponse`: Network usage data\n* `AllResourcesResponse`: Combined resource data\n* `PruneResponse`: Pruning decision data\n\n### API Features\n\n* **Caching**: All responses are cached for 1 second to reduce system load\n* **Background Tasks**: Cache is automatically refreshed in the background\n* **Error Handling**: Comprehensive error handling with appropriate HTTP status codes\n* **Clean Shutdown**: Resources are properly cleaned up when the API server shuts down\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaviornt%2Fresourcemanager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaviornt%2Fresourcemanager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaviornt%2Fresourcemanager/lists"}