Skip to content

Commit 511a9ee

Browse files
authored
Merge pull request #7 from stackhpc/standalone-exporter
Standalone exporter
2 parents c21f1c6 + 7bd3e7f commit 511a9ee

File tree

5 files changed

+247
-150
lines changed

5 files changed

+247
-150
lines changed

.github/workflows/docker.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Docker image
2+
# Run the tasks on every push
3+
on: push
4+
jobs:
5+
build_push_api:
6+
name: Build and push execution environment
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Check out the repository
10+
uses: actions/checkout@v2
11+
12+
- name: Set up Docker Buildx
13+
uses: docker/setup-buildx-action@v1
14+
15+
- name: Set up Docker layer caching
16+
uses: actions/cache@v2
17+
with:
18+
path: /tmp/.buildx-cache
19+
key: ${{ runner.os }}-buildx-${{ github.sha }}
20+
restore-keys: |
21+
${{ runner.os }}-buildx-
22+
- name: Login to GitHub Container Registry
23+
uses: docker/login-action@v1
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Calculate metadata for image
30+
id: image-meta
31+
uses: docker/metadata-action@v3
32+
with:
33+
images: ghcr.io/stackhpc/os-capacity
34+
# Produce the branch name or tag and the SHA as tags
35+
tags: |
36+
type=ref,event=branch
37+
type=ref,event=tag
38+
type=sha,prefix=
39+
- name: Build and push image
40+
uses: docker/build-push-action@v2
41+
with:
42+
context: .
43+
push: true
44+
tags: ${{ steps.image-meta.outputs.tags }}
45+
labels: ${{ steps.image-meta.outputs.labels }}
46+
cache-from: type=local,src=/tmp/.buildx-cache
47+
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
48+
49+
# Temp fix
50+
# https://github.com/docker/build-push-action/issues/252
51+
# https://github.com/moby/buildkit/issues/1896
52+
# https://github.com/docker/buildx/pull/535
53+
- name: Move cache
54+
run: |
55+
rm -rf /tmp/.buildx-cache
56+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM ubuntu:22.04
2+
3+
RUN apt-get update && apt-get upgrade -y && apt-get install python3-pip tini -y && apt-get clean
4+
5+
COPY ./requirements.txt /opt/os-capacity/requirements.txt
6+
RUN pip install -U -r /opt/os-capacity/requirements.txt
7+
8+
COPY ./os_capacity/prometheus.py /opt/os-capacity/prometheus.py
9+
ENTRYPOINT ["tini", "--"]
10+
CMD ["python3", "/opt/os-capacity/prometheus.py"]

README.rst

Lines changed: 14 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ os-capacity
33

44
This is a prototype tool to extract capacity information.
55

6-
.. note::
7-
8-
This is currently quite specific to Ironic powered OpenStack Nova clouds.
9-
106
Install
117
-------
128

@@ -21,139 +17,28 @@ Now lets get that installed inside a virtual environment:
2117

2218
.. code::
2319
24-
virtualenv .venv-test
25-
source .venv-test/bin/activate
20+
python3 -m virtualenv .venv
21+
source .venv/bin/activate
2622
pip install -U .
2723
2824
Prometheus Exporter
2925
-------------------
3026

31-
Assuming you have clouds.yaml in the right place and OS_CLOUD set:
32-
33-
.. code::
34-
35-
./os_capacity/prometheus.py
36-
openstack_total_capacity_per_flavor{flavor="small"} 1
37-
openstack_capacity_by_hostname{hypervisor="aio",flavor="small"} 1
38-
39-
40-
TODOs we need support for:
41-
42-
* add request filter support for require_tenant_aggregate,
43-
map_az_to_placement_aggregate and compute_status_filter
44-
45-
Configuration
46-
-------------
47-
48-
The easiest way to configure this is to populate a typical OpenStack RC file:
49-
50-
.. code::
51-
52-
cat > .openrc <<EOF
53-
export OS_AUTH_URL=http://keystone.example.com:5000/v3
54-
export OS_PROJECT_ID=
55-
export OS_PROJECT_NAME=
56-
export OS_USER_DOMAIN_NAME=
57-
export OS_PROJECT_DOMAIN_NAME=
58-
export OS_USERNAME=
59-
export OS_REGION_NAME=
60-
export OS_INTERFACE=
61-
export OS_IDENTITY_API_VERSION=3
62-
export OS_AUTH_PLUGIN=v3password
63-
echo "Please enter your OpenStack Password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
64-
read -sr OS_PASSWORD_INPUT
65-
export OS_PASSWORD=$OS_PASSWORD_INPUT
66-
EOF
67-
68-
source .openrc
69-
70-
Some openrc files don't contain the OS_AUTH_PLUGIN and OS_PROJECT_DOMAIN_NAME
71-
variables, but os-capacity requires that those are set.
72-
73-
Usage
74-
-----
75-
76-
When opening a new terminal, first activate the venv and the configuration:
77-
78-
.. code::
79-
80-
source .venv-test/bin/activate
81-
source .openrc
82-
83-
84-
You can do things like list all flavors:
85-
86-
.. code::
87-
88-
(.venv-test) $ os-capacity flavor list
89-
+--------------------------------------+-------------+-------+--------+---------+
90-
| UUID | Name | VCPUs | RAM MB | DISK GB |
91-
+--------------------------------------+-------------+-------+--------+---------+
92-
| 2622d978-7072-484d-8c7a-144a308c2709 | my-flavor-1 | 1 | 512 | 20 |
93-
| 45de641c-950e-434b-9c2e-6f76b120f85c | my-flavor-2 | 2 | 1024 | 40 |
94-
+--------------------------------------+-------------+-------+--------+---------+
95-
96-
If you want to see all the REST API calls made, use the verbose flag, and you
97-
can also get the output in json format by adding the format flag:
98-
99-
.. code::
100-
101-
(.venv-test) $ os-capacity -v flavor list -f json
102-
103-
You can look at all the different types of resources and amount used:
104-
105-
.. code::
106-
107-
(.venv-test) $ os-capacity resources group
108-
+----------------------------------+-------+------+------+-------------+
109-
| Resource Class Groups | Total | Used | Free | Flavors |
110-
+----------------------------------+-------+------+------+-------------+
111-
| VCPU:1,MEMORY_MB:512,DISK_GB:20 | 5 | 1 | 4 | my-flavor-1 |
112-
| VCPU:2,MEMORY_MB:1024,DISK_GB:40 | 2 | 0 | 2 | my-flavor-2 |
113-
+----------------------------------+-------+------+------+-------------+
114-
115-
116-
You can also look at the usage grouped by project or user or total usage:
117-
118-
.. code::
119-
120-
(.venv-test) $ os-capacity usages group user --max-width 70
121-
+----------------------+----------------------+----------------------+
122-
| User | Current Usage | Usage Days |
123-
+----------------------+----------------------+----------------------+
124-
| 1e6abb726dd04d4eb4b8 | Count:4, | Count:410, |
125-
| 94e19c397d5e | DISK_GB:1484, | DISK_GB:152110, |
126-
| | MEMORY_MB:524288, | MEMORY_MB:53739520, |
127-
| | VCPU:256 | VCPU:26240 |
128-
| 4661c3e5f2804696ba26 | Count:1, | Count:3, |
129-
| 56b50dbd0f3d | DISK_GB:371, | DISK_GB:1113, |
130-
| | MEMORY_MB:131072, | MEMORY_MB:393216, |
131-
| | VCPU:64 | VCPU:192 |
132-
+----------------------+----------------------+----------------------+
133-
134-
See the online help for more details:
27+
Assuming you have clouds.yaml in the right place,
28+
you can run the exporter doing something like this:
13529

13630
.. code::
13731
138-
os-capacity help
139-
usage: os-capacity [--version] [-v | -q] [--log-file LOG_FILE] [-h] [--debug]
32+
export OS_CLIENT_CONFIG_FILE=myappcred.yaml
33+
export OS_CLOUD=openstack
14034
141-
OS-Capacity (StackHPC) Command Line Interface (CLI)
35+
./os_capacity/prometheus.py &
36+
curl localhost:9000 > mytestrun
37+
cat mytestrun
14238
143-
optional arguments:
144-
--version show program's version number and exit
145-
-v, --verbose Increase verbosity of output. Can be repeated.
146-
-q, --quiet Suppress output except warnings and errors.
147-
--log-file LOG_FILE Specify a file to log output. Disabled by default.
148-
-h, --help Show help message and exit.
149-
--debug Show tracebacks on errors.
39+
Or just run via docker or similar:::
15040

151-
Commands:
152-
complete print bash completion command
153-
flavor list List all the flavors.
154-
help print detailed help for another command
155-
prometheus To be run as node exporter textfile collector
156-
resources all List all resource providers, with their resources and servers.
157-
resources group Lists counts of resource providers with similar inventories.
158-
usages all List all current resource usages.
159-
usages group Group usage by specified key (by user or project).
41+
docker run -d --name os_capacity \
42+
--mount type=bind,source=/etc/openstack/,target=/etc/openstack/ \
43+
--env OS_CLOUD=openstack --env OS_CLIENT_CONFIG_FILE=/etc/openstack/mycloud.yaml \
44+
-p 9000:9000 ghcr.io/stackhpc/os-capacity:master

0 commit comments

Comments
 (0)