Dr Michael Mosley has written about this non-sleeping problem. He suggested a "ritual" could help. I follow this by making lists that I repeat nightly. I started with simple subjects like fruit and flowers and listed them alphabetically. Bored, I chose other subjects and I now list, not alphabetically, 40 detectives in fiction (books and TV) . I find this makes my little grey cells work and, hopefully, helps me retain my memory.
I also spray magnesium oil on my feet and calves to try and prevent cramp. Magnesium helps one sleep and, touch wood, I don't get that awful cramp these days.
My cat tries to sleep with me but starts waking me around six ; also he likes to leave the bedroom and then reappear noisily. Keeping him out has also helped!
If I wake up and really can't go back to sleep and start thinking the 3 a.m thoughts I read my Kindle, or get up and make a cuppa. (I even had mulled wine one morning! As I'm 93 I think I can be excused for this!!)