#!/usr/bin/env bash

set -euo pipefail

inode_utilization_threshold=${1:-90}

sudo find /var/cache/netdata -type f -mtime +30 -delete
sudo find /var/cache/netdata -type d -empty -delete
sudo find /host_tmp -type f -name 'netstats' -mtime +30 -delete
sudo find /host_tmp -type f -name 'shell_timings' -mtime +30 -delete
sudo find /host_tmp -type d -name 'netdata-charts*' -empty -delete

inode_utilization=$(df --inodes / | sed --expression /^Filesystem/d | awk '{print $5}' | sed --expression "s/\%//")

if (( ${inode_utilization} > ${inode_utilization_threshold} )); then
    echo "Warning: inode utilization at ${inode_utilization}"
    exit 1
fi
