-
-
Notifications
You must be signed in to change notification settings - Fork 237
Added CPU and RAM utilization tracking #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IamLRBA
wants to merge
12
commits into
mlco2:master
Choose a base branch
from
IamLRBA:885
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c21f596
Add CPU and RAM utilization tracking
IamLRBA fc9b3d8
style: fix linting issues
IamLRBA 0999d9c
Collect CPU and RAM utilization metrics
55a1352
Add GPU laod tracking
363b5c9
Add CPU, GPU and RAM load to API
05d9d4d
wip: fix test
fdfacd4
Merge branch 'mlco2:master' into 885
IamLRBA 6db1f8b
test: update test data with new utilization columns
IamLRBA 9a32b12
Merge branch 'master' into 885
benoit-cty d06433a
Fix pre-commit
613e495
Fix pre-commit
13c9b0b
Fix alembic migration chain
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
carbonserver/carbonserver/database/alembic/versions/20251119_add_utilization_metrics.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| """add_utilization_metrics_to_emissions | ||
|
|
||
| Revision ID: 20251119_add_utilization | ||
| Revises: 3212895acafd | ||
| Create Date: 2025-11-19 18:52:00.000000 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "20251119_add_utilization" | ||
| down_revision = "3212895acafd" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| """ | ||
| Add CPU, GPU, and RAM utilization percentage fields to emissions table. | ||
| These fields track the average utilization of resources during emission tracking. | ||
| """ | ||
| op.add_column( | ||
| "emissions", | ||
| sa.Column("cpu_utilization_percent", sa.Float, nullable=True), | ||
| ) | ||
| op.add_column( | ||
| "emissions", | ||
| sa.Column("gpu_utilization_percent", sa.Float, nullable=True), | ||
| ) | ||
| op.add_column( | ||
| "emissions", | ||
| sa.Column("ram_utilization_percent", sa.Float, nullable=True), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| """ | ||
| Remove CPU, GPU, and RAM utilization percentage fields from emissions table. | ||
| """ | ||
| op.drop_column("emissions", "ram_utilization_percent") | ||
| op.drop_column("emissions", "gpu_utilization_percent") | ||
| op.drop_column("emissions", "cpu_utilization_percent") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Simple test script to verify GPU load monitoring functionality. | ||
| This script will run a simple workload and check if GPU utilization is being tracked. | ||
| """ | ||
|
|
||
| import time | ||
|
|
||
| from codecarbon import EmissionsTracker | ||
|
|
||
|
|
||
| def main(): | ||
| print("Starting GPU load monitoring test...") | ||
| print("=" * 60) | ||
|
|
||
| # Initialize the tracker | ||
| tracker = EmissionsTracker( | ||
| project_name="gpu_load_test", | ||
| measure_power_secs=2, | ||
| save_to_file=True, | ||
| output_file="test_gpu_emissions.csv", | ||
| ) | ||
|
|
||
| # Start tracking | ||
| tracker.start() | ||
| print("Tracker started. Running for 10 seconds...") | ||
|
|
||
| # Run for a short duration to collect some metrics | ||
| time.sleep(10) | ||
|
|
||
| # Stop tracking | ||
| emissions = tracker.stop() | ||
|
|
||
| print("=" * 60) | ||
| print("Test completed!") | ||
| print(f"Total emissions: {emissions:.6f} kg CO2") | ||
|
|
||
| # Check if GPU utilization was tracked | ||
| if hasattr(tracker, "final_emissions_data"): | ||
| data = tracker.final_emissions_data | ||
| print(f"GPU utilization: {data.gpu_utilization_percent:.2f}%") | ||
| print(f"CPU utilization: {data.cpu_utilization_percent:.2f}%") | ||
| print(f"RAM utilization: {data.ram_utilization_percent:.2f}%") | ||
|
|
||
| if data.gpu_utilization_percent > 0: | ||
| print("\n✓ GPU utilization tracking is working!") | ||
| else: | ||
| print("\n⚠ GPU utilization is 0% (may not have GPU or no GPU workload)") | ||
|
|
||
| print("\nCheck test_gpu_emissions.csv for detailed results.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we have to multiply it by 100 to have a percent ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested and it's OK in the CSV : 55 for 55% of RAM used.