Skip to main content

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.
  • 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

energycnv-2.1.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

energycnv-2.1.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file energycnv-2.1.2.tar.gz.

File metadata

  • Download URL: energycnv-2.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for energycnv-2.1.2.tar.gz
Algorithm Hash digest
SHA256 73ec9ae00f123404b90f6e1b7df3982153463e14c1d978d15232b660033d8fb7
MD5 9f62dcd57135ae2f53f9e15899f45e84
BLAKE2b-256 a538fd8d64cc923cd8be1cd2be305f4d237b76eea36e18e49343fd9f2594df02

See more details on using hashes here.

File details

Details for the file energycnv-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: energycnv-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for energycnv-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 117d4e6c5e0cb365be57511a71a0a0e90ba404d9467d92cdd8fd92ae33051fef
MD5 942c04474f0c25c3f1dcc7e57f071154
BLAKE2b-256 b243da153a0bd5033106231a3f29b39b7a020fc2366f655c542a6705601e95e6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page