There can be many reasons behind it but the most common problems often seen in dogs are;
It can be a urinary tract infection
It can be infected prostate
Chances of uterine infection are also there
Your dg can have stones inside its tract.
It has eaten something poisonous
Some tick might have bitten it.
It has been hit by something really hard
Take it to vet for a thorough examination as soon as possible