Filter for Spectrum Analyzer
Buying a mains isolation transformer is definitely one of the first things you should get when doing this type of testing. My though would be that you could measure the spectral density by measuring the total harmonic distortion (THD) of the current. This will give you spectral content where you want to see all the content mains frequency (ideal situation).

All about circuits has a decent enough article to get you thinking about these topics.

https://www.allaboutcircuits.com/technical-articles/understanding-thd-total-harmonic-distortion-in-power-systems/

You could use a current transformer for mains current measurements, rectify the signal, and then do some digital signal processing (fast fourier transform) to get the harmonic content. This approach would keep your controller isolated from main since you'd be using a current transformer.