Skip to content

Commit 373180e

Browse files
ksatchitKiran Mova
authored andcommitted
(enhancement)collections: filter PVs by provisioner
Signed-off-by: ksatchit <[email protected]>
1 parent 958797e commit 373180e

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

node-exporter-pv-metrics.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ spec:
6565
value: /shared_vol
6666
- name: COLLECT_INTERVAL
6767
value: "10"
68+
- name: PROVISIONER_WHITELIST
69+
value: "openebs.io/provisioner-iscsi,openebs.io/local"
6870
command:
6971
- /bin/bash
7072
args:

textfile_collector.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
FILEPATH=${TEXTFILE_PATH:=/shared_vol}
44
INTERVAL=${COLLECT_INTERVAL:=10}
5+
PROVISIONERS=${PROVISIONER_WHITELIST:=openebs.io/local}
56

67
## calculate_pv_capacity obtains the size of a PV in bytes
78
function calculate_pv_capacity(){
@@ -73,16 +74,27 @@ function collect_pv_utilization_metrics(){
7374

7475
while true
7576
do
77+
provisioner_list=$(echo ${PROVISIONERS} | tr ',' ' ')
7678
declare -a pv_list=()
7779

7880
## Select only those PVs that are bound. Several stale PVs can exist.
7981
for i in $(kubectl get pv -o jsonpath='{.items[?(@.status.phase=="Bound")].metadata.name}')
8082
do
81-
pv_list+=(${i})
83+
## Select only those PVs that are provisioned by the whitelisted provisioners
84+
## Nested conditions in jsonpath filters are not supported yet. Ref: https://github.com/kubernetes/kubernetes/issues/20352
85+
if [[ ${provisioner_list} =~ $(kubectl get pv ${i} -o jsonpath='{.metadata.annotations.pv\.kubernetes\.io/provisioned-by}') ]]
86+
then
87+
pv_list+=(${i})
88+
fi
8289
done
8390

84-
echo "pv_list: ${pv_list[@]}"
85-
collect_pv_capacity_metrics;
86-
collect_pv_utilization_metrics;
91+
echo "No. of PVs by specified provisioners: ${#pv_list[@]}"
92+
93+
if [[ ${#pv_list[@]} -ne 0 ]]; then
94+
echo "PV List: ${pv_list[@]}"
95+
collect_pv_capacity_metrics;
96+
collect_pv_utilization_metrics;
97+
fi
98+
8799
sleep ${INTERVAL}
88100
done

0 commit comments

Comments
 (0)