"Count your blessings" is an idiomatic expression in English, essentially encouraging an individual to focus on the positive aspects of life rather than the negative. This is a very common expression, frequently found in songs as well as certain religious hymns. Though it can serve as a reminder to appreciate happy times, "count your blessings" also encourages an individual going through a challenging period to notice and appreciate the positive things, and remember all the good things that have come before.
There are two primary instances in which someone might say to another person, "count your blessings." The first is when things are going particularly well, and this individual is reminding the other not to take anything for granted, and to appreciate what he or she has. The underlying message here is that things can change very quickly, so it is important to recognize the happy, positive, or fortunate things in life when they occur, and to take time to appreciate them. The second time someone might say, "count your blessings," is when things are not going particularly well.
At this point, the individual is reminding the other that he or she has already had many blessings in life, and should take time to remember them. Ideally, this will encourage the person to feel more positive, even during a challenging time, and to remember that things will likely look up again soon. Some people get annoyed by being hearing this phrase during negative times in life, or periods of misfortune, so it is important to be careful when saying this, and to be sure not to do so dismissively. Always respect that the other person may not particularly feel like being positive at that current moment.
The idiom, "count your blessings," simply serves as a reminder that nothing is certain, but if we look hard enough, most people can find something to be grateful for, even if it is something as simple as a beautiful day outside, or a smile from a stranger. Psychologists frequently encourage people to keep "gratitude journals," in which a person will take a few moments at the end of the day to write down some positive things that happened, or things that he or she was grateful for. Ideally, over time this makes an individual more likely to notice the positive aspects of everyday life, rather than only the negative ones, and therefore more likely to remember them. This can help with some mental illnesses such as depression or anxiety.