I would use dcraw and ImageMagick, as I am most familiar with those tools. Windows BAT script:
%DCRAW% -d -D -t 0 -o 0 -h -4 AGA_3443.NEF
%IMG7%magick AGA_3443.ppm -alpha off -separate +append -threshold 16382 -format %%[fx:mean] info:
This returns a floating-point number, such as “0.0170776”. This is the proportion of pixel values that are greater than 16382. My camera (Nikon D800) records a maximum value of 16383. So this image has nearly 2% of the values at the maximum, which is more than I usually accept.