{"id":25666482,"url":"https://github.com/parvvaresh/monitor-gpu-usage","last_synced_at":"2025-02-24T08:30:28.652Z","repository":{"id":231274674,"uuid":"781335876","full_name":"parvvaresh/Monitor-GPU-usage","owner":"parvvaresh","description":"This repository contains a Python script that monitors GPU usage and logs the data into a CSV file at regular intervals. The script leverages nvidia-smi to query GPU statistics and runs in the background using the screen utility.","archived":false,"fork":false,"pushed_at":"2024-12-21T17:26:19.000Z","size":893,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-21T18:26:41.713Z","etag":null,"topics":["bash-script","cpu-monitoring","gpu-monitoring","monitoring","nvidia"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/parvvaresh.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":"2024-04-03T07:31:07.000Z","updated_at":"2024-12-21T17:27:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"695870c8-65b0-45f9-80e5-6437777d2e14","html_url":"https://github.com/parvvaresh/Monitor-GPU-usage","commit_stats":null,"previous_names":["parvvaresh/download-manager","parvvaresh/monitor-gpu-usage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parvvaresh%2FMonitor-GPU-usage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parvvaresh%2FMonitor-GPU-usage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parvvaresh%2FMonitor-GPU-usage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parvvaresh%2FMonitor-GPU-usage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parvvaresh","download_url":"https://codeload.github.com/parvvaresh/Monitor-GPU-usage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240444289,"owners_count":19802203,"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":["bash-script","cpu-monitoring","gpu-monitoring","monitoring","nvidia"],"created_at":"2025-02-24T08:30:27.860Z","updated_at":"2025-02-24T08:30:28.477Z","avatar_url":"https://github.com/parvvaresh.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"Here is the **README** file for your script:\n\n---\n\n# GPU and CPU Utilization Logger\n\nThis Bash script logs GPU and CPU utilization data into a CSV file at user-specified intervals. It uses NVIDIA's `nvidia-smi` command to gather GPU data and `mpstat` for CPU utilization. This script is useful for monitoring system performance over time.\n\n---\n\n## Features\n- Logs timestamp, GPU name, GPU utilization, memory utilization, and CPU utilization.\n- Allows users to specify the file path for saving the logs.\n- Lets users set the interval for collecting and saving the data.\n- Outputs data in CSV format, compatible with tools like Excel and Python.\n\n---\n\n## Prerequisites\n1. **NVIDIA GPU**:\n   - Ensure you have an NVIDIA GPU with the `nvidia-smi` tool installed (typically included with NVIDIA drivers).\n\n2. **mpstat**:\n   - Install the `sysstat` package for CPU monitoring.\n   - On Ubuntu/Debian:\n     ```bash\n     sudo apt-get install sysstat\n     ```\n   - On CentOS/RHEL:\n     ```bash\n     sudo yum install sysstat\n     ```\n\n---\n\n## Usage\n\n### Step 1: Make the script executable\n```bash\nchmod +x logger.sh\n```\n\n### Step 2: Run the script\n```bash\n./logger.sh\n```\n\n### Step 3: Provide the required inputs\n- **CSV File Path**: Specify the file where the logs will be saved. If the file does not exist, it will be created with appropriate headers.\n- **Sampling Interval**: Enter the interval in seconds between data collection cycles.\n\n---\n\n## Example\nIf you provide:\n- File path: `/home/user/logs/utilization.csv`\n- Sampling interval: `5` seconds\n\nThe script will append rows to `/home/user/logs/utilization.csv` every 5 seconds, with entries like:\n```csv\ntimestamp,name,utilization.gpu [%],utilization.memory [%],cpu.utilization [%]\n2024-12-21 10:15:30,NVIDIA GeForce RTX 3080,85,70,20\n2024-12-21 10:15:35,NVIDIA GeForce RTX 3080,80,65,25\n```\n\n---\n\n## Notes\n- **Stop the Script**: To stop the script, press `Ctrl+C`.\n- **Performance Impact**: The script runs lightweight monitoring commands (`nvidia-smi` and `mpstat`). However, frequent sampling intervals (e.g., 1 second) may cause a slight system overhead.\n- **File Size**: Over time, the log file can grow large. Consider periodically archiving or clearing it if needed.\n\n---\n\n## Troubleshooting\n\n1. **Command not found: `nvidia-smi`**:\n   - Ensure that you have an NVIDIA GPU and the drivers are properly installed.\n\n2. **Command not found: `mpstat`**:\n   - Install the `sysstat` package using the instructions above.\n\n3. **Permission Denied**:\n   - Ensure the script has execute permissions:\n     ```bash\n     chmod +x logger.sh\n     ```\n\n4. **Incorrect Interval Input**:\n   - The `sleep` command requires a numeric interval. Ensure that you enter a valid number.\n\n---\n\n## License\nThis script is provided \"as is\" without any warranties. Feel free to modify and use it as needed.\n\n---\n\nLet me know if you need additional details or adjustments!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparvvaresh%2Fmonitor-gpu-usage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparvvaresh%2Fmonitor-gpu-usage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparvvaresh%2Fmonitor-gpu-usage/lists"}