Skip to content

Commit

Permalink
Fixed to write to file even if no PV's
Browse files Browse the repository at this point in the history
Signed-off-by: Kalle Fagerberg <[email protected]>
  • Loading branch information
applejag committed Oct 7, 2022
1 parent 9e55e2c commit 161b631
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions textfile_collector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ function collect_pv_utilization_metrics(){
done
}

collect_and_write_to_file() {
cap_metrics="$(collect_pv_capacity_metrics)"
util_metrics="$(collect_pv_utilization_metrics)"
write_to_file() {
cap_metrics="${1:-""}"
util_metrics="${2:-""}"

cat <<END > "${FILEPATH}"
# Prometheus metrics generated by monitor-pv at $(date)
Expand All @@ -49,7 +49,6 @@ ${cap_metrics}
# Utilization metrics
${util_metrics}
END

}

while true
Expand All @@ -72,7 +71,11 @@ do

if [[ ${#pv_list[@]} -ne 0 ]]; then
echo "PV List: ${pv_list[@]}"
collect_and_write_to_file
cap_metrics="$(collect_pv_capacity_metrics)"
util_metrics="$(collect_pv_utilization_metrics)"
write_to_file "$cap_metrics" "$util_metrics"
else
write_to_file "" ""
fi

sleep ${INTERVAL}
Expand Down

0 comments on commit 161b631

Please sign in to comment.