Within how many blocks does a monster have to be close to my bed to trigger the warning?
http://www.minecraftwiki.net/wiki/Bed#Sleep_interruption
The system is much simpler since the full release — sleep is not allowed within 10 blocks of a hostile mob.
Quoted from the minecraft wiki. Hope this helps.
If a hostile mob is in the ten block radius you will not be allowed to sleep.