Skip to content

Commit

Permalink
Merge pull request #5 from deNBI/refactor/dev
Browse files Browse the repository at this point in the history
Refactor/dev
  • Loading branch information
eKatchko authored Aug 4, 2020
2 parents 301cd65 + 4f85785 commit c643753
Show file tree
Hide file tree
Showing 14 changed files with 657 additions and 321 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea

*openrc*
# Swap
[._]*.s[a-v][a-z]
Expand Down Expand Up @@ -96,8 +98,6 @@ profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.7.8
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM python:3.7-alpine

RUN apk add --no-cache linux-headers musl-dev gcc libffi-dev openssl-dev
COPY . /code
WORKDIR /code
RUN pip install --no-cache pipenv && pipenv install --system --deploy --ignore-pipfile
ADD requirements.txt /code
RUN pip install -r requirements.txt
COPY . /code

EXPOSE 8080
CMD ["python", "project_usage_exporter.py"]
78 changes: 63 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ Exported labels per project are:
- `project_name`

## Requirements/Installation
All dependencies are managed with a requirements.txt. Create a virtual environment with a tool of your choosing
(e.g. [*pyenv*](https://github.com/pyenv/pyenv) with [*pyenv-virtualenv*](https://github.com/pyenv/pyenv-virtualenv) or [*venv*](https://docs.python.org/3/library/venv.html)) and
install with `pip install -r requirements.txt`.

All production and development dependencies are managed via
Deprecated:
~~All production and development dependencies are managed via
[*pipenv*](https://pipenv.readthedocs.io). Therefore simply go via `pipenv install` or
start directly with one of the modi listed below. You can activate the virtual
environment via `pipenv shell` or simply prefix any command with `pipenv run` to have it
run inside the corresponding environment.
run inside the corresponding environment.~~

A [docker image](https://hub.docker.com/r/tluettje/os_project_usage_exporter/) is
available as well and all command line options do have corresponding environment
Expand All @@ -39,11 +43,20 @@ optional arguments:
-h, --help show this help message and exit
-d DUMMY_DATA, --dummy-data DUMMY_DATA
Use dummy values instead of connecting to an openstack
instance. Usage values are calculated base on the
configured existence, take a look at the example file
for an explanation resources/dummy_machines.toml. Can
also be provided via environment variable
$USAGE_EXPORTER_DUMMY_FILE (default: None)
instance. Usage values are calculated based on the
configured existence. Toml files can be updated on the
fly as they are read every time a dummy-cloud function
is called (functions of nested classes excluded). Take
a look at the example file for an explanation
resources/dummy_cc.toml. Can also be provided via
environment variable $USAGE_EXPORTER_DUMMY_FILE
(default: None)
-w DUMMY_WEIGHTS, --dummy-weights DUMMY_WEIGHTS
Use dummy weight endpoint instead of connecting to the
api. Take a look at the example file for an
explanation resources/dummy_weights.toml. Can also be
provided via environment variable
$USAGE_EXPORTER_DUMMY_WEIGHTS_FILE (default: None)
--domain [DOMAIN [DOMAIN ...]]
Only export usages of projects belonging to one of the
given domains. Separate them via comma if passing via
Expand All @@ -55,17 +68,52 @@ optional arguments:
identified by the given ID. Takes precedence over any
specified domain and default values. Can also be set
via $USAGE_EXPORTER_PROJECT_DOMAIN_ID (default: )
--vcpu-weights VCPU_WEIGHTS
Use weights for different numbers of cpus in a vm.
Value is given as the string representation of a
dictionary with ints as keys and as values. a weight
of 1 means no change. Above 1 its more expensive,
under one it is less expensive. Can also be set via
$USAGE_EXPORTER_VCPU_WEIGHTS (default: {})
--mb-weights MB_WEIGHTS
Use weights for different numbers of mb (of ram) in a
vm. Value is given as the string representation of a
dictionary with ints as keys and as values. a weight
of 1 means no change. Above 1 its more expensive,
under one it is less expensive. Can also be set via
$USAGE_EXPORTER_PROJECT_MB_WEIGHTS (default: {})
--simple-vm-id SIMPLE_VM_ID
The ID of the Openstack project, that hosts the
SimpleVm projects. Can also be set vis
$USAGE_EXPORTER_SIMPLE_VM_PROJECT_ID (default: )
--simple-vm-tag SIMPLE_VM_TAG
The metadata of the Openstack project, that hosts the
SimpleVm projects. It is used to differentiate the
simple vm projects, default: project_name Can also be
set vis $USAGE_EXPORTER_SIMPLE_VM_PROJECT_TAG
(default: project_name)
--weight-update-frequency WEIGHT_UPDATE_FREQUENCY
The frequency of checking if there is a weight update.
Is a multiple of the update interval length . Defaults
to the value of environment variable
$USAGE_EXPORTER_WEIGHT_UPDATE_FREQUENCY or 10
(default: 10)
--weight-update-endpoint WEIGHT_UPDATE_ENDPOINT
The endpoint url where the current weights can be
updated . Defaults to the value of environment
variable $USAGE_EXPORTER_WEIGHTS_UPDATE_ENDPOINT or
will be left blank (default: )
-s START, --start START
Beginning time of stats (YYYY-MM-DD). If set the value
of environment variable $USAGE_EXPORTER_START_DATE is
used. Uses maya for parsing. (default: 2019-01-30
15:29:32.363451)
used. Uses maya for parsing. (default: 2020-07-21
14:24:34.159480)
-i UPDATE_INTERVAL, --update-interval UPDATE_INTERVAL
Time to sleep between intervals, in case the calls
cause to much load on your openstack instance.
Defaults to the value of environment variable
$USAGE_EXPORTER_UPDATE_INTERVAL or 300 (in seconds)
(default: 300)
(default: 30)
-p PORT, --port PORT Port to provide metrics on (default: 8080)
GNU AGPLv3 @ tluettje
Expand All @@ -78,14 +126,14 @@ access to an OpenStack instance you can emulate running projects and machines wi
simple `toml` files. A few profiles are available inside the `/resources` folder.

```shell
pipenv run ./project_usage_exporter.py \
--dummy-data resources/dummy_machines.toml \
--update-interval 10 --domain
./project_usage_exporter.py \
-d resources/dummy_cc.toml -w resources/dummy_weights.toml \
--vcpu-weights "{2:1}" --mb-weights "{1024:1}" --domain --simple-vm-id 123realsimplevm
```
or
```
docker run -e USAGE_EXPORTER_DUMMY_FILE=/code/resources/dummy_machines.toml \
-e USAGE_EXPORTER_UPDATE_INTERVAL=10 \
docker run -e USAGE_EXPORTER_DUMMY_FILE=/code/resources/dummy_cc.toml \
-e USAGE_EXPORTER_DUMMY_WEIGHTS_FILE=/code/resources/dummy_weigths.toml \
-e USAGE_EXPORTER_PROJECT_DOMAINS= \
-p 8080:8080 tluettje/os_project_usage_exporter:v2
```
Expand Down
Loading

0 comments on commit c643753

Please sign in to comment.