I guess the thing to take from this is that it's OK to tell God what you're thinking, even if it's not the nicest of thoughts.
We also see that David came to the place where he admitted to God what a mess his life was and what bad shape he was in.
The last thing I noticed is - after complaining about his enemy (and wishing him the very worst), then admitting how wrecked he was as a man, David still says this
30 With my mouth I will greatly extol the LORD; in the great throng of worshipers I will praise him.
If we put these three thoughts together we can come up with this plan.
When you're being attacked or life is going all wrong or things couldn't be worse.....
1. Tell God your honest thoughts
2. Admit that you're a wreck without Him
3. Choose to praise Him - with a lot of other people - like at church, not by yourself. You need God's people around you.