#!/usr/bin/env bash
# fd_check.sh — open file descriptor usage ratio.
set -euo pipefail

FD_PCT=0
if [ -r /proc/sys/fs/file-nr ]; then
  read -r ALLOC _ LIMIT < /proc/sys/fs/file-nr
  if [ "$LIMIT" -gt 0 ]; then
    FD_PCT=$(awk "BEGIN {printf \"%.1f\", $ALLOC*100/$LIMIT}")
  fi
fi

echo "{\"health\":\"healthy\",\"metrics\":{\"fd_pct\":$FD_PCT}}"
