Instead of melatonin supplements, you can try meditation. Melatonin is produced a couple of hours a night while we sleep (typically 11 pm - 2 am); meditating (deep breathing and gradual relaxation) gets your melatonin naturally going and helps you sleep better.
If you haven't slept well for a while then you're going to have to invest a couple of weeks into catching up on your sleep and building a solid routine for sleep.
Sounds like you're a light sleeper (someone who has a hard time staying asleep and wakes up frequently), it could be due to environmental factors. Like, noises or light may keep you awake so you may want to invest in earplugs and eye-masks. If you do wind up using earplugs or eye-masks to stay asleep, don't use them for long-periods of time (over a month or so) because it messes up your ability to wake-up naturally.
*Light* exercise earlier in the day (preferably in the morning) is much better for a good nights rest. By putting your body into peak performance during the day, you're body will want to naturally unwind when it is dark. Diet is a huge component. Sugar, simple carbohydrates and other stimulants are abundant in the ordinary diet - even if you keep your stimulant foods to the morning or noontime you can still greatly influence your ability to fall asleep. You would want to reduce your alcohol, caffeine, and sugar intake for at least eight hours before going to bed.
The problem is that you cannot catch up on your sleep the way that many of us think we can. You don't just oversleep one day and you've caught up; you actually have to earn it back over a longer period of time than most people are willing to indulge. If you've missed about an hours worth of sleep for a week, then you'd add an additional 20 or so minutes to your sleep regime every day for about two weeks.
When you work on getting your sleep cycle back to normal: make sure you're adding the additional time to the end of your sleep time. Because if you start to go to bed earlier (in order to catch up on sleep) and you're not a night owl, you'll train to body to sleep earlier - instead, you'd rather train your body to sleep later. This usually means tweaking your morning routine - but it's not that hard.
You'll definitely, however, want to consult with a doctor if you've had difficulty falling asleep for more than a couple of months. Chronic insomnia can be an effect of a serious illness (or general poor health) and can be the cause for a serious illness or general poor health. Sleep deficiency depresses the immune system, sex drive, and can lead to heart disease, headaches, depression, and chronic fatigue. It’s hard to suggest remedies for lack of sleep because of the many factors influencing sleep deprivation: anxiety and stress, diet, indigestion, pain, lack of exercise, stimulants, aging, hormones, etc. Only a certified doctor can determine what factor is keeping you from getting the sleep you need.
If you want to go the supplement route, 5-HTP*, melatonin*, passionflower, valerian*, calcium-magnesium*, and vitamin B12 are good supplements.
*5-HTP should not be taken without a doctor consultation because, if taking it unnecessarily, you can cause a serotonin disorder and leave yourself at a high-risk for chronic insomnia, paranoia, anxiety, depression, and a hoard of other unpleasant mental health issues. Valerian should not be taken without monitoring from a doctor because of its known side effects. Calcium-magnesium and iron should not be taken without a doctor’s consent or input because of toxicity issues (plus, many people wind up taking supplements that are the equivalent of dirt - you would definitely want a doctor to give the thumbs up or down on the type of supplement you take).
So long as you are consistent in your practices to stay asleep (meaning you spend more than two weeks getting your sleep cycle underway) you should prevail.
Sleep studies (I've participated in); many talks with doctors; Scientific American (on how to earn back missed sleep); excellent health classes in college.