Skip to content
This repository was archived by the owner on May 2, 2023. It is now read-only.

Commit 31a5a5a

Browse files
committed
Modified both FA and FB collectors to handle wrong endpoint.
Resolved Issue #26. Included metrics for FA Pods and Volumes pending for eradication
2 parents 6c7fce9 + f66f585 commit 31a5a5a

File tree

12 files changed

+63
-49
lines changed

12 files changed

+63
-49
lines changed

Dockerfile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
FROM python:3.6-alpine
1+
FROM python:3.9-alpine
22

33
# Application directory
44
WORKDIR /app
5-
COPY pure_exporter.py /app
6-
COPY requirements.txt /app
5+
COPY pure_exporter.py requirements.txt /app/
76
COPY flasharray_collector /app/flasharray_collector
87
COPY flashblade_collector /app/flashblade_collector
98

109
# Install dependencies and WSGI server
1110
RUN pip install --upgrade pip && \
1211
pip install --no-cache-dir --upgrade requests && \
13-
pip install --no-cache-dir -r requirements.txt && \
14-
pip install --no-cache-dir gunicorn
12+
pip install --no-cache-dir -r requirements.txt
1513

1614
# Run as non-root user
1715
RUN addgroup -S app && adduser -S -G app app

Dockerfile.fa

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
FROM python:3.6-alpine
1+
FROM python:3.9-alpine
22

33
# Application directory
44
WORKDIR /app
5-
COPY pure_fa_exporter.py /app
6-
COPY requirements.fa.txt /app
7-
COPY ./flasharray_collector /app/flasharray_collector
5+
COPY pure_fa_exporter.py requirements.fa.txt /app/
6+
COPY flasharray_collector /app/flasharray_collector
87

98
# Install dependencies and WSGI server
109
RUN pip install --upgrade pip && \
1110
pip install --no-cache-dir --upgrade requests && \
12-
pip install --no-cache-dir -r requirements.fa.txt && \
13-
pip install --no-cache-dir gunicorn
11+
pip install --no-cache-dir -r requirements.fa.txt
1412

1513
# Run as non-root user
1614
RUN addgroup -S app && adduser -S -G app app

Dockerfile.fb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
FROM python:3.6-alpine
1+
FROM python:3.9-alpine
22

33
# Application directory
44
WORKDIR /app
5-
COPY pure_fb_exporter.py /app
6-
COPY requirements.fb.txt /app
5+
COPY pure_fb_exporter.py requirements.fb.txt /app/
76
COPY flashblade_collector /app/flashblade_collector
87

98
# Install dependencies and WSGI server
109
RUN pip install --upgrade pip && \
1110
pip install --no-cache-dir --upgrade requests && \
12-
pip install --no-cache-dir -r requirements.fb.txt && \
13-
pip install --no-cache-dir gunicorn
11+
pip install --no-cache-dir -r requirements.fb.txt
1412

1513
# Run as non-root user
1614
RUN addgroup -S app && adduser -S -G app app

flasharray_collector/flasharray_collector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ class FlasharrayCollector():
2626
:type api_token: str
2727
"""
2828
def __init__(self, endpoint, api_token, request = 'all'):
29-
# self.fb = PurityFb(endpoint, conn_timeo=ctimeo, read_timeo=rtimeo, retries=retries)
30-
self.fa = FlashArray(endpoint, api_token)
29+
self.fa = None
30+
try:
31+
self.fa = FlashArray(endpoint, api_token)
32+
except Exception as e:
33+
raise Exception('Connection for FlashArray {} not initialized. Check array name/address and api-token'.format(endpoint))
3134
self.request = request
3235

3336
def collect(self):

flasharray_collector/flasharray_metrics/flasharray.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,31 @@
88

99
PURE_NAA = 'naa.624a9370'
1010

11-
kpi_params = [{'action': 'monitor'},
12-
{'action': 'monitor', 'mirrored': True},
13-
{'action': 'monitor', 'latency': True},
14-
{'action': 'monitor', 'latency': True, 'mirrored': True},
15-
{'action': 'monitor', 'size': True},
16-
{'action': 'monitor', 'size': True, 'mirrored': True},
17-
{'space': True}]
11+
base_kpi_params = [{'action': 'monitor'},
12+
{'action': 'monitor', 'mirrored': True},
13+
{'action': 'monitor', 'latency': True},
14+
{'action': 'monitor', 'latency': True, 'mirrored': True},
15+
{'action': 'monitor', 'size': True},
16+
{'action': 'monitor', 'size': True, 'mirrored': True}]
17+
18+
comm_kpi_params = base_kpi_params + [{'space': True, 'pending': True}]
19+
20+
host_kpi_params = base_kpi_params + [{'space': True}]
21+
1822

1923
class FlashArray:
2024
"""
2125
Base class for FlashArray Prometheus array info
2226
"""
2327
def __init__(self, endpoint, api_token):
24-
self.flasharray = purestorage.FlashArray(
25-
endpoint,
26-
api_token=api_token,
27-
user_agent='Purity_FA_Prometheus_exporter/1.0')
28+
self.flasharray = None
29+
try:
30+
self.flasharray = purestorage.FlashArray(
31+
endpoint,
32+
api_token=api_token,
33+
user_agent='Purity_FA_Prometheus_exporter/1.0')
34+
except purestorage.PureError:
35+
pass
2836

2937
self.array = None
3038
self.hosts = None
@@ -40,7 +48,7 @@ def get_array(self):
4048
return self.array
4149
self.array = self.flasharray.get()
4250

43-
for params in kpi_params:
51+
for params in comm_kpi_params:
4452
try:
4553
a = self.flasharray.get(**params)[0]
4654
self.array.update(a)
@@ -65,7 +73,7 @@ def get_volumes(self):
6573
if self.volumes is not None:
6674
return self.volumes
6775
vdict = {}
68-
for v in self.flasharray.list_volumes():
76+
for v in self.flasharray.list_volumes(pending='true'):
6977
v['naaid'] = PURE_NAA + v['serial']
7078
vdict[v['name']] = v
7179
try:
@@ -81,12 +89,13 @@ def get_volumes(self):
8189
except purestorage.PureError:
8290
pass
8391

84-
for params in kpi_params:
92+
for params in comm_kpi_params:
8593
try:
8694
for v in self.flasharray.list_volumes(**params):
8795
vdict[v['name']].update(v)
8896
except purestorage.PureError:
8997
pass
98+
# vdict = {key:val for key, val in vdict.items() if val['time_remaining'] is None}
9099
self.volumes = list(vdict.values())
91100
return self.volumes
92101

@@ -100,7 +109,7 @@ def get_hosts(self):
100109
except purestorage.PureError:
101110
pass
102111

103-
for params in kpi_params:
112+
for params in host_kpi_params:
104113
try:
105114
for h in self.flasharray.list_hosts(**params):
106115
hdict[h['name']].update(h)
@@ -114,16 +123,17 @@ def get_pods(self):
114123
return self.pods
115124
pdict = {}
116125
try:
117-
for p in self.flasharray.list_pods():
126+
for p in self.flasharray.list_pods(pending='true'):
118127
pdict[p['name']] = p
119128
except purestorage.PureError:
120129
pass
121130

122-
for params in kpi_params:
131+
for params in comm_kpi_params:
123132
try:
124133
for p in self.flasharray.list_pods(**params):
125134
pdict[p['name']].update(p)
126135
except purestorage.PureError:
127136
pass
137+
# pdict = {key:val for key, val in pdict.items() if val['time_remaining'] is None}
128138
self.pods = list(pdict.values())
129139
return self.pods

flashblade_collector/flashblade_collector.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ class FlashbladeCollector():
2929
:type api_token: str
3030
"""
3131
def __init__(self, endpoint, api_token, request='all'):
32-
# self.fb = PurityFb(endpoint, conn_timeo=ctimeo, read_timeo=rtimeo,
33-
# retries=retries)
34-
self.fb = FlashBlade(endpoint, api_token)
32+
self.fb = None
33+
try:
34+
self.fb = FlashBlade(endpoint, api_token)
35+
except Exception as e:
36+
raise Exception('Connection with FlashBlade {} not initialized. Check array name/address and api-token'.format(endpoint))
3537
self.request = request
3638

3739
def collect(self):

flashblade_collector/flashblade_metrics/buckets_replica_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def _replica_links(self):
2929
l.remote.name,
3030
l.remote_bucket.name,
3131
l.remote_credentials.name,
32-
l.status], l.lag)
32+
l.status], -1 if l.lag is None else l.lag)
3333

3434
def get_metrics(self):
3535
self._replica_links()

flashblade_collector/flashblade_metrics/filesystems_replica_metrics.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class FilesystemsReplicaMetrics():
77
"""
88
def __init__(self, fb):
99
self.fb = fb
10-
self.replica_links_lag = GaugeMetricFamily('purefb_bucket_filesystems_links_lag_msec',
11-
'FlashBlade bucket filesystem links lag',
10+
self.replica_links_lag = GaugeMetricFamily('purefb_filesystems_links_lag_msec',
11+
'FlashBlade filesystem links lag',
1212
labels=['name', 'direction', 'remote_name',
1313
'remote_filesystem_name', 'status'])
1414

@@ -23,7 +23,7 @@ def _replica_links_lag(self):
2323
f.direction,
2424
f.remote.name,
2525
f.remote_file_system.name,
26-
f.status], f.lag)
26+
f.status], -1 if f.lag is None else f.lag)
2727

2828
def get_metrics(self):
2929
self._replica_links_lag()

flashblade_collector/flashblade_metrics/flashblade.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ class FlashBlade():
1111
Base class for FlashBlade Prometheus array info
1212
"""
1313
def __init__(self, endpoint, api_token):
14-
# self.fb = PurityFb(endpoint, conn_timeo=ctimeo, read_timeo=rtimeo,
15-
# retries=retries)
16-
self.flashblade = PurityFb(host=endpoint)
17-
self.flashblade.disable_verify_ssl()
18-
self.flashblade._api_client.user_agent = 'Purity_FB_Prometheus_exporter/1.0'
19-
self.flashblade.request_timeout = urllib3.Timeout(connect=2.0, read=60.0)
20-
self.flashblade.login(api_token)
14+
self.flashblade = None
15+
try:
16+
self.flashblade = PurityFb(host=endpoint)
17+
self.flashblade.disable_verify_ssl()
18+
self.flashblade._api_client.user_agent = 'Purity_FB_Prometheus_exporter/1.0'
19+
self.flashblade.request_timeout = urllib3.Timeout(connect=2.0, read=60.0)
20+
self.flashblade.login(api_token)
21+
except Exceprion:
22+
pass
2123
self.filesystems = []
2224
self.buckets = []
2325
self.array_performance = {}

requirements.fa.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Flask>=1.1.2
22
prometheus-client>=0.7.1
33
purestorage>=1.19
44
urllib3>=1.25.10
5+
gunicorn>=20.1.0

0 commit comments

Comments
 (0)