Skip to content

Commit 16e947f

Browse files
committed
python 2.7 to 3.8
1 parent 5987045 commit 16e947f

File tree

6 files changed

+385
-294
lines changed

6 files changed

+385
-294
lines changed

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
FROM alpine:latest
1+
FROM alpine:3.11
22
RUN apk update
3-
RUN apk add python py-pip
3+
RUN apk add python3
44
RUN apk add curl iputils
5-
RUN pip install prometheus_client requests pyyaml retrying
5+
COPY pip_requirements.txt .
6+
RUN pip3 install -r pip_requirements.txt
67
COPY version/VERSION /exporter/
78
COPY exporter.py /exporter/
89
COPY metrics.json /exporter/
@@ -11,4 +12,4 @@ RUN ln -sf /dev/stdout /exporter/exporter.log
1112
USER nobody
1213

1314

14-
ENTRYPOINT ["python", "/exporter/exporter.py" ]
15+
ENTRYPOINT ["python3", "/exporter/exporter.py" ]

Dockerfile_rhel

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
1-
FROM registry.redhat.io/rhel7
1+
# This is an intermediate image
2+
FROM registry.redhat.io/rhel8/python-38 as base
3+
4+
COPY version/VERSION /exporter/
5+
COPY exporter.py /exporter/
6+
COPY metrics.json /exporter/
7+
8+
# Using Red Hat Universal Base Image 8
9+
# This is final shipping image
10+
FROM registry.redhat.io/ubi8
11+
12+
ARG VER
13+
### Required Atomic/OpenShift Labels - https://github.com/projectatomic/ContainerApplicationGenericLabels
14+
LABEL name="Citrix ADC Metric Exporter" \
15+
maintainer="[email protected]" \
16+
vendor="Citrix" \
17+
version=${VER} \
18+
summary="Citrix provides an metrics exporter for Citrix ADC MPX (hardware), Citrix ADC VPX (virtualized), Citrix ADC CPX (containerized) and Citrix ADC BLX (Bare Metal) for on-prem and cloud deployments. It is is a simple server that scrapes Citrix ADC stats and exports them via HTTP to Prometheus." \
19+
description="Citrix provides an metrics exporter for Citrix ADC MPX (hardware), Citrix ADC VPX (virtualized), Citrix ADC CPX (containerized) and Citrix ADC BLX (Bare Metal) for on-prem and cloud deployments. It is is a simple server that scrapes Citrix ADC stats and exports them via HTTP to Prometheus."
20+
21+
#### add licenses to this directory
22+
COPY license/LICENSE /licenses/
23+
24+
# Make bash the default shell
25+
SHELL ["/bin/bash", "-c"]
26+
27+
# RHEL 8 requires a subscription. Use --build-arg USERNAME=<RHEL_USERNAME> --build-arg PASSWORD=<RHEL_PASSWORD> for these arguments.
228
ARG USERNAME
329
ARG PASSWORD
430
RUN subscription-manager register --username ${USERNAME} --password ${PASSWORD} --auto-attach
5-
RUN subscription-manager repos --enable rhel-7-server-optional-rpms --enable rhel-7-server-extras-rpms --enable rhel-server-rhscl-7-rpms
31+
632
RUN yum -y update \
7-
&& yum -y install python27-python-pip \
8-
&& yum clean all \
9-
&& scl enable python27 bash
10-
ENV PATH /opt/rh/python27/root/usr/bin:$PATH
11-
ENV LD_LIBRARY_PATH /opt/rh/python27/root/usr/lib64
12-
RUN pip install prometheus_client requests pyyaml
13-
COPY version/VERSION /exporter/
14-
COPY exporter.py /exporter/
15-
COPY metrics.json /exporter/
33+
&& yum -y install python38 \
34+
&& alternatives --set python /usr/bin/python3 \
35+
&& dnf install -y python3-pip \
36+
&& yum clean all
37+
38+
# Removing subscription from image as private RHEL credential was used for the subscription.
39+
RUN subscription-manager unregister
40+
COPY --from=base /opt/app-root/lib/python3.8/site-packages/ /usr/lib/python3.8/site-packages/
41+
COPY --from=base /usr/lib64/libpython* /usr/local/lib/
42+
COPY --from=base /exporter /exporter/
1643
RUN touch /exporter/exporter.log
1744
RUN ln -sf /dev/stdout /exporter/exporter.log
18-
USER nobody
45+
COPY ./pip_requirements.txt .
46+
RUN python3.8 -m pip install -r pip_requirements.txt
1947

48+
# Starting CIC as nobody
49+
USER nobody
2050

21-
ENTRYPOINT ["python", "/exporter/exporter.py" ]
51+
ENTRYPOINT ["python3.8", "/exporter/exporter.py"]

README.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ The exporter can be run as a standalone python script, built into a container or
2828
<summary>Usage as a Python Script</summary>
2929
<br>
3030

31-
To use the exporter as a python script, the ```prometheus_client``` and ```requests``` package needs to be installed. This can be done using
31+
To use the exporter as a python3 script, few packages needs to be installed. This can be done using
3232
```
33-
pip install prometheus_client
34-
pip install requests
35-
pip install PyYAML
36-
pip install retrying
33+
pip3 install -r pip_requirements.txt
3734
```
35+
Contents of requirements.txt
36+
37+
```
38+
prometheus-client==0.8.0
39+
requests==2.23.0
40+
PyYAML==5.3.1
41+
tenacity==6.2.0
42+
urllib3==1.25.9
43+
```
44+
3845
Now, create a folder ```/exporter``` and copy the ```metrics.json``` file to the folder.
3946
Finally, the exporter can be run as a python script using;
4047
```
@@ -49,10 +56,10 @@ flag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
4956
--metric | Provide a specific metric to load from metrics.json file (eg: 'lbvserver', 'protocolhttp', etc). If not provided, all metric entities from metrics.json will be loaded
5057
--secure | Ensures HTTPS connection to ADC. Option 'no'(HTTP) can be provided to collect metrics from Citrix ADC. Default: 'yes'.
5158
--start-delay | Specify time for which exporter should sleep before starting metric collection. Default: 10s
52-
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADCs. Default: 15s
59+
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADCs. Default: 10s
5360
--metrics-file | The location of metrics.json file. Default: /exporter/metrics.json
5461
--log-file | The location of exporter.log file. Default: /exporter/exporter.log
55-
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: DEBUG
62+
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: INFO
5663
--config-file | File with configs such as ```username```, ```password```, ```validate-cert```, ```cacert-path```, etc. Helps supply username and password through file rather than CLI.
5764
--validate-cert. | Specify if ca certifcate is to be validated to access Citrix ADC. Default: 'no'. Valid value: 'yes'
5865
--cacert-path. | Provide valid cert path if "-validate-cert" set to 'yes'. cert path will only be considered if '--validate-cert' is set to 'yes'.
@@ -91,15 +98,15 @@ For this:
9198
<summary>Usage as a Container</summary>
9299
<br>
93100

94-
In order to use the exporter as a container, the image ```quay.io/citrix/citrix-adc-metrics-exporter:1.4.4``` will need to be pulled using;
101+
In order to use the exporter as a container, the image ```quay.io/citrix/citrix-adc-metrics-exporter:1.4.5``` will need to be pulled using;
95102
```
96-
docker pull quay.io/citrix/citrix-adc-metrics-exporter:1.4.4
103+
docker pull quay.io/citrix/citrix-adc-metrics-exporter:1.4.5
97104
```
98105
**NOTE:** It can also be build locally using ```docker build -f Dockerfile -t <image_name>:<tag> ./```
99106

100107
Now, the exporter can be run using:
101108
```
102-
docker run -dt -p <host_port>:<container_port> --mount type=bind,source=<host-path-for-config-file>,target=/exporter/config.yaml quay.io/citrix/citrix-adc-metrics-exporter:1.4.4 [flags] --config-file=/exporter/config.yaml
109+
docker run -dt -p <host_port>:<container_port> --mount type=bind,source=<host-path-for-config-file>,target=/exporter/config.yaml quay.io/citrix/citrix-adc-metrics-exporter:1.4.5 [flags] --config-file=/exporter/config.yaml
103110
```
104111
where the flags are:
105112

@@ -110,10 +117,10 @@ flag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
110117
--metric | Provide a specific metric to load from metrics.json file (eg: 'lbvserver', 'protocolhttp', etc). If not provided, all metric entities from metrics.json will be loaded
111118
--secure | Ensures HTTPS connection to ADC. Option 'no'(HTTP) can be provided to collect metrics from Citrix ADC. Default: 'yes'.
112119
--start-delay | Specify time for which exporter should sleep before starting metric collection. Default: 10s
113-
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADC. Default: 15s
120+
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADC. Default: 10s
114121
--metrics-file | The location of metrics.json file. Default: /exporter/metrics.json
115122
--log-file | The location of exporter.log file. Default: /exporter/exporter.log
116-
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: DEBUG
123+
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: INFO
117124
--config-file | File with configs such as ```username```, ```password```, ```validate-cert``, ```cacert-path```, etc. Helps supply username and password through file rather than CLI for secure deployment.
118125
--validate-cert | Specify if ca certifcate is to be validated to access Citrix ADC. Default: 'no'. Valid value: 'yes'
119126
--cacert-path | Provide valid cert path if "--validate-cert" set to 'yes'. cert path will only be considered if '--validate-cert' is set to 'yes'.
@@ -122,7 +129,7 @@ flag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
122129

123130
To setup the exporter as given in the diagram, the following command can be used:
124131
```
125-
docker run -dt -p 8888:8888 --mount type=bind,source=/path/to/config.yaml,target=/exporter/config.yaml --name citrix-adc-exporter quay.io/citrix/citrix-adc-metrics-exporter:1.4.4 --target-nsip=10.0.0.1 --port=8888 --config-file=/exporter/config.yaml
132+
docker run -dt -p 8888:8888 --mount type=bind,source=/path/to/config.yaml,target=/exporter/config.yaml --name citrix-adc-exporter quay.io/citrix/citrix-adc-metrics-exporter:1.4.5 --target-nsip=10.0.0.1 --port=8888 --config-file=/exporter/config.yaml
126133
```
127134
This directs the exporter container to scrape the 10.0.0.1 IP, and the expose the stats it collects on port 8888.
128135

@@ -149,7 +156,7 @@ For this:
149156
Certificate should then be mounted at the '--cacert-path' provided. For instance, if cert is 'cacert.pem' and '--cacert-path' provided in 'config.yaml' is '/exporter/cacert.pem'
150157

151158
```
152-
docker run -dt -p 8888:8888 --mount type=bind,source=/path/to/config.yaml,target=/exporter/config.yaml --mount type=bind,source=/path/to/cacert.pem,target=/exporter/cacert.pem --name citrix-adc-exporter quay.io/citrix/citrix-adc-metrics-exporter:1.4.4 --target-nsip=10.0.0.1 --port=8888 --config-file=/exporter/config.yaml
159+
docker run -dt -p 8888:8888 --mount type=bind,source=/path/to/config.yaml,target=/exporter/config.yaml --mount type=bind,source=/path/to/cacert.pem,target=/exporter/cacert.pem --name citrix-adc-exporter quay.io/citrix/citrix-adc-metrics-exporter:1.4.5 --target-nsip=10.0.0.1 --port=8888 --config-file=/exporter/config.yaml
153160
```
154161
Cert validation options can also be provided using environment variables using NS_VALIDATE_CERT, NS_CACERT_PATH. Thoughconfig file input is the preferred method.
155162

@@ -178,7 +185,7 @@ metadata:
178185
spec:
179186
containers:
180187
- name: exporter
181-
image: quay.io/citrix/citrix-adc-metrics-exporter:1.4.4
188+
image: quay.io/citrix/citrix-adc-metrics-exporter:1.4.5
182189
args:
183190
- "--target-nsip=10.0.0.1"
184191
- "--port=8888"
@@ -221,10 +228,10 @@ flag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs
221228
--metric | Provide a specific metric to load from metrics.json file (eg: 'lbvserver', 'protocolhttp', etc). If not provided, all metric entities from metrics.json will be loaded
222229
--secure | Ensures HTTPS connection to ADC. Option 'no'(HTTP) can be provided to collect metrics from Citrix ADC. Default: 'yes'.
223230
--start-delay | Specify time for which exporter should sleep before starting metric collection. Default: 10s
224-
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADC. Default: 15s
231+
--timeout | Specify timeout period for exporter to obtain response from target Citrix ADC. Default: 10s
225232
--metrics-file | The location of metrics.json file. Default: /exporter/metrics.json
226233
--log-file | The location of exporter.log file. Default: /exporter/exporter.log
227-
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: DEBUG
234+
--log-level | The level of logging. DEBUG, INFO, WARNING, ERROR or CRITICAL Default: INFO
228235
--config-file | File with configs such as ```username```, ```password```, ```validate-cert```, ```cacert-path```, etc. Helps supply username and password through file rather than CLI.
229236
--validate-cert | Specify if ca certifcate is to be validated to access Citrix ADC. Default: 'no'. Valid value: 'yes'
230237
--cacert-path | Provide valid cert path if "--validate-cert" set to 'yes'. cert path will only be considered if '--validate-cert' is set to 'yes'.
@@ -255,7 +262,7 @@ metadata:
255262
spec:
256263
containers:
257264
- name: exporter
258-
image: quay.io/citrix/citrix-adc-metrics-exporter:1.4.4
265+
image: quay.io/citrix/citrix-adc-metrics-exporter:1.4.5
259266
args:
260267
- "--target-nsip=10.0.0.1"
261268
- "--port=8888"

0 commit comments

Comments
 (0)