Skip to content

Commit 958797e

Browse files
authored
Add pvc name in metrics (#10)
Signed-off-by: Sumit Lalwani <[email protected]>
1 parent 2d1e613 commit 958797e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

textfile_collector.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ function collect_pv_capacity_metrics(){
3737

3838
for i in ${pv_list[@]}
3939
do
40+
pvc_name=$(kubectl get pv ${i} -o custom-columns=:spec.claimRef.name --no-headers | tr '[:upper:]' '[:lower:]')
4041
size_in_spec=$(kubectl get pv ${i} -o custom-columns=:spec.capacity.storage --no-headers | tr '[:upper:]' '[:lower:]')
4142
size_in_bytes=$(calculate_pv_capacity ${size_in_spec};)
42-
echo "pv_capacity_bytes{persistentvolume=\"${i}\"} ${size_in_bytes}" >> ${FILEPATH}/pv_size.prom
43+
echo "pv_capacity_bytes{persistentvolume=\"${i}\",persistentvolumeclaim=\"${pvc_name}\"} ${size_in_bytes}" >> ${FILEPATH}/pv_size.prom
4344
done
4445
}
4546

@@ -65,7 +66,8 @@ function collect_pv_utilization_metrics(){
6566
mount_data=$(du -sb ${i})
6667
utilization=$(echo ${mount_data}| cut -d " " -f 1)
6768
pv_name=$(basename $(echo ${mount_data} | cut -d " " -f 2))
68-
echo "pv_utilization_bytes{persistentvolume=\"${pv_name}\"} ${utilization}" >> ${FILEPATH}/pv_used.prom
69+
pvc_name=$(kubectl get pv ${pv_name} -o custom-columns=:spec.claimRef.name --no-headers | tr '[:upper:]' '[:lower:]')
70+
echo "pv_utilization_bytes{persistentvolume=\"${pv_name}\",persistentvolumeclaim=\"${pvc_name}\"} ${utilization}" >> ${FILEPATH}/pv_used.prom
6971
done
7072
}
7173

0 commit comments

Comments
 (0)