Skip to content
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

Update Boagent to 0.1.0 #54

Open
wants to merge 230 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
752401e
fix: removed volume for boaviztapi, using tag dev for scaphandre image
bdromard Feb 21, 2024
000eea9
fix: ignoring db sqlite files
bdromard Feb 21, 2024
a8ecc02
fix: added db creation step with sqlite3
bdromard Feb 21, 2024
371c460
fix: going back to previous scaphandre image, functioning boagent
bdromard Feb 21, 2024
56cccfb
docs: improving routes description
bpetit Feb 21, 2024
0d35e82
Merge branch 'dev' of github.com:Boavizta/boagent into dev
bdromard Feb 21, 2024
6ed5017
fix: corrected number of arguments for format for sorting disks
bdromard Feb 22, 2024
75f902b
fix: indentation for get_metrics
bdromard Feb 26, 2024
d70fb4a
fix: adding reload flag to uvicorn for dev environment
bdromard Feb 26, 2024
95954ff
config: add boagent volume for dev environment
bdromard Feb 26, 2024
e18b6ac
config: pytest dependency
bdromard Feb 26, 2024
c9afccb
fix: removed whitespaces
bdromard Feb 26, 2024
8778925
fix: csv route to fix
bdromard Feb 26, 2024
5b54d21
test: 200 codes for API endpoints
bdromard Feb 26, 2024
dd9f1df
config: update boaviztapi image to release 1.2.2
bdromard Feb 26, 2024
00d6b99
fix: removed whitespaces in configure_app
bdromard Feb 28, 2024
fee8572
fix: second info() fn, created recommendation() instead
bdromard Feb 28, 2024
602cdde
fix: modified volume to access power_data.json
bdromard Feb 28, 2024
42c232c
fix: checking if keys 'manufacturer' and 'USAGE' exist in boaviztapi_…
bdromard Feb 28, 2024
53b84b4
fix: database creation
bdromard Feb 28, 2024
801e985
test: implementing different use cases for read_query
bdromard Feb 28, 2024
1af577a
fix: checking for valid vendor, vendor as disk class property
bdromard Feb 29, 2024
113f560
fix: lowercase vendor for boaviztapi format request
bdromard Feb 29, 2024
f50b49e
fix: put settings in constants
bdromard Mar 4, 2024
6dd84bc
test: use mock files (json, db) for testing environment
bdromard Mar 4, 2024
e330bbd
fix: constants for public, azure and boaviztapi paths
bdromard Mar 4, 2024
1670766
fix: refactor cpu
bdromard Mar 4, 2024
847f9a0
feat: get scaphandre v1.0.0 image
bdromard Mar 4, 2024
e9430fd
fix: format scaphandre json
bdromard Mar 4, 2024
c02d729
Merge pull request #42 from Boavizta/40-upgrade-to-boaviztapi-v122
bdromard Mar 5, 2024
9f7162c
config: reduce pytz import
bdromard Mar 5, 2024
9e10631
fix: remove get_timeseries_data, duplicate of get_power_data
bdromard Mar 5, 2024
2272e6e
Merge pull request #43 from Boavizta/41-upgrade-to-scaphandre-v100
bdromard Mar 5, 2024
3b26e0b
refactor:commenting routes to be implemented / removed, returning 501…
bdromard Mar 5, 2024
64b65b2
refactor: typing for model and query_machine_impact_data
bdromard Mar 5, 2024
a4c2a6c
refactor: typing and syntax
bdromard Mar 5, 2024
c51002a
refactor: marking tests with pytest
bdromard Mar 6, 2024
c1c9b74
tests: modified folder structure for pytest
bdromard Mar 6, 2024
a3e4b87
fix: remove motherboard
bdromard Mar 6, 2024
56d0244
fix: syntax for return formatted_scaphandre_json
bdromard Mar 6, 2024
32d7868
fix: format cpu
bdromard Mar 6, 2024
152524d
fix: remove motherboard in config
bdromard Mar 6, 2024
a56dc88
config: dependencies for netbox-agent integration
bdromard Mar 7, 2024
c4eec48
config: tests folder structure in project
bdromard Mar 7, 2024
66b22c8
config: modified path to hardware_cli
bdromard Mar 7, 2024
5ad0166
feat: add lshw to fetch hardware, modified hardware folder structure
bdromard Mar 7, 2024
1281c2b
config: modified folder structure
bdromard Mar 7, 2024
1979ed6
feat: add check_disk_vendor as util
bdromard Mar 11, 2024
580fd07
test: testing lshw cpus and disks properties
bdromard Mar 11, 2024
4e0a01d
feat: WIP modifying lshw for boaviztapi data format
bdromard Mar 11, 2024
0fe4830
refactor: moved check_disk_vendor to lshw
bdromard Mar 11, 2024
3e34482
test: simplified assertions
bdromard Mar 11, 2024
d061396
test: testing ram data from lshw
bdromard Mar 11, 2024
4c4e008
feat: get ram data from lshw
bdromard Mar 11, 2024
f025f32
test: get units for each component, list slices for parsing data
bdromard Mar 11, 2024
8360fbf
feat: adding units for disks, cpus, ram
bdromard Mar 11, 2024
6fecd49
feat: check disk type with rotational
bdromard Mar 12, 2024
e3db639
test: testing check disk type and reading disk logicalname
bdromard Mar 12, 2024
742ffdc
feat: separate function for get rotational int
bdromard Mar 13, 2024
48dcf9a
test: mock rotational for get disk type
bdromard Mar 13, 2024
fd4cf48
test: test error handling for rotational_int and get_disk_type
bdromard Mar 13, 2024
e275ca8
test: modified tests files and directories structure
bdromard Mar 13, 2024
ead597f
feat: WIP lshw class instance in hardware_cli to fetch hardware
bdromard Mar 13, 2024
ece37c3
test: testing hardware cli main with click testing module
bdromard Mar 13, 2024
56552fe
test: test_api_integration in same folder as api, WIP modifying API code
bdromard Mar 13, 2024
ce7abac
test: adding file for api functions tests
bdromard Mar 13, 2024
5fcfa8d
test: correct format for read_hardware_data
bdromard Mar 14, 2024
62fd76b
fix: singular for components format
bdromard Mar 14, 2024
680fa59
fix: modified logic for check_vendor, format for component units, exc…
bdromard Mar 14, 2024
9125136
test: check_vendor, nvme-cli not installed exception, component units…
bdromard Mar 14, 2024
d31169b
refactor: get_rotational_int, check_disk_vendor and check_disk_type a…
bdromard Mar 18, 2024
dee59dc
config: pytest config for module importation
bdromard Mar 18, 2024
ecff149
test: get_hardware data with different booleans for fetch_hardware
bdromard Mar 18, 2024
5d02079
refactor: changed output name from main to hardware_data
bdromard Mar 18, 2024
24ff907
config: install pre-commit for formatting and linting
bdromard Mar 18, 2024
e83a265
Merge pull request #45 from Boavizta/44-integrate-netbox-agent-to-fet…
bdromard Mar 18, 2024
8374948
refactor: update to BoaviztAPI Server class, update to pydantic-settings
bdromard Mar 18, 2024
3c51abc
fix: format for carbon aware api token setting
bdromard Mar 18, 2024
39bcb00
test: plural for data keys
bdromard Mar 18, 2024
2e58a8c
feat: conditional for model list of length 1
bdromard Mar 18, 2024
e8b7823
test: raise exception as context manager for checking installation of…
bdromard Mar 18, 2024
a088dfb
docs: comments on change in BoaviztAPI SDK, on usage of generate_mach…
bdromard Mar 19, 2024
0be60df
test: import for query_machine_impact_data
bdromard Mar 19, 2024
85febee
test: refactor to show caught exception
bdromard Mar 19, 2024
2a92eba
Merge pull request #47 from Boavizta/46-update-boaviztapi-sdk-in-boagent
bdromard Mar 19, 2024
e02e921
test: format_usage_request with BoaviztAPI keys
bdromard Mar 19, 2024
72a20de
feat: add use_time_ratio and calculate avg_power in usage for Boavizt…
bdromard Mar 19, 2024
1b1bd8e
test: add compute average consumption test
bdromard Mar 19, 2024
8d1c31b
refactor: host_avg_consumption to avg_power
bdromard Mar 19, 2024
5e1f160
feat: add time_workload for BoaviztAPI request, typing
bdromard Mar 19, 2024
46b9b4e
test: format_usage_request with time workload as percentage
bdromard Mar 19, 2024
ae0cafa
refactor: iso8601 or timestamp fn returns float
bdromard Mar 19, 2024
c66775c
refactor: call for format_usage_request kwargs
bdromard Mar 19, 2024
0c65d68
test: get_power_data test, set setup variables
bdromard Mar 20, 2024
6c8232f
test: get_metrics test cases
bdromard Mar 20, 2024
48b9925
feat: get_metrics with BoaviztAPI 1.2.4. response format
bdromard Mar 20, 2024
b3efeca
refactor: remove deprecated usage_location status responses from Boav…
bdromard Mar 20, 2024
f9aa697
test: json mocks for tests
bdromard Mar 20, 2024
c9fadc9
refactor: typing in query and get_metrics
bdromard Mar 20, 2024
4516418
refactor: repo structure with tests directory and api modules
bdromard Mar 21, 2024
bb53826
refactor: moved test_lshw file in hardware
bdromard Mar 21, 2024
0ab925c
fix: modules importations
bdromard Mar 21, 2024
c7aa1fa
config: Dockerfile entrypoint & api module importations
bdromard Mar 25, 2024
62cea42
tests: mocks for tests
bdromard Apr 9, 2024
285e838
config: uvicorn start command modified to reflect module import
bdromard Apr 9, 2024
96cfc89
config: update requirements
bdromard Apr 9, 2024
f14007a
test: setting tests directory at boagent root
bdromard Apr 10, 2024
5ecc679
config: update config settings to use pydantic_settings package
bdromard Apr 10, 2024
5ae081a
config: settings instance in api
bdromard Apr 10, 2024
5f54763
config: dockerfile command at root of boagent directory
bdromard Apr 10, 2024
f67854c
test: mocking hardware_data in several test cases
bdromard Apr 11, 2024
50ebe1c
feat: add query post route with time_workload in request body
bdromard Apr 11, 2024
d091828
feat: build hardware_data directly in api module
bdromard Apr 11, 2024
15146ec
test: patch hardware_file_path for path resolution
bdromard Apr 11, 2024
41c2ef5
feat: try except block to handle non-root access to lshw, such as in …
bdromard Apr 11, 2024
3679baf
config: install lshw and nvme-cli for hardware output
bdromard Apr 22, 2024
a8a0fdc
fix: remove pool_threads, deprecated argument for BoaviztAPI SDK
bdromard Apr 22, 2024
97df8d5
refactor: remove sudo for lshw and nvme-cli in lshw class
bdromard Apr 22, 2024
9cb4f64
test: testing with formatted scaphandre JSON output for one hour
bdromard Apr 22, 2024
f513230
chore: remove duplicate requirements and csv log
bdromard Apr 23, 2024
8d9bf25
refactor: send lshw error messages to stderr
bdromard Apr 23, 2024
388277b
feat: parsing power_data for json query
bdromard Apr 23, 2024
9f08e45
refactor: typing for location and time_workload
bdromard Apr 24, 2024
c5f5b04
test: typing for time_workload
bdromard Apr 24, 2024
68e4c78
feat: time_workload list as pydantic model, example in models
bdromard Apr 24, 2024
4d2eebc
feat: add warning in response when location is default or unset
bdromard Apr 24, 2024
b41596a
test: warning message present when location is unset or default
bdromard Apr 24, 2024
122d1d2
feat: format prometheus output for verbose, total impacts and impacts…
bdromard Apr 25, 2024
5109ab0
test: format prometheus output, with mocks
bdromard Apr 25, 2024
83d72a6
feat: add verbose to format_prometheus_output, adjust to prometheus f…
bdromard Apr 29, 2024
8c56973
feat: remove label, each impact value represented as one metric
bdromard Apr 29, 2024
cf70015
test: format_prometheus_output with verbose argument
bdromard Apr 29, 2024
1ae9539
test: remove print output in test
bdromard Apr 29, 2024
cf33a4e
fix: correct format of components to search in prometheus_output
bdromard Apr 29, 2024
27d19b3
doc: update README
bdromard May 2, 2024
66e30da
doc: update README
bdromard May 2, 2024
b19f5a4
config: using scaphandre-dev docker image
bdromard May 6, 2024
08da128
test: testing api endpoints with mocks
bdromard May 6, 2024
f2e1dc7
config: ignore virtual environment directory
bdromard May 6, 2024
f54b5dc
config: remove cpuid dependencies
bdromard May 6, 2024
0bc4a71
refactor: cpu code not needed anymore by using lshw
bdromard May 6, 2024
bdf83a9
docs: update README, changes for installing boagent locally
bdromard May 6, 2024
dec4eb4
fix: remove useless items variable
bdromard May 6, 2024
7ffc2e5
config: update dockerfile, lighter docker image with useless dependen…
bdromard May 6, 2024
65b8837
config: remove empty or useless files
bdromard May 6, 2024
440ff98
docs: change version in init
bdromard May 6, 2024
5a42740
chore(ci): upgrade github actions following Node 16 deprecation
May 24, 2024
b5c8fa7
feat: add process_embedded_impacts route, get_process_info function
bdromard May 27, 2024
fb9b929
test: get_process_info
bdromard May 27, 2024
585fee6
test: process_embedded_impacts route
bdromard May 27, 2024
49eb4a0
Merge pull request #51 from Boavizta/50-choreci-upgrade-github-action…
bdromard May 27, 2024
dd5f4f2
config: modify scaphandre container cmd to get processes and consumed…
bdromard May 29, 2024
674d50a
feat: calculate total ram for host, get ram usage by process and time…
bdromard May 29, 2024
99a4840
test: process info, total ram for host, ram usage per process
bdromard May 29, 2024
8226319
test: mocks from scaphandre 1.0.0
bdromard May 29, 2024
74dfcc3
feat: calculate embedded impact for ram for each ram share
bdromard Jun 3, 2024
b47bff4
test: ram embedded impact share by timestamp
bdromard Jun 3, 2024
381c311
refactor: implement retrieval of process info through process class
bdromard Jun 4, 2024
693b055
test: refactor to test process class
bdromard Jun 4, 2024
5a8f8ea
refactor: calculate abstract component embedded impact shares instead…
bdromard Jun 4, 2024
2dc985e
test: cpu embedded impact shares
bdromard Jun 4, 2024
a035914
feat: WIP calculate average values for each impact for each component
bdromard Jun 4, 2024
746ce42
test: calculate average embedded impacts for component
bdromard Jun 4, 2024
5655945
refactor: calculate average for gwp, adp and pe criterias for queried…
bdromard Jun 5, 2024
94b88a9
test: average impact share for cpu and ram, rewrote a few assertions …
bdromard Jun 5, 2024
150908f
feat: get max and min in addition of average values, refactored a few…
bdromard Jun 5, 2024
64cd6dc
test: avg, min and max embedded impacts for cpu and ram, call process…
bdromard Jun 5, 2024
5fdb961
feat: WIP process_id validation in Process class for error handling
bdromard Jun 5, 2024
bea9557
test: success and error handling for process_embedded_impacts route
bdromard Jun 5, 2024
bcac79c
test: WIP validate PID error handling
bdromard Jun 5, 2024
6d8483a
feat: validating PID, refactored get_process_info
bdromard Jun 6, 2024
834ab70
feat: create invalid process_id exception
bdromard Jun 6, 2024
e7930d8
test: check invalid pid exception and message
bdromard Jun 6, 2024
7106d40
test: add assertion to check response content for process_embedded_im…
bdromard Jun 10, 2024
5799077
refactor: pids as set to only have unique values and not iterate thro…
bdromard Jun 10, 2024
591dd15
feat: process_embedded_impacts response with invalid pid
bdromard Jun 10, 2024
f5f7036
test: assertions to check data in process_details
bdromard Jun 10, 2024
eac077f
doc: document parameters for process_embedded_impacts route
bdromard Jun 10, 2024
8f26a25
fix: error handling when invalid component is queried
bdromard Jun 12, 2024
bc3afde
test: assertions to check data in process_embedded_impacts response
bdromard Jun 12, 2024
decacaa
feat: return json content for process_embedded_impacts
bdromard Jun 12, 2024
c4bfb61
feat: WIP get ssd embedded impacts through 219M .
bdromard Jun 12, 2024
10efcc9
test: process exe, process disk usage, process ssd embedded impact
bdromard Jun 12, 2024
101258f
refactor: setting process class properties with decorators
bdromard Jun 19, 2024
7aed87b
test: process name and exe as attributes, assertions for process pid …
bdromard Jun 19, 2024
2de42c9
config: install poetry
bdromard Jun 19, 2024
5a1acc0
feat: install dependencies and run uvicorn through poetry
bdromard Jun 19, 2024
28083a4
Merge pull request #52 from Boavizta/install-poetry
bdromard Jul 16, 2024
4234206
fix: json key for cpu from 'vendor' to 'manufacturer'
bdromard Jul 22, 2024
b7b2361
fix: cpu core_units as integer
bdromard Jul 23, 2024
002c7e7
test: cpu manufacturer key, cpu core_units as integer
bdromard Jul 23, 2024
676e1db
fix: calculate storage embedded impact for process through written by…
bdromard Sep 16, 2024
319e025
refactor: create distinct process route tests file
bdromard Sep 17, 2024
176de06
chore: modify fake get metrics with hdd and no hdd
bdromard Sep 17, 2024
e3ebaf3
feat: add hdd as queryable component
bdromard Sep 17, 2024
67ac6a9
refactor: add embedded_impact_values as property of process class
bdromard Sep 17, 2024
50e71bf
test: check hdd embedded impacts are present
bdromard Sep 17, 2024
12cb70d
test: embedded_impact_values property and error handling
bdromard Sep 17, 2024
8e5a53e
refactor: embedded_impact_values as property
bdromard Sep 18, 2024
9c9e953
fix: add boolean for fetch_hardware on process route
bdromard Sep 18, 2024
d6f27d0
Merge pull request #53 from Boavizta/48-feature-route-to-get-per-proc…
bdromard Sep 18, 2024
84dd682
fix: send total size of ssd and not used storage
bdromard Sep 19, 2024
d117274
chore: remove disk and ram folders
bdromard Sep 19, 2024
3356de8
chore: remove dead code, concerning database, cron, pandas
bdromard Sep 19, 2024
e59a9a3
chore: remove tests for deleted routes
bdromard Sep 19, 2024
715892f
chore: remove yearly_embedded route
bdromard Sep 19, 2024
ce37187
chore: remove ready query machine impact test
bdromard Sep 19, 2024
625b7db
docs: update boagent documentation
bdromard Sep 23, 2024
f53168c
fix: raise python exceptions
bdromard Sep 23, 2024
4b4e3d0
test: check lshw installation
bdromard Sep 23, 2024
e86cbe1
chore: move hardware_cli at project root
bdromard Sep 23, 2024
34c26fb
build: remove sqlalchemy
bdromard Sep 23, 2024
d91a424
test: change import of hardware_cli
bdromard Sep 23, 2024
e4021c3
build: add httpx
bdromard Sep 23, 2024
a79a789
refactor: serialized_lshw_output as external function
bdromard Sep 25, 2024
725e9cb
refactor: error handling with click, lshw instance in main
bdromard Sep 25, 2024
9d74841
fix: mock lshw, lshw attributes to avoid side effects
bdromard Sep 25, 2024
ebe63a7
test: mock nvme, add assertions to check data from mocks
bdromard Sep 25, 2024
c499a34
refactor: serialize nvme output as external function
bdromard Sep 25, 2024
cefebc8
build: change poetry install, remove comments from docker-compose
bdromard Sep 25, 2024
234dffd
build: modify click imports
bdromard Sep 25, 2024
828aeb6
build: update dependencies
bdromard Sep 25, 2024
11c86d5
refactor: create mocks module with mocklshw
bdromard Sep 25, 2024
6772341
ci: execute test job, push & pr on main and dev
bdromard Sep 25, 2024
85289f4
ci: add python 3.11 for test matrix
bdromard Sep 25, 2024
7e588fb
fix: filenotfounderror for hardware_data in test
bdromard Sep 25, 2024
47665c7
refactor: simplify access to mock files
bdromard Sep 30, 2024
33e4a84
fix: use metrics_data in process, not filepath to process metrics
bdromard Oct 1, 2024
2741192
feat: add pid in process_embedded_impacts response
bdromard Oct 1, 2024
5131d70
feat: add process_embedded_values key in response
bdromard Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.git
venv
6 changes: 3 additions & 3 deletions .github/workflows/greenhack22.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python 3
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Python 3
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'

Expand Down
40 changes: 40 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Execute tests

on:
push:
branches:
- main
- dev
paths:
- "boagent/**"
- "tests/**"
- "poetry.lock"
- "pyproject.toml"
pull_request:
branches:
- main
- dev
paths:
- "boagent/**"
- "tests/**"
- "poetry.lock"
- "pyproject.toml"

jobs:
test:
strategy:
matrix:
version: ["3.10", "3.11"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Python setup
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
- name: Poetry setup
run : python3 -m pip install --upgrade poetry wheel
- name: Install dependencies
run: poetry install
- name: Execute tests
run: poetry run python3 -m pytest
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,6 @@ dmypy.json
.idea/
.vscode/

*.json
*.db
*.svg
*.csv
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
entry: flake8 --ignore=E501,W503 --per-file-ignores='__init__.py:F401'
18 changes: 6 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ FROM python:3.10-slim

LABEL org.opencontainers.image.authors="[email protected]"

RUN apt update && apt install gcc g++ -y

RUN apt-get install -y cron sqlite3

RUN useradd -ms /bin/bash boagent

#USER boagent

WORKDIR /home/boagent

COPY requirements.txt requirements.txt
RUN python3 -m pip install --upgrade poetry

RUN apt update && apt install lshw nvme-cli -y

RUN pip3 install -r requirements.txt
COPY pyproject.toml .

ENV PATH $PATH:/home/boagent/.local/bin
RUN poetry install

COPY . .

EXPOSE 8000

ENTRYPOINT [ "/bin/bash", "-c", "cd boagent/api && uvicorn api:app --host 0.0.0.0" ]
ENTRYPOINT ["poetry", "run", "uvicorn", "--reload", "boagent.api.api:app", "--host", "0.0.0.0"]
66 changes: 51 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,73 @@ _If no parameters are passed to the API to isolate the application, then the imp

## How to use

This is an API, you could use either your browser, curl, or call it directly from an application (which is the main usecase).
This is an API, you could use either your browser, cURL, or call it directly from an application (which is the main usecase).

Once the API is running, a Swagger interface is available on [localhost:8000/docs](http://localhost:8000/docs).


### Run natively

Boagent will not be able to return proper responses from its endpoints without root privileges in order to fetch hardware data.
It also needs information from BoaviztAPI and Scaphandre, see the [setup informations](#Setup).

To run it :

Without `poetry`

```
cd boagent/
apt update && apt install lshw nvme-cli -y
pip3 install -r requirements.txt
cd api/
cd boagent/api/
uvicorn api:app --reload
```

The app can run without root privileges, but you won't get full data about the RAM and get some warnings.
Run as root to have the best evaluation possible.
With `poetry`

```
apt update && apt install lshw nvme-cli -y
poetry install --only main
poetry run uvicorn --reload boagent.api.api:app
```

### Run in a docker container

You could pull the [image](https://github.com/Boavizta/boagent/pkgs/container/boagent) with `docker pull ghcr.io/boavizta/boagent:latest`.

### Run in docker-compose (with all the requirements)

To get started you need docker and docker-compose installed on your machine. On a debian or ubuntu machine, run :
To get started you need docker and docker-compose installed on your machine. On a Debian or Ubuntu environment, run :

# apt update && apt install -y docker.io docker-compose

To get the full setup easily, you could run the stack in docker-compose with `docker-compose up -d`. `docker-compose.yml`, at the root of the project will build a docker image from the source for boagent, and setup a container for [Scaphandre](#Scaphandre) and another for the [BoaviztAPI](#BoaviztAPI), allowing you to get the full evaluation easily on a physical machine.
To get the full setup easily, you could run the stack in docker-compose with `docker-compose up -d`. `docker-compose.yml`, at the root of the project will build a Docker image from the source for Boagent, and setup a container for [Scaphandre](#Scaphandre) and another for the [BoaviztAPI](#BoaviztAPI), allowing you to get the full evaluation easily on a physical machine.

Please see [Configuration](#Configuration) for the environment variables you can tweak in the Boagent container.

## Setup required
### Use `hardware_cli`

To have an example of the retrieved hardware information by Boagent, you can run `sudo ./hardware_cli.py`.
At the moment, it will output the formatted data for CPU, RAM and storage devices used by Boagent when sending a request to BoaviztAPI.
`sudo ./hardware_cli.py --output-file <file>` can send the formatted output to a file.

## Setup

## Linux

Boagent parses output from `lshw` (a tool listing hardware components and characteristics) and `nvme-cli` (a tool listing information on SSD storage
devices available through NVME interfaces). To get all actually parsed information (and for future developments), Boagent needs those two programs and toexecute them with root privileges.

### BoaviztAPI

You need either to use an existing BoaviztAPI endpoint, or to build the BoaviztAPI container image, then run the container locally on port 5000.

Depending or your setup, specify the endpoint to be used with the environment variable `BOAVIZTAPI_ENDPOINT`, see [Configuration](#Configuration).

Ensure that the version of BoaviztAPI SDK installed (see `requirements.txt`) is the same as the version of the API running the endpoint you use.
Ensure that the version of BoaviztAPI SDK installed (see `requirements.txt` or `pyproject.toml`) is the same as the version of the API running the endpoint you use.

### Scaphandre

To get power consumption metrics, you need [Scaphandre](https://github.com/hubblo-org/scaphandre) runnig in the background, with the json exporter. This will write power metrics to a file, that Boagent will read :
To get power consumption metrics, you need [Scaphandre](https://github.com/hubblo-org/scaphandre) running in the background, with the JSON exporter. This will write power metrics to a file, that Boagent will read :

```
scaphandre json -s 5 -f power_data.json
Expand All @@ -65,11 +87,11 @@ scaphandre json -s 5 -f power_data.json

Boagent can be configured with the following variables :

- `DEFAULT_LIFETIME`: machines lifetime used to compute the scope 3 / manufacturing, transport, end of life impacts
- `HARDWARE_FILE_PATH`: path to the file containing the hardware list (output from hardware.py)
- `POWER_FILE_PATH`: path to the file containing power mearsurements (output from [Scaphandre](https://github.com/hubblo-org/scaphandre) with JSON exporter)
- `HARDWARE_CLI`: path to the executable file to collect hardware information (hardware.py from this project)
- `BOAVIZTAPI_ENDPOINT`: http endpoint to the BoaviztAPI, in the form `http://myendpoint.com:PORTNUMBER`
- `DEFAULT_LIFETIME`: machines lifetime used to compute the scope 3 / manufacturing, transport, end-of-life impacts
- `HARDWARE_FILE_PATH`: path to the file containing the hardware list (output from `lshw.py`)
- `POWER_FILE_PATH`: path to the file containing power measurements (output from [Scaphandre](https://github.com/hubblo-org/scaphandre) with JSON exporter)
- `HARDWARE_CLI`: path to the executable file to collect hardware information (`lshw.py` from this project)
- `BOAVIZTAPI_ENDPOINT`: HTTP endpoint to the BoaviztAPI, in the form `http://myendpoint.com:PORTNUMBER`

You can set those variables in the following order (as interpreted by the tool):

Expand All @@ -79,6 +101,20 @@ You can set those variables in the following order (as interpreted by the tool):

You can check the configuration applied by querying the `/info` route.

## How it works

Currently, Boagent only works for Linux systems.

Boagent exposes multiple API endpoints, most notably `/query` and `/metrics`. Both will query an instance of [BoaviztAPI](https://doc.api.boavizta.org/) in order to give the environmental impacts
of the received hardware data. `/query` will return a response in JSON format, and `/metrics` will return a response parsable by a Prometheus instance. If needed, both those
endpoints can return data from [Scaphandre](https://github.com/hubblo-org/scaphandre/) and give the energy consumption of components from the queried hardware.

Presently, Boagent gets hardware data through a parsing of the output of `lshw`, a common utility available for Linux distributions that lists a lot of information of all
hardware components on a running computer. The code for this `Lshw` class is an adaptation of [netbox-agent](https://github.com/Solvik/netbox-agent)'s implementation.
`lshw`, to get all proper data needed by BoaviztAPI, needs to be executed as a privileged user with `sudo`. Boagent, executed with the available `docker-compose` file,
will run as privileged and will be able to receive the needed hardware data. At the moment, only data for the CPU, RAM and storage (either HDD or SSD) are parsed and sent to BoaviztAPI
in order to calculate impacts.

## Deeper explanations

### Environmental metrics
Expand Down
6 changes: 3 additions & 3 deletions boagent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
Monitoring agent/framework for evaluating the environmental impacts of a machine and its applications, including several to all steps of the life cycle of the machine and service, plus multiple criterias of impacts (not just CO2eq metrics / Global Warming Potential). Part of the efforts of https://boavizta.org/en and https://sdialliance.org/.
"""

__version__ = "0.0.8"
__author__ = 'Benoit Petit <[email protected]>'
__credits__ = 'Boavizta contributors'
__version__ = "0.0.9"
__author__ = "Benoit Petit <[email protected]>"
__credits__ = "Boavizta contributors"
Loading