Track and visualize GPU energy consumption using PyNVML, with MongoDB integration.
Project description
EnergyMonitor
Overview
EnergyMonitor is a Python-based tool that tracks GPU power consumption using NVIDIA Management Library (NVML) and stores energy usage data in a MongoDB database. It allows users to log in, track energy consumption per project, and store run-specific energy data.
Features
- User Authentication: Secure login using bcrypt.
- Energy Monitoring: Tracks GPU power usage using NVML.
- Project-Based Tracking: Associates energy consumption data with different projects.
- Database Storage: Saves energy consumption history in MongoDB.
Installation Requirements
Before using the tool, install the required dependencies:
pip install pymongo bcrypt pynvml
Ensure you have:
- A MongoDB database (e.g., MongoDB Atlas or a local instance).
- NVIDIA GPU and drivers installed.
- NVML library (included in the NVIDIA drivers).
Usage
1. Import and Initialize
from energy_monitor import EnergyMonitor
monitor = EnergyMonitor()
2. Login
Before tracking energy consumption, log in with:
monitor.login("username", "password")
3. Start Monitoring
Start tracking energy consumption for a specific project:
monitor.start("ProjectName")
If the project does not exist, it prompts the user to create one.
4. Stop Monitoring
To stop tracking and save energy data:
monitor.stop()
This logs the total energy used and duration to the database.
5. Update Energy Consumption
This function continuously updates power consumption:
monitor.update_energy()
This should be run in a loop while monitoring is active.
Functions
login(username, password)
Inputs:
username(str): The username of the user.password(str): The corresponding password.
Functionality:
- Authenticates the user with a hashed password.
- Stores the user ID after successful login.
start(project_name)
Inputs:
project_name(str): Name of the project to track energy usage.
Functionality:
- Initializes GPU energy monitoring.
- Checks if the project exists; if not, prompts user to create one.
stop()
Functionality:
- Stops monitoring and logs energy consumption data.
- Stores run details like duration, timestamp, and energy used.
update_energy()
Functionality:
- Continuously updates GPU energy consumption while running.
- Runs in a loop to track power usage per second.
Database Structure
Each user document in MongoDB follows this structure:
{
"_id": ObjectId("..."),
"username": "user123",
"password": "hashed_password",
"projects": {
"ProjectName": {
"run1": {
"timestamp": "2025-03-08T12:00:00Z",
"duration": 3600,
"energy": 500000,
"energy_kwh": 0.138
}
}
}
}
Notes
- Make sure you log in before starting monitoring.
- Ensure your GPU supports NVML.
- The program exits on incorrect login.
License
This project is open-source. Feel free to modify and extend it!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file energyCnV-1.0.2.tar.gz.
File metadata
- Download URL: energyCnV-1.0.2.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9dc1397d245dfb7ea7bf754f00f1a0453eae6433efbccd8ba6a85b8aa8cbaa38
|
|
| MD5 |
9064a50cd956bb0fff1fe52a4a7f92f5
|
|
| BLAKE2b-256 |
469b51678176b2b2de8c7779a520b4133961b50e320990fff418712b51cdce86
|
File details
Details for the file energycnv-1.0.2-py3-none-any.whl.
File metadata
- Download URL: energycnv-1.0.2-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d4b8caaea9c72fd340cab23cae9d858d57d107b92f54ef12dbdc447ce91711bf
|
|
| MD5 |
18a94af2d14ac78029a0e053e0445683
|
|
| BLAKE2b-256 |
600e290ab977f23244ecd05b17efd4b1ad302619c9647fc4446e7056b98eab7b
|
File details
Details for the file energyCnV-1.0.2-py3-none-any.whl.
File metadata
- Download URL: energyCnV-1.0.2-py3-none-any.whl
- Upload date:
- Size: 2.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55f115a6cd04b6401938d8ef990be6ce62aed5464429278e7a15c53083bebbaa
|
|
| MD5 |
021c8a33623e1bb2b285669405b25a16
|
|
| BLAKE2b-256 |
e8d2f0c631de1cdccd9e6b350348ce6554482d0f5f3a3926450b623badea9ea8
|