I was traveling with some friends, doing my usual complaining every day, when one of them finally asked me to please shut up. At first I was offended, but shortly after realized what I had been doing. Committed to stop doing it there and then.
Because I've been there, I'm now conscious about others having this trait. For many people I think it's an attempt at socializing. Commiserating is an easy way to bond, but if you can't temper it, you just come across as an annoying complainer.
I wrote about this on my blog, and even made a flowchart for what to do when I feel the urge to complain. That particular post is not in English, so I won't share it here.