-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:green-coding-solutions/green-metric…
…s-tool * 'main' of github.com:green-coding-solutions/green-metrics-tool: Codespaces merge into main (#993) Container energy idle (#992)
- Loading branch information
Showing
41 changed files
with
346 additions
and
219 deletions.
There are no files selected for viewing
This file contains 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,36 @@ | ||
#!/bin/bash | ||
set -euxo pipefail | ||
|
||
# we have to rename this makefile as it doesn't compile in Codespaces | ||
if [ -f /workspaces/green-metrics-tool/metric_providers/lm_sensors/Makefile ]; then | ||
mv /workspaces/green-metrics-tool/metric_providers/lm_sensors/Makefile /workspaces/green-metrics-tool/metric_providers/lm_sensors/Makefile.bak | ||
git update-index --assume-unchanged /workspaces/green-metrics-tool/metric_providers/lm_sensors/Makefile | ||
fi | ||
|
||
/workspaces/green-metrics-tool/install_linux.sh -p testpw -a "https://${CODESPACE_NAME}-9142.app.github.dev" -m "https://${CODESPACE_NAME}-9143.app.github.dev" -t -i -s -l | ||
source venv/bin/activate | ||
|
||
# Also add XGBoost, as we need it | ||
python3 -m pip install -r /workspaces/green-metrics-tool/metric_providers/psu/energy/ac/xgboost/machine/model/requirements.txt | ||
|
||
# make edits to ports so we can use 9143 to access front end | ||
sed -i 's/listen \[::\]:9142;/listen [::]:9143;/; s/listen 9142;/listen 9143;/' /workspaces/green-metrics-tool/docker/nginx/frontend.conf | ||
sed -i 's/- 9142:9142/- 9142:9142\n - 9143:9143/' /workspaces/green-metrics-tool/docker/compose.yml | ||
sed -i 's|- ./nginx/block.conf|#- ./nginx/block.conf|' /workspaces/green-metrics-tool/docker/compose.yml | ||
|
||
# activate XGBoost provider with sane values for GitHub Codespaces | ||
sed -i 's/common:/common:\n psu.energy.ac.xgboost.machine.provider.PsuEnergyAcXgboostMachineProvider:\n resolution: 99\n CPUChips: 1\n HW_CPUFreq: 2800\n CPUCores: 32\n CPUThreads: 64\n TDP: 270\n HW_MemAmountGB: 256\n VHost_Ratio: 0.03125\n/' /workspaces/green-metrics-tool/config.yml | ||
|
||
|
||
git clone https://github.com/green-coding-solutions/example-applications.git --depth=1 --single-branch /workspaces/green-metrics-tool/example-applications || true | ||
|
||
source venv/bin/activate | ||
|
||
docker compose -f /workspaces/green-metrics-tool/docker/compose.yml down | ||
|
||
docker compose -f /workspaces/green-metrics-tool/docker/compose.yml up -d | ||
|
||
|
||
gh codespace ports visibility 9142:public -c $CODESPACE_NAME | ||
|
||
gh codespace ports visibility 9143:public -c $CODESPACE_NAME |
This file contains 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,31 @@ | ||
{ | ||
"postStartCommand": "/workspaces/green-metrics-tool/.devcontainer/on-start.sh", | ||
"forwardPorts": [9142, 9143], | ||
"portsAttributes": { | ||
"9143": { | ||
"label": "metrics page" | ||
}, | ||
"9142": { | ||
"label": "api" | ||
} | ||
}, | ||
"customizations": { | ||
"codespaces": { | ||
"openFiles": [ | ||
".devcontainer/splash.md" | ||
] | ||
}, | ||
"vscode": { | ||
"settings": { | ||
"workbench.editorAssociations": { | ||
"*.md": "vscode.markdown.preview.editor" // Open markdown files in preview mode by default | ||
} | ||
}, | ||
"extensions": | ||
[ | ||
"ms-python.python", | ||
"ms-azuretools.vscode-docker" | ||
] | ||
} | ||
} | ||
} |
This file contains 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,17 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
etc_hosts_line_1="127.0.0.1 green-coding-postgres-container" | ||
|
||
echo "Writing to /etc/hosts file..." | ||
|
||
# Entry 1 is needed for the local resolution of the containers through the jobs.py and runner.py | ||
if ! sudo grep -Fxq "$etc_hosts_line_1" /etc/hosts; then | ||
echo "$etc_hosts_line_1" | sudo tee -a /etc/hosts | ||
else | ||
echo "Entry was already present..." | ||
fi | ||
|
||
# Ensure that after a restart of the Codespace the ports are set to public again | ||
gh codespace ports visibility 9142:public -c $CODESPACE_NAME | ||
gh codespace ports visibility 9143:public -c $CODESPACE_NAME |
This file contains 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,35 @@ | ||
# Green Metrics Tool Codespaces Quickstart | ||
|
||
Thank you for trying out the Green Metrics Tool :-) | ||
|
||
Please run the following command in the terminal to set up everything! 🚀 | ||
|
||
```sh | ||
bash .devcontainer/codespace-setup.sh | ||
``` | ||
|
||
It will take about 3 minutes. | ||
|
||
Afterwards, load the python environment: | ||
|
||
```sh | ||
source venv/bin/activate | ||
``` | ||
|
||
Do your first measurement run like this: | ||
|
||
```sh | ||
python3 runner.py --name "Simple Test" --uri "/workspaces/green-metrics-tool/example-applications/" --filename "stress/usage_scenario.yml" --skip-system-checks --dev-no-optimizations --dev-cache-build | ||
``` | ||
|
||
Then, if you want to see a more representative repository, try running our Bakery Demo repository we did together with the Wagtail Community: | ||
|
||
```sh | ||
python3 runner.py --uri https://github.com/green-coding-solutions/bakerydemo --branch gmt --skip-system-checks --dev-no-optimization --dev-cache-build --skip-unsafe --name "Bakery Demo Test" | ||
``` | ||
|
||
To see the Metrics front end, go to your ports tab and follow the forwarding address for port 9143. | ||
|
||
Make sure the `api` port (9142) is public. If it's private, the metrics frontend will not be able to access the API due to CORS issues. | ||
|
||
If you are experiencing problems, see the file [.devcontainer/troubleshooting.md](./troubleshooting.md) for some common troubleshooting tips. |
This file contains 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,27 @@ | ||
# Troubleshooting | ||
|
||
## Frontend can't be open | ||
|
||
Make sure the ports 9142 (`api`) und 9143 (`metrics page`) are public. If they are private, the metrics frontend will not be able to access the API due to CORS issues. After a restart of the codespace the ports are set to private, so you have to change the visibility manually. | ||
|
||
You can use the following commands in the terminal to make the ports public: | ||
|
||
```sh | ||
gh codespace ports visibility 9142:public -c $CODESPACE_NAME | ||
gh codespace ports visibility 9143:public -c $CODESPACE_NAME | ||
``` | ||
|
||
## Connection to server failed | ||
|
||
If you entcounter an error like | ||
|
||
```log | ||
error connecting in 'pool-1': connection failed: connection to server at "127.0.0.1", port 9573 failed: Connection refused | ||
Is the server running on that host and accepting TCP/IP connections? | ||
``` | ||
|
||
then ensure that the Docker containers of GMT are running. | ||
|
||
```sh | ||
docker compose -f docker/compose.yml up -d | ||
``` |
This file contains 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 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
CFLAGS = -O3 -Wall | ||
|
||
all: parse_int.o detect_cgroup_path.o | ||
|
||
parse_int.o: parse_int.c | ||
gcc -c $< $(CFLAGS) -o $@ | ||
|
||
detect_cgroup_path.o: detect_cgroup_path.c | ||
gcc -c $< $(CFLAGS) -o $@ |
This file contains 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,64 @@ | ||
#include "detect_cgroup_path.h" | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <limits.h> | ||
#include <errno.h> | ||
|
||
char* detect_cgroup_path(const char* controller, int user_id, const char* id) { | ||
char* path = malloc(PATH_MAX); | ||
if (path == NULL) { | ||
fprintf(stderr, "Could not allocate memory for detect_cgroup_path\n"); | ||
exit(1); | ||
} | ||
|
||
FILE* fd = NULL; | ||
|
||
// Try cgroups v2 with systemd slices (typically in rootless mode) | ||
snprintf(path, PATH_MAX, | ||
"/sys/fs/cgroup/user.slice/user-%d.slice/user@%d.service/user.slice/docker-%s.scope/%s", | ||
user_id, user_id, id, controller); | ||
fd = fopen(path, "r"); | ||
if (fd != NULL) { | ||
fclose(fd); | ||
return path; | ||
} | ||
|
||
// Try cgroups v2 with systemd but non-slice mountpoints (typically in non-rootless mode) | ||
snprintf(path, PATH_MAX, | ||
"/sys/fs/cgroup/system.slice/docker-%s.scope/%s", | ||
id, controller); | ||
fd = fopen(path, "r"); | ||
if (fd != NULL) { | ||
fclose(fd); | ||
return path; | ||
} | ||
|
||
// Try cgroups v2 without slice mountpoints (used in Github codespaces) | ||
snprintf(path, PATH_MAX, | ||
"/sys/fs/cgroup/docker/%s/%s", | ||
id, controller); | ||
fd = fopen(path, "r"); | ||
if (fd != NULL) { | ||
fclose(fd); | ||
return path; | ||
} | ||
|
||
// Try cgroups v2 without slice mountpoints and in subdir (used in Github actions) | ||
snprintf(path, PATH_MAX, | ||
"/sys/fs/cgroup/actions_job/%s/%s", | ||
id, controller); | ||
fd = fopen(path, "r"); | ||
if (fd != NULL) { | ||
fclose(fd); | ||
return path; | ||
} | ||
|
||
// If no valid path is found, free the allocated memory and error | ||
free(path); | ||
fprintf(stderr, "Error - Could not open container for reading: %s. Maybe the container is not running anymore? Errno: %d\n", id, errno); | ||
exit(1); | ||
|
||
} | ||
|
This file contains 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,6 @@ | ||
#ifndef DETECT_CGROUP_PATH_H | ||
#define DETECT_CGROUP_PATH_H | ||
|
||
char* detect_cgroup_path(const char* controller, int user_id, const char* id); | ||
|
||
#endif // DETECT_CGROUP_PATH_H |
This file contains 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
Oops, something went wrong.