slurm-usage-history
slurm-usage-history: Dashboard for to display the usage history of a Slurm scheduler.
app
account_formatter
AccountFormatter
Configurable formatter for cluster account names.
Source code in src/slurm_usage_history/app/account_formatter.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
format_account(account)
Format account name by keeping first N segments.
Source code in src/slurm_usage_history/app/account_formatter.py
13 14 15 16 17 18 19 20 21 | |
app
create_dash_app(args, server=True, url_base_pathname='/')
Create a Dash app that visualizes data from the specified Parquet files.
Source code in src/slurm_usage_history/app/app.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
datastore
PandasDataStore
DataStore implementation using Pandas with enhanced filtering capabilities.
Implemented as a Singleton to ensure only one instance exists throughout the application lifecycle.
Source code in src/slurm_usage_history/app/datastore.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
__init__(directory=None, auto_refresh_interval=600, account_formatter=None)
Initialize the PandasDataStore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path | None
|
Path to the data directory. Defaults to current working directory if None. |
None
|
auto_refresh_interval
|
int
|
Refresh interval in seconds. Defaults to 600 seconds (10 minutes). |
600
|
account_formatter
|
Any | None
|
Formatter for account names. Defaults to None. |
None
|
Source code in src/slurm_usage_history/app/datastore.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
check_for_updates()
Check all hosts for new or changed files and reload if necessary.
Returns:
| Type | Description |
|---|---|
bool
|
True if any host was updated, False otherwise. |
Source code in src/slurm_usage_history/app/datastore.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
filter(hostname, start_date=None, end_date=None, partitions=None, accounts=None, users=None, qos=None, states=None, complete_periods_only=False, period_type='month', format_accounts=True, account_segments=None)
Public method to filter data with enhanced options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
start_date
|
str | None
|
Start date filter. |
None
|
end_date
|
str | None
|
End date filter. |
None
|
partitions
|
list[str] | None
|
List of partitions to include. |
None
|
accounts
|
list[str] | None
|
List of accounts to include. |
None
|
users
|
list[str] | None
|
List of users to include. |
None
|
qos
|
list[str] | None
|
List of QOS values to include. |
None
|
states
|
list[str] | None
|
List of job states to include. |
None
|
complete_periods_only
|
bool
|
Whether to include only complete time periods. |
False
|
period_type
|
str
|
Type of period when using complete_periods_only ('day', 'week', 'month', 'year'). |
'month'
|
format_accounts
|
bool
|
Whether to apply account name formatting. |
True
|
account_segments
|
int | None
|
Number of segments to keep. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered DataFrame. |
Source code in src/slurm_usage_history/app/datastore.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 | |
get_accounts(hostname)
Get available accounts for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available accounts for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
132 133 134 135 136 137 138 139 140 141 | |
get_complete_periods(hostname, period_type='month')
Get list of complete time periods available in the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
period_type
|
str
|
Type of period ('day', 'week', 'month', 'year'). |
'month'
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of complete periods. |
Source code in src/slurm_usage_history/app/datastore.py
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
get_hostnames()
Retrieve the list of hostnames.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available host names found in the data directory. |
Source code in src/slurm_usage_history/app/datastore.py
100 101 102 103 104 105 106 | |
get_min_max_dates(hostname)
Get minimum and maximum dates for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
tuple[str | None, str | None]
|
A tuple containing (min_date, max_date) for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
108 109 110 111 112 113 114 115 116 117 118 119 | |
get_partitions(hostname)
Get available partitions for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available partitions for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
121 122 123 124 125 126 127 128 129 130 | |
get_qos(hostname)
Get available QOS options for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available QOS options for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
154 155 156 157 158 159 160 161 162 163 | |
get_states(hostname)
Get available states for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available states for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
165 166 167 168 169 170 171 172 173 174 | |
get_users(hostname)
Get available users for the specified hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The cluster hostname. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of available users for the specified hostname. |
Source code in src/slurm_usage_history/app/datastore.py
143 144 145 146 147 148 149 150 151 152 | |
load_data()
Load all data files into the hosts dictionary.
Iterates through all hostnames and loads their respective data. Performance is measured using the timeit decorator.
Source code in src/slurm_usage_history/app/datastore.py
268 269 270 271 272 273 274 275 276 277 | |
set_refresh_interval(interval)
Change the auto-refresh interval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
int
|
New refresh interval in seconds. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the interval was updated and auto-refresh is running, |
bool
|
False if auto-refresh is not running. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the interval is not a positive integer. |
Source code in src/slurm_usage_history/app/datastore.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | |
start_auto_refresh(interval=None)
Start the background thread for automatic data refresh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
int | None
|
Optional refresh interval in seconds. If provided, overrides the interval set during initialization. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the provided interval is not a positive integer. |
Source code in src/slurm_usage_history/app/datastore.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
stop_auto_refresh()
Stop the background thread for automatic data refresh.
Signals the auto-refresh thread to stop and waits for its termination.
Source code in src/slurm_usage_history/app/datastore.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
Singleton
Bases: type
Metaclass to implement the Singleton pattern.
Ensures only one instance of a class exists.
Source code in src/slurm_usage_history/app/datastore.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
__call__(*args, **kwargs)
Override the call method to implement singleton behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Variable positional arguments to pass to the class constructor. |
()
|
**kwargs
|
Any
|
Variable keyword arguments to pass to the class constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
The singleton instance of the class. |
Source code in src/slurm_usage_history/app/datastore.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
get_datastore(directory=None, auto_refresh_interval=600, account_formatter=formatter)
Get the singleton instance of PandasDataStore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str | Path | None
|
Path to the data directory (only used if this is the first call). |
None
|
auto_refresh_interval
|
int
|
Refresh interval in seconds (only used if this is the first call). |
600
|
account_formatter
|
Any | None
|
Formatter for account names. Defaults to the imported formatter. |
formatter
|
Returns:
| Type | Description |
|---|---|
PandasDataStore
|
The singleton instance of PandasDataStore. |
Source code in src/slurm_usage_history/app/datastore.py
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 | |
layout
create_account_formatter_controls()
Create UI controls for account name formatting.
Source code in src/slurm_usage_history/app/layout.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
create_filter(component, title=None)
Create a consistently styled filter with an optional title
Source code in src/slurm_usage_history/app/layout.py
65 66 67 68 69 70 71 72 | |
create_section(title, children, id=None)
Create a section with a title and content
Source code in src/slurm_usage_history/app/layout.py
270 271 272 273 274 275 276 277 278 279 | |
main
main()
Main function to run the Dash app.
Source code in src/slurm_usage_history/app/main.py
28 29 30 31 32 33 34 35 36 37 38 39 | |
parse_arguments()
Parse command line arguments.
Source code in src/slurm_usage_history/app/main.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
node_config
NodeConfiguration
Class to handle node configuration for resources normalization.
Source code in src/slurm_usage_history/app/node_config.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
__init__(config_file=None)
Initialize the Node Configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Optional[str]
|
Path to config file (YAML or JSON) |
None
|
Source code in src/slurm_usage_history/app/node_config.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
get_all_node_resources(node_names)
Get CPU and GPU counts for a list of nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_names
|
List[str]
|
List of node names |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Dict[str, int]]
|
Dictionary mapping node names to resource dictionaries |
Source code in src/slurm_usage_history/app/node_config.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
get_node_cpu_count(node_name)
Get CPU count for a specific node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
str
|
Name of the node |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of CPUs for the node, or 1 if not configured |
Source code in src/slurm_usage_history/app/node_config.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
get_node_gpu_count(node_name)
Get GPU count for a specific node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_name
|
str
|
Name of the node |
required |
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of GPUs for the node, or 0 if not configured |
Source code in src/slurm_usage_history/app/node_config.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
load_config(config_file)
Load configuration from a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
str
|
Path to config file (YAML or JSON) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if loaded successfully, False otherwise |
Source code in src/slurm_usage_history/app/node_config.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
scripts
get_weekly_usage
DataExporter
Exports the fetched and formatted data.
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
__init__(data_fetcher, data_formatter)
Initialize the DataExporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_fetcher
|
UsageDataFetcher
|
UsageDataFetcher instance |
required |
data_formatter
|
UsageDataFormatter
|
UsageDataFormatter instance |
required |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
fetch_data_weekly(from_year, from_week, until_year=None, until_week=None, output_dir='slurmo_weekly_data', overwrite=False, verbose=False)
Fetch data weekly and save to Parquet files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_year
|
int
|
Starting year |
required |
from_week
|
int
|
Starting week |
required |
until_year
|
Optional[int]
|
Ending year (default: from_year) |
None
|
until_week
|
Optional[int]
|
Ending week (default: from_week) |
None
|
output_dir
|
str
|
Directory to save Parquet files |
'slurmo_weekly_data'
|
overwrite
|
bool
|
Whether to overwrite existing files |
False
|
verbose
|
bool
|
Whether to print verbose output |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of paths to saved Parquet files |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
UsageDataFetcher
Fetches usage data from the SLURM database.
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
__init__(command_executor=None)
Initialize the UsageDataFetcher with an optional command executor. This allows dependency injection for better testing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command_executor
|
Optional[Callable]
|
Function to execute shell commands. |
None
|
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
export_usage_data(from_year, from_week, until_year=None, until_week=None, verbose=False)
Export usage data for the specified date range.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_year
|
int
|
Starting year |
required |
from_week
|
int
|
Starting week |
required |
until_year
|
Optional[int]
|
Ending year (default: from_year) |
None
|
until_week
|
Optional[int]
|
Ending week (default: from_week) |
None
|
verbose
|
bool
|
Whether to print verbose output |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the combined usage data |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
get_week_dates(year, week, chunk_size=7)
staticmethod
Calculate the start and end dates of a specific week.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year. |
required |
week
|
int
|
The week number. |
required |
chunk_size
|
int
|
Number of days in the week (default is 7). |
7
|
Returns:
| Type | Description |
|---|---|
Tuple[datetime, datetime]
|
Tuple containing the start and end dates of the week. |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
run_sacct_command(sacct_start, sacct_end, verbose=False)
Run the sacct command and return the output as a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sacct_start
|
str
|
Start time for the command. |
required |
sacct_end
|
str
|
End time for the command. |
required |
verbose
|
bool
|
Whether to print verbose output. |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing the command output. |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
UsageDataFormatter
Formats the usage data DataFrame.
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
__init__()
Initialize the UsageDataFormatter.
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
253 254 255 256 257 258 259 260 | |
convert_mem_to_gb(mem_value)
staticmethod
Convert memory value to gigabytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mem_value
|
Union[str, float, None]
|
Memory value with unit (e.g., "1000M" or "1G") |
required |
Returns:
| Type | Description |
|---|---|
float
|
Float value in gigabytes |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
format_usage_data(df)
Format the usage data DataFrame: - Convert Start, End, and Submit columns to datetime format. - Split AllocTRES into separate columns: billing, cpu, gres_gpu, mem, node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
DataFrame containing usage data fetched from sacct command. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Formatted DataFrame with datetime columns and split AllocTRES. |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
calculate_date_range(weeks_back=None, from_date=None, to_date=None)
Calculate date range for data extraction based on different inputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weeks_back
|
Optional[int]
|
Number of weeks to go back from today |
None
|
from_date
|
Optional[str]
|
Starting date in ISO week format (YYYY-Www) |
None
|
to_date
|
Optional[str]
|
Ending date in ISO week format (YYYY-Www) |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[int, int, int, int]
|
Tuple of (from_year, from_week, until_year, until_week) |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
main()
Main entry point for the data fetcher.
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 | |
parse_iso_week(iso_week_str)
Parse an ISO week string in the format YYYY-Www (e.g., 2025-W01).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iso_week_str
|
str
|
ISO week string in the format YYYY-Www |
required |
Returns:
| Type | Description |
|---|---|
Tuple[int, int]
|
Tuple of (year, week_number) |
Source code in src/slurm_usage_history/scripts/get_weekly_usage.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
tools
categorize_time(hours)
Categorize time in hours into predefined categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hours
|
Union[float, int]
|
Time in hours to categorize. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The category corresponding to the given time. |
Source code in src/slurm_usage_history/tools.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
categorize_time_series(hours_series)
Categorize a Pandas Series of time in hours into predefined categories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hours_series
|
Series
|
A Pandas Series with time in hours. |
required |
Returns:
| Type | Description |
|---|---|
Series
|
A Pandas Series of categorical type with the corresponding categories. |
Source code in src/slurm_usage_history/tools.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
get_time_column(date_str1, date_str2)
Calculate the timespan in days between two dates provided in ISO format strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_str1
|
str
|
The first date in ISO format (YYYY-MM-DD). |
required |
date_str2
|
str
|
The second date in ISO format (YYYY-MM-DD). |
required |
Returns:
| Type | Description |
|---|---|
str
|
The column name to use based on the timespan between dates. |
Source code in src/slurm_usage_history/tools.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
month_to_date(year_month_str)
Convert a year-month string to a datetime object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year_month_str
|
str
|
String in format 'YYYY-MM' where YYYY is year and MM is month |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
First day of the specified month |
Source code in src/slurm_usage_history/tools.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
natural_sort_key(s)
Natural sorting function that handles numeric parts in strings properly. For example: "cpu2" will come before "cpu11" with natural sorting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
s
|
Optional[Union[str, Any]]
|
String to convert to a natural sort key |
required |
Returns:
| Type | Description |
|---|---|
Union[List[Union[int, str]], Any]
|
A list that can be used as a sort key with proper numeric ordering |
Source code in src/slurm_usage_history/tools.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
print_column_info_in_markdown(df)
Prints the column data types and an example value for each column in markdown format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
The dataframe to inspect. |
required |
Source code in src/slurm_usage_history/tools.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
timeit(func)
Decorator to measure execution time of a function.
Source code in src/slurm_usage_history/tools.py
10 11 12 13 14 15 16 17 18 19 | |
unpack_nodelist_string(nodelist_str)
Unpacks a GPU string into a list of individual components. Handles ranges (e.g., gpu[08-09,11,14]) and single items (e.g., gpu16).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodelist_str
|
Optional[str]
|
String containing node list information |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of individual node names |
Source code in src/slurm_usage_history/tools.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
week_to_date(year_week_str)
Convert a year-week string to a datetime object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year_week_str
|
str
|
String in format 'YYYY-WW' where YYYY is year and WW is week number |
required |
Returns:
| Type | Description |
|---|---|
datetime
|
First day (Monday) of the specified week |
Source code in src/slurm_usage_history/tools.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |