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.
- Automatic Timing: Energy tracking automatically starts and stops when monitoring begins and ends.
Installation Requirements
Just install the library. That's all your going to need
pip install energyCnV==1.0.26
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.
- The timer automatically starts when monitoring begins.
4. Stop Monitoring
To stop tracking and save energy data:
monitor.stop()
- This automatically calculates the total energy used and duration.
- Data is stored in the database.
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.
- Automatically starts the timer when monitoring begins.
stop()
Functionality:
- Automatically stops the timer and calculates energy consumption.
- Stores run details like duration, timestamp, and energy used.
- Saves data in MongoDB.
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.
- Timing is handled automatically; no need for manual tracking.
License
This project is open-source. Feel free to modify and extend it!
Metadata
Release files for energyCnV 2.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| energycnv-2.1.4.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| energycnv-2.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / energycnv-2.1.4.tar.gz
| Download URL | energycnv-2.1.4.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55349e95f9730d4ac876d2d5f3fad335ae0e6edc41d34c77fb6f5729fb5a9a2c
|
|
BLAKE2b-256 checksum How to use checksums |
8a47d257eef16b577b487a2a3806cb221491f7dc0d63a8e247cd43bc66d3278c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|
Release files / energycnv-2.1.4-py3-none-any.whl
| Download URL | energycnv-2.1.4-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
354e496e31e6e87f4df3b37d326160f718846c029aeca4019ab5d81eca9c610b
|
|
BLAKE2b-256 checksum How to use checksums |
3b2e26fff4b003ccd29ce7bc92804eaa315245cf49dc2564b99e53942a9cbd97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.11
|